Skip to content

Commit

Permalink
fix RichText definition (#28)
Browse files Browse the repository at this point in the history
* fix RichText definition (and a couple of formatting issues)

* use pointer to Link (link is optional)

* fix unit tests
  • Loading branch information
pcarion authored Oct 5, 2021
1 parent 43ea89a commit 77a7cdf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestDatabaseClient(t *testing.T) {
Title: []notionapi.RichText{
{
Type: notionapi.ObjectTypeText,
Text: notionapi.Text{Content: "Test Database", Link: ""},
Text: notionapi.Text{Content: "Test Database"},
Annotations: &notionapi.Annotations{Color: "default"},
PlainText: "Test Database",
Href: "",
Expand Down
8 changes: 6 additions & 2 deletions object.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ type RichText struct {

type Text struct {
Content string `json:"content"`
Link string `json:"link,omitempty"`
Link *Link `json:"link,omitempty"`
}

type Link struct {
Url string `json:"url,omitempty"`
}

type Annotations struct {
Expand Down Expand Up @@ -111,7 +115,7 @@ type File struct {
}

type FileObject struct {
URL string `json:"url,omitempty"`
URL string `json:"url,omitempty"`
ExpiryTime *time.Time `json:"expiry_time,omitempty"`
}

Expand Down
9 changes: 6 additions & 3 deletions page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package notionapi_test
import (
"context"
"encoding/json"
"github.com/jomei/notionapi"
"net/http"
"reflect"
"testing"
"time"

"github.com/jomei/notionapi"
)

func TestPageClient(t *testing.T) {
Expand Down Expand Up @@ -340,7 +341,9 @@ func TestPageCreateRequest_MarshallJSON(t *testing.T) {
{
Text: notionapi.Text{
Content: "Lacinato",
Link: "some_url",
Link: &notionapi.Link{
Url: "some_url",
},
},
},
},
Expand All @@ -349,7 +352,7 @@ func TestPageCreateRequest_MarshallJSON(t *testing.T) {
},
},
},
want: []byte(`{"parent":{"database_id":"some_id"},"properties":{"Link":{"url":"some_url"},"Name":{"title":[{"text":{"content":"New Media Article"}}]},"Publishing/Release Date":{"date":{"start":"2020-12-08T12:00:00Z","end":null}},"Read":{"checkbox":false},"Summary":{"text":[{"type":"text","text":{"content":"Some content"},"annotations":{"bold":true,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"blue"},"plain_text":"Some content"}]},"Type":{"select":{"id":"some_id","name":"Article","color":"default"}}},"children":[{"object":"block","type":"heading_2","heading_2":{"text":[{"type":"text","text":{"content":"Lacinato"}}]}},{"object":"block","type":"paragraph","paragraph":{"text":[{"text":{"content":"Lacinato","link":"some_url"}}]}}]}`),
want: []byte(`{"parent":{"database_id":"some_id"},"properties":{"Link":{"url":"some_url"},"Name":{"title":[{"text":{"content":"New Media Article"}}]},"Publishing/Release Date":{"date":{"start":"2020-12-08T12:00:00Z","end":null}},"Read":{"checkbox":false},"Summary":{"text":[{"type":"text","text":{"content":"Some content"},"annotations":{"bold":true,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"blue"},"plain_text":"Some content"}]},"Type":{"select":{"id":"some_id","name":"Article","color":"default"}}},"children":[{"object":"block","type":"heading_2","heading_2":{"text":[{"type":"text","text":{"content":"Lacinato"}}]}},{"object":"block","type":"paragraph","paragraph":{"text":[{"text":{"content":"Lacinato","link":{"url":"some_url"}}}]}}]}`),
},
}

Expand Down

0 comments on commit 77a7cdf

Please sign in to comment.