Skip to content

Commit d8debc6

Browse files
authored
test: add settings test (#11)
1 parent ffe1e13 commit d8debc6

File tree

2 files changed

+48
-20
lines changed

2 files changed

+48
-20
lines changed

api.go

-20
Original file line numberDiff line numberDiff line change
@@ -68,42 +68,22 @@ func New(authToken string, setters ...APISetting) *API {
6868
}
6969

7070
func (c *API) Users() UsersInterface {
71-
if c == nil {
72-
return nil
73-
}
74-
7571
return c.usersClient
7672
}
7773

7874
func (c *API) Databases() DatabasesInterface {
79-
if c == nil {
80-
return nil
81-
}
82-
8375
return c.databasesClient
8476
}
8577

8678
func (c *API) Pages() PagesInterface {
87-
if c == nil {
88-
return nil
89-
}
90-
9179
return c.pagesClient
9280
}
9381

9482
func (c *API) Blocks() BlocksInterface {
95-
if c == nil {
96-
return nil
97-
}
98-
9983
return c.blocksClient
10084
}
10185

10286
func (c *API) Search(ctx context.Context, params SearchParameters) (*SearchResponse, error) {
103-
if c == nil {
104-
return nil, ErrUnknown
105-
}
106-
10787
return c.searchClient.Search(ctx, params)
10888
}
10989

api_internal_test.go

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package notion
2+
3+
import (
4+
"net/http"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
func TestWithUserAgent(t *testing.T) {
11+
var settings apiSettings
12+
13+
userAgent := "test-user-agent"
14+
15+
WithUserAgent("test-user-agent")(&settings)
16+
17+
assert.Equal(t, settings.userAgent, userAgent)
18+
}
19+
20+
func TestWithBaseURL(t *testing.T) {
21+
var settings apiSettings
22+
23+
baseURL := "https://example.com"
24+
25+
WithBaseURL(baseURL)(&settings)
26+
27+
assert.Equal(t, settings.baseURL, baseURL)
28+
}
29+
30+
func TestNotionVersion(t *testing.T) {
31+
var settings apiSettings
32+
33+
notionVersion := "2021-05-19"
34+
35+
WithNotionVersion(notionVersion)(&settings)
36+
37+
assert.Equal(t, settings.notionVersion, notionVersion)
38+
}
39+
40+
func TestHTTPClient(t *testing.T) {
41+
var settings apiSettings
42+
43+
httpClient := &http.Client{}
44+
45+
WithHTTPClient(httpClient)(&settings)
46+
47+
assert.Same(t, settings.httpClient, httpClient)
48+
}

0 commit comments

Comments
 (0)