mirror of
https://github.com/dstotijn/go-notion.git
synced 2025-06-08 23:46:12 +02:00
Add test case for creating page with database parent (#10)
* fix-json-tag * fix test case name * fix to use database_id * fix client test * fix typo * remove .idea and fix test name Co-authored-by: rita <kajirita2002@gmail.com>
This commit is contained in:
parent
1d8c71b79b
commit
14d2e8c377
127
client_test.go
127
client_test.go
@ -978,6 +978,133 @@ func TestCreatePage(t *testing.T) {
|
|||||||
},
|
},
|
||||||
expError: nil,
|
expError: nil,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "database parent, successful response",
|
||||||
|
params: notion.CreatePageParams{
|
||||||
|
ParentType: notion.ParentTypeDatabase,
|
||||||
|
ParentID: "b0668f48-8d66-4733-9bdb-2f82215707f7",
|
||||||
|
DatabasePageProperties: ¬ion.DatabasePageProperties{
|
||||||
|
"title": notion.DatabasePageProperty{
|
||||||
|
Title: []notion.RichText{
|
||||||
|
{
|
||||||
|
Text: ¬ion.Text{
|
||||||
|
Content: "Foobar",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Children: []notion.Block{
|
||||||
|
{
|
||||||
|
Object: "block",
|
||||||
|
Type: notion.BlockTypeParagraph,
|
||||||
|
Paragraph: ¬ion.RichTextBlock{
|
||||||
|
Text: []notion.RichText{
|
||||||
|
{
|
||||||
|
Text: ¬ion.Text{
|
||||||
|
Content: "Lorem ipsum dolor sit amet.",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
respBody: func(_ *http.Request) io.Reader {
|
||||||
|
return strings.NewReader(
|
||||||
|
`{
|
||||||
|
"object": "page",
|
||||||
|
"id": "276ee233-e426-4ed0-9986-6b22af8550df",
|
||||||
|
"created_time": "2021-05-19T19:34:05.068Z",
|
||||||
|
"last_edited_time": "2021-05-19T19:34:05.069Z",
|
||||||
|
"parent": {
|
||||||
|
"type": "database_id",
|
||||||
|
"database_id": "b0668f48-8d66-4733-9bdb-2f82215707f7"
|
||||||
|
},
|
||||||
|
"archived": false,
|
||||||
|
"properties": {
|
||||||
|
"title": {
|
||||||
|
"id": "title",
|
||||||
|
"title": [
|
||||||
|
{
|
||||||
|
"text": {
|
||||||
|
"content": "Foobar",
|
||||||
|
"link": null
|
||||||
|
},
|
||||||
|
"annotations": {
|
||||||
|
"bold": false,
|
||||||
|
"italic": false,
|
||||||
|
"strikethrough": false,
|
||||||
|
"underline": false,
|
||||||
|
"code": false,
|
||||||
|
"color": "default"
|
||||||
|
},
|
||||||
|
"href": null
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
respStatusCode: http.StatusOK,
|
||||||
|
expPostBody: map[string]interface{}{
|
||||||
|
"parent": map[string]interface{}{
|
||||||
|
"database_id": "b0668f48-8d66-4733-9bdb-2f82215707f7",
|
||||||
|
},
|
||||||
|
"properties": map[string]interface{}{
|
||||||
|
"title": map[string]interface{}{
|
||||||
|
"title": []interface{}{
|
||||||
|
map[string]interface{}{
|
||||||
|
"text": map[string]interface{}{
|
||||||
|
"content": "Foobar",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"children": []interface{}{
|
||||||
|
map[string]interface{}{
|
||||||
|
"object": "block",
|
||||||
|
"type": "paragraph",
|
||||||
|
"paragraph": map[string]interface{}{
|
||||||
|
"text": []interface{}{
|
||||||
|
map[string]interface{}{
|
||||||
|
"text": map[string]interface{}{
|
||||||
|
"content": "Lorem ipsum dolor sit amet.",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expResponse: notion.Page{
|
||||||
|
ID: "276ee233-e426-4ed0-9986-6b22af8550df",
|
||||||
|
CreatedTime: mustParseTime(time.RFC3339Nano, "2021-05-19T19:34:05.068Z"),
|
||||||
|
LastEditedTime: mustParseTime(time.RFC3339Nano, "2021-05-19T19:34:05.069Z"),
|
||||||
|
Parent: notion.PageParent{
|
||||||
|
Type: notion.ParentTypeDatabase,
|
||||||
|
DatabaseID: notion.StringPtr("b0668f48-8d66-4733-9bdb-2f82215707f7"),
|
||||||
|
},
|
||||||
|
Properties: notion.DatabasePageProperties{
|
||||||
|
"title": notion.DatabasePageProperty{
|
||||||
|
ID: "title",
|
||||||
|
Title: []notion.RichText{
|
||||||
|
{
|
||||||
|
Text: ¬ion.Text{
|
||||||
|
Content: "Foobar",
|
||||||
|
},
|
||||||
|
Annotations: ¬ion.Annotations{
|
||||||
|
Color: notion.ColorDefault,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expError: nil,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "error response",
|
name: "error response",
|
||||||
params: notion.CreatePageParams{
|
params: notion.CreatePageParams{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user