Skip to content

Commit

Permalink
test: add settings test (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkfsn authored May 19, 2021
1 parent ffe1e13 commit d8debc6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 20 deletions.
20 changes: 0 additions & 20 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,42 +68,22 @@ func New(authToken string, setters ...APISetting) *API {
}

func (c *API) Users() UsersInterface {
if c == nil {
return nil
}

return c.usersClient
}

func (c *API) Databases() DatabasesInterface {
if c == nil {
return nil
}

return c.databasesClient
}

func (c *API) Pages() PagesInterface {
if c == nil {
return nil
}

return c.pagesClient
}

func (c *API) Blocks() BlocksInterface {
if c == nil {
return nil
}

return c.blocksClient
}

func (c *API) Search(ctx context.Context, params SearchParameters) (*SearchResponse, error) {
if c == nil {
return nil, ErrUnknown
}

return c.searchClient.Search(ctx, params)
}

Expand Down
48 changes: 48 additions & 0 deletions api_internal_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package notion

import (
"net/http"
"testing"

"github.com/stretchr/testify/assert"
)

func TestWithUserAgent(t *testing.T) {
var settings apiSettings

userAgent := "test-user-agent"

WithUserAgent("test-user-agent")(&settings)

assert.Equal(t, settings.userAgent, userAgent)
}

func TestWithBaseURL(t *testing.T) {
var settings apiSettings

baseURL := "https://example.com"

WithBaseURL(baseURL)(&settings)

assert.Equal(t, settings.baseURL, baseURL)
}

func TestNotionVersion(t *testing.T) {
var settings apiSettings

notionVersion := "2021-05-19"

WithNotionVersion(notionVersion)(&settings)

assert.Equal(t, settings.notionVersion, notionVersion)
}

func TestHTTPClient(t *testing.T) {
var settings apiSettings

httpClient := &http.Client{}

WithHTTPClient(httpClient)(&settings)

assert.Same(t, settings.httpClient, httpClient)
}

0 comments on commit d8debc6

Please sign in to comment.