Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3a86f2d

Browse files
Add unit test cases for IDatabasesClient ✅ (#90)
Add unit test cases for IDatabaseClient ✅
1 parent 0d43510 commit 3a86f2d

File tree

5 files changed

+461
-15
lines changed

5 files changed

+461
-15
lines changed

‎Test/Notion.UnitTests/DatabasesClientTests.cs‎

Lines changed: 93 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.IO;
1+
using System.Collections.Generic;
2+
using System.IO;
23
using System.Threading.Tasks;
34
using FluentAssertions;
45
using Notion.Client;
@@ -16,29 +17,106 @@ public DatabasesClientTests()
1617
_client = new DatabasesClient(new RestClient(ClientOptions));
1718
}
1819

19-
[Fact(Skip="Internal Testing Purpose")]
20+
[Fact]
2021
public async Task ListDatabasesAsync()
2122
{
22-
var databasesList = await _client.ListAsync();
23-
Assert.NotNull(databasesList);
23+
var path = ApiEndpoints.DatabasesApiUrls.List();
24+
var jsonData = await File.ReadAllTextAsync("data/databases/DatabasesListResponse.json");
25+
26+
Server.Given(CreateGetRequestBuilder(path))
27+
.RespondWith(
28+
Response.Create()
29+
.WithStatusCode(200)
30+
.WithBody(jsonData)
31+
);
32+
33+
var databases = await _client.ListAsync();
34+
35+
databases.Results.Should().HaveCount(3);
36+
37+
foreach (var database in databases.Results)
38+
{
39+
database.Parent.Should().BeAssignableTo<IDatabaseParent>();
40+
foreach (var property in database.Properties)
41+
{
42+
property.Key.Should().Be(property.Value.Name);
43+
}
44+
}
2445
}
2546

26-
[Fact(Skip="Internal Testing Purpose")]
27-
public async Task RetrieveDatabaseAsync()
47+
[Fact]
48+
public async Task QueryAsync()
2849
{
29-
var databaseId = "";
30-
var database = await _client.RetrieveAsync(databaseId);
31-
Assert.NotNull(database);
50+
var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1";
51+
var path = ApiEndpoints.DatabasesApiUrls.Query(databaseId);
52+
var jsonData = await File.ReadAllTextAsync("data/databases/DatabasesQueryResponse.json");
53+
54+
Server.Given(CreatePostRequestBuilder(path))
55+
.RespondWith(
56+
Response.Create()
57+
.WithStatusCode(200)
58+
.WithBody(jsonData)
59+
);
60+
61+
var databasesQueryParams = new DatabasesQueryParameters
62+
{
63+
Filter = new CompoundFilter
64+
{
65+
Or = new List<Filter> {
66+
new CheckboxFilter(
67+
"In stock",
68+
true
69+
),
70+
new NumberFilter(
71+
"Cost of next trip",
72+
greaterThanOrEqualTo: 2
73+
)
74+
},
75+
},
76+
Sorts = new List<Sort>
77+
{
78+
new Sort
79+
{
80+
Property = "Last ordered",
81+
Direction = Direction.Ascending
82+
}
83+
}
84+
};
85+
86+
var pagesPaginatedList = await _client.QueryAsync(databaseId, databasesQueryParams);
87+
88+
pagesPaginatedList.Results.Should().ContainSingle();
89+
90+
foreach (var page in pagesPaginatedList.Results)
91+
{
92+
page.Parent.Should().BeAssignableTo<IPageParent>();
93+
page.Object.Should().Be(ObjectType.Page);
94+
}
3295
}
3396

34-
[Fact(Skip="Internal Testing Purpose")]
35-
public async Task QueryAsync()
97+
[Fact]
98+
public async Task RetrieveDatabaseAsync()
3699
{
37-
var databaseId = "";
38-
var databasesQueryParameters = new DatabasesQueryParameters { };
39-
var pagesList = await _client.QueryAsync(databaseId, databasesQueryParameters);
100+
var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1";
101+
var path = ApiEndpoints.DatabasesApiUrls.Retrieve(databaseId);
102+
var jsonData = await File.ReadAllTextAsync("data/databases/DatabaseRetrieveResponse.json");
103+
104+
Server.Given(CreateGetRequestBuilder(path))
105+
.RespondWith(
106+
Response.Create()
107+
.WithStatusCode(200)
108+
.WithBody(jsonData)
109+
);
40110

41-
Assert.NotNull(pagesList);
111+
var database = await _client.RetrieveAsync(databaseId);
112+
113+
database.Parent.Type.Should().Be(ParentType.PageId);
114+
database.Parent.Should().BeOfType<PageParent>();
115+
((PageParent)database.Parent).PageId.Should().Be("649089db-8984-4051-98fb-a03593b852d8");
116+
foreach (var property in database.Properties)
117+
{
118+
property.Key.Should().Be(property.Value.Name);
119+
}
42120
}
43121

44122
[Fact]

‎Test/Notion.UnitTests/Notion.UnitTests.csproj‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@
4242
<None Update="data\databases\DatabasePropertyObjectContainNameProperty.json">
4343
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
4444
</None>
45+
<None Update="data\databases\DatabaseRetrieveResponse.json">
46+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
47+
</None>
48+
<None Update="data\databases\DatabasesListResponse.json">
49+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
50+
</None>
51+
<None Update="data\databases\DatabasesQueryResponse.json">
52+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
53+
</None>
4554
</ItemGroup>
4655

4756
</Project>
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
{
2+
"object": "database",
3+
"id": "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1",
4+
"created_time": "2021年05月22日T18:44:00.000Z",
5+
"last_edited_time": "2021年05月23日T12:29:00.000Z",
6+
"title": [
7+
{
8+
"type": "text",
9+
"text": {
10+
"content": "sample table",
11+
"link": null
12+
},
13+
"annotations": {
14+
"bold": false,
15+
"italic": false,
16+
"strikethrough": false,
17+
"underline": false,
18+
"code": false,
19+
"color": "default"
20+
},
21+
"plain_text": "sample table",
22+
"href": null
23+
}
24+
],
25+
"properties": {
26+
"Tags": {
27+
"id": "YG~h",
28+
"name": "Tags",
29+
"type": "multi_select",
30+
"multi_select": {
31+
"options": []
32+
}
33+
},
34+
"SimpleText": {
35+
"id": "_Dfp",
36+
"name": "SimpleText",
37+
"type": "rich_text",
38+
"rich_text": {}
39+
},
40+
"Column": {
41+
"id": "bxhl",
42+
"name": "Column",
43+
"type": "multi_select",
44+
"multi_select": {
45+
"options": [
46+
{
47+
"id": "5a44a233-33be-435e-b358-2c0ed1799dcf",
48+
"name": "what",
49+
"color": "gray"
50+
}
51+
]
52+
}
53+
},
54+
"SelectProp": {
55+
"id": "eZ[y",
56+
"name": "SelectProp",
57+
"type": "select",
58+
"select": {
59+
"options": [
60+
{
61+
"id": "362dc255-c867-4543-b3ea-7bd988638228",
62+
"name": "Female",
63+
"color": "green"
64+
}
65+
]
66+
}
67+
},
68+
"Property": {
69+
"id": "zDGa",
70+
"name": "Property",
71+
"type": "relation",
72+
"relation": {
73+
"database_id": "f86f2262-0751-40f2-8f63-e3f7a3c39fcb",
74+
"synced_property_name": "Related to sample table (Property)",
75+
"synced_property_id": "VQ}{"
76+
}
77+
},
78+
"Name": {
79+
"id": "title",
80+
"name": "Name",
81+
"type": "title",
82+
"title": {}
83+
}
84+
},
85+
"parent": {
86+
"type": "page_id",
87+
"page_id": "649089db-8984-4051-98fb-a03593b852d8"
88+
}
89+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /