Skip to content

Commit

Permalink
feat: added support for inline database creation (#134)
Browse files Browse the repository at this point in the history
* feat: added IsInline property to DatabaseCreateRequest

* chore: added is_inline json test data

* tests: added create database test with is_inline property set to true
  • Loading branch information
egbakou authored May 9, 2023
1 parent fd76786 commit f8583ef
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
1 change: 1 addition & 0 deletions database.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,5 @@ type DatabaseCreateRequest struct {
Parent Parent `json:"parent"`
Title []RichText `json:"title"`
Properties PropertyConfigs `json:"properties"`
IsInline bool `json:"is_inline"`
}
58 changes: 58 additions & 0 deletions database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ func TestDatabaseClient(t *testing.T) {
Type: notionapi.PropertyConfigTypeTitle,
},
},
IsInline: false,
},
want: &notionapi.Database{
Object: notionapi.ObjectTypeDatabase,
Expand Down Expand Up @@ -326,6 +327,7 @@ func TestDatabaseClient(t *testing.T) {
Type: notionapi.PropertyConfigTypeTitle,
},
},
IsInline: false,
},
want: &notionapi.Database{
Object: notionapi.ObjectTypeDatabase,
Expand Down Expand Up @@ -361,6 +363,62 @@ func TestDatabaseClient(t *testing.T) {
},
},
},
{
name: "returns created db 3",
filePath: "testdata/database_create_3.json",
statusCode: http.StatusOK,
request: &notionapi.DatabaseCreateRequest{
Parent: notionapi.Parent{
Type: notionapi.ParentTypePageID,
PageID: "some_id",
},
Title: []notionapi.RichText{
{
Type: notionapi.ObjectTypeText,
Text: &notionapi.Text{Content: "Grocery List"},
},
},
Properties: notionapi.PropertyConfigs{
"create": notionapi.TitlePropertyConfig{
Type: notionapi.PropertyConfigTypeTitle,
},
},
IsInline: true,
},
want: &notionapi.Database{
Object: notionapi.ObjectTypeDatabase,
ID: "some_id",
CreatedTime: timestamp,
LastEditedTime: timestamp,
CreatedBy: user,
LastEditedBy: user,
Parent: notionapi.Parent{
Type: "page_id",
PageID: "a7744006-9233-4cd0-bf44-3a49de2c01b5",
},
Title: []notionapi.RichText{
{
Type: notionapi.ObjectTypeText,
Text: &notionapi.Text{Content: "Grocery List"},
PlainText: "Grocery List",
Annotations: &notionapi.Annotations{Color: notionapi.ColorDefault},
},
},
Description: []notionapi.RichText{},
IsInline: true,
Archived: false,
Icon: &notionapi.Icon{
Type: "emoji",
Emoji: &emoji,
},
Cover: &notionapi.Image{
Type: "external",
External: &notionapi.FileObject{
URL: "https://website.domain/images/image.png",
},
},
},
},
}

for _, tt := range tests {
Expand Down
49 changes: 49 additions & 0 deletions testdata/database_create_3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"object": "database",
"id": "some_id",
"cover": {
"type": "external",
"external": {
"url": "https://website.domain/images/image.png"
}
},
"icon": {
"type": "emoji",
"emoji": "🎉"
},
"created_time": "2021-05-24T05:06:34.827Z",
"last_edited_time": "2021-05-24T05:06:34.827Z",
"created_by":{
"object": "user",
"id": "some_id"
},
"last_edited_by":{
"object": "user",
"id": "some_id"
},
"title": [
{
"type": "text",
"text": {
"content": "Grocery List",
"link": null
},
"annotations": {
"bold": false,
"italic": false,
"strikethrough": false,
"underline": false,
"code": false,
"color": "default"
},
"plain_text": "Grocery List",
"href": null
}
],
"parent": {
"type": "page_id",
"page_id": "a7744006-9233-4cd0-bf44-3a49de2c01b5"
},
"description": [],
"is_inline": true
}

0 comments on commit f8583ef

Please sign in to comment.