From f8583ef7485c92dd5f6e25287c15ce1fe41b3b81 Mon Sep 17 00:00:00 2001 From: Laurent Egbakou <26142591+egbakou@users.noreply.github.com> Date: Tue, 9 May 2023 15:26:15 +0200 Subject: [PATCH] feat: added support for inline database creation (#134) * 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 --- database.go | 1 + database_test.go | 58 +++++++++++++++++++++++++++++++++ testdata/database_create_3.json | 49 ++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 testdata/database_create_3.json diff --git a/database.go b/database.go index e729c48..061a2ab 100644 --- a/database.go +++ b/database.go @@ -180,4 +180,5 @@ type DatabaseCreateRequest struct { Parent Parent `json:"parent"` Title []RichText `json:"title"` Properties PropertyConfigs `json:"properties"` + IsInline bool `json:"is_inline"` } diff --git a/database_test.go b/database_test.go index db44134..add4844 100644 --- a/database_test.go +++ b/database_test.go @@ -271,6 +271,7 @@ func TestDatabaseClient(t *testing.T) { Type: notionapi.PropertyConfigTypeTitle, }, }, + IsInline: false, }, want: ¬ionapi.Database{ Object: notionapi.ObjectTypeDatabase, @@ -326,6 +327,7 @@ func TestDatabaseClient(t *testing.T) { Type: notionapi.PropertyConfigTypeTitle, }, }, + IsInline: false, }, want: ¬ionapi.Database{ Object: notionapi.ObjectTypeDatabase, @@ -361,6 +363,62 @@ func TestDatabaseClient(t *testing.T) { }, }, }, + { + name: "returns created db 3", + filePath: "testdata/database_create_3.json", + statusCode: http.StatusOK, + request: ¬ionapi.DatabaseCreateRequest{ + Parent: notionapi.Parent{ + Type: notionapi.ParentTypePageID, + PageID: "some_id", + }, + Title: []notionapi.RichText{ + { + Type: notionapi.ObjectTypeText, + Text: ¬ionapi.Text{Content: "Grocery List"}, + }, + }, + Properties: notionapi.PropertyConfigs{ + "create": notionapi.TitlePropertyConfig{ + Type: notionapi.PropertyConfigTypeTitle, + }, + }, + IsInline: true, + }, + want: ¬ionapi.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: ¬ionapi.Text{Content: "Grocery List"}, + PlainText: "Grocery List", + Annotations: ¬ionapi.Annotations{Color: notionapi.ColorDefault}, + }, + }, + Description: []notionapi.RichText{}, + IsInline: true, + Archived: false, + Icon: ¬ionapi.Icon{ + Type: "emoji", + Emoji: &emoji, + }, + Cover: ¬ionapi.Image{ + Type: "external", + External: ¬ionapi.FileObject{ + URL: "https://website.domain/images/image.png", + }, + }, + }, + }, } for _, tt := range tests { diff --git a/testdata/database_create_3.json b/testdata/database_create_3.json new file mode 100644 index 0000000..d8ce77d --- /dev/null +++ b/testdata/database_create_3.json @@ -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 +}