Skip to content

Commit

Permalink
Enable empty DatabaseQueryFilter (#15)
Browse files Browse the repository at this point in the history
* Add test for "DatabaseQuery"

* Fix DatabaseQuery Filter field type

* Assert database query JSON omit logic in `Client` tests

Co-authored-by: Alexandre Falardeau <[email protected]>
Co-authored-by: David Stotijn <[email protected]>
  • Loading branch information
3 people authored May 25, 2021
1 parent c675641 commit 969ba03
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
26 changes: 24 additions & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ func TestQueryDatabase(t *testing.T) {
{
name: "with query, successful response",
query: &notion.DatabaseQuery{
Filter: notion.DatabaseQueryFilter{
Filter: &notion.DatabaseQueryFilter{
Property: "Name",
Text: &notion.TextDatabaseQueryFilter{
Contains: "foobar",
Expand Down Expand Up @@ -775,7 +775,7 @@ func TestQueryDatabase(t *testing.T) {
expError: nil,
},
{
name: "without query, successful response",
name: "without query, doesn't send POST body",
query: nil,
respBody: func(_ *http.Request) io.Reader {
return strings.NewReader(
Expand All @@ -796,6 +796,28 @@ func TestQueryDatabase(t *testing.T) {
},
expError: nil,
},
{
name: "with non nil query, but without fields, omits all fields from POST body",
query: &notion.DatabaseQuery{},
respBody: func(_ *http.Request) io.Reader {
return strings.NewReader(
`{
"object": "list",
"results": [],
"next_cursor": null,
"has_more": false
}`,
)
},
respStatusCode: http.StatusOK,
expPostBody: map[string]interface{}{},
expResponse: notion.DatabaseQueryResponse{
Results: []notion.Page{},
HasMore: false,
NextCursor: nil,
},
expError: nil,
},
{
name: "error response",
respBody: func(_ *http.Request) io.Reader {
Expand Down
8 changes: 4 additions & 4 deletions database.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ type DatabaseProperty struct {

// DatabaseQuery is used for quering a database.
type DatabaseQuery struct {
Filter DatabaseQueryFilter `json:"filter,omitempty"`
Sorts []DatabaseQuerySort `json:"sorts,omitempty"`
StartCursor string `json:"start_cursor,omitempty"`
PageSize int `json:"page_size,omitempty"`
Filter *DatabaseQueryFilter `json:"filter,omitempty"`
Sorts []DatabaseQuerySort `json:"sorts,omitempty"`
StartCursor string `json:"start_cursor,omitempty"`
PageSize int `json:"page_size,omitempty"`
}

// DatabaseQueryResponse contains the results and pagination data from a query request.
Expand Down

0 comments on commit 969ba03

Please sign in to comment.