Skip to content

Commit ad0532d

Browse files
Merge pull request #112 from notion-dotnet/test/add-unit-or-integration-tests-for-search-client
Add unit or integration tests for search client ✅
2 parents a05797e + bdb1f56 commit ad0532d

File tree

4 files changed

+157
-2
lines changed

4 files changed

+157
-2
lines changed

Src/Notion.Client/Api/Search/Parameters/SearchSort.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ public class SearchSort
88
{
99
public SearchDirection Direction { get; set; }
1010

11-
[JsonConverter(typeof(IsoDateTimeConverter))]
12-
public DateTime Timestamp { get; set; }
11+
public string Timestamp { get; set; }
1312
}
1413
}

Test/Notion.UnitTests/Notion.UnitTests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@
7878
<None Update="data\users\RetrieveUserResponse.json">
7979
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
8080
</None>
81+
<None Update="data\search\SearchResponse.json">
82+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
83+
</None>
8184
</ItemGroup>
8285

8386
</Project>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using System;
2+
using System.IO;
3+
using System.Threading.Tasks;
4+
using FluentAssertions;
5+
using Notion.Client;
6+
using WireMock.ResponseBuilders;
7+
using Xunit;
8+
9+
namespace Notion.UnitTests
10+
{
11+
public class SearchClientTest : ApiTestBase
12+
{
13+
private readonly SearchClient _client;
14+
15+
public SearchClientTest()
16+
{
17+
_client = new SearchClient(new RestClient(ClientOptions));
18+
}
19+
20+
[Fact]
21+
public async Task Search()
22+
{
23+
// Arrange
24+
var path = ApiEndpoints.SearchApiUrls.Search();
25+
var jsonData = await File.ReadAllTextAsync("data/search/SearchResponse.json");
26+
27+
Server.Given(CreatePostRequestBuilder(path))
28+
.RespondWith(
29+
Response.Create()
30+
.WithStatusCode(200)
31+
.WithBody(jsonData)
32+
);
33+
34+
SearchParameters searchParameters = new SearchParameters()
35+
{
36+
Query = "External tasks",
37+
Sort = new SearchSort
38+
{
39+
Direction = SearchDirection.Ascending,
40+
Timestamp = "last_edited_time"
41+
}
42+
};
43+
44+
// Act
45+
var searchResult = await _client.SearchAsync(searchParameters);
46+
47+
// Assert
48+
var results = searchResult.Results;
49+
50+
results.Should().SatisfyRespectively(
51+
obj =>
52+
{
53+
obj.Object.Should().Be(ObjectType.Database);
54+
55+
var database = (Database)obj;
56+
database.Properties.Should().HaveCount(2);
57+
},
58+
obj =>
59+
{
60+
obj.Object.Should().Be(ObjectType.Page);
61+
62+
var page = (Page)obj;
63+
page.IsArchived.Should().BeFalse();
64+
page.Properties.Should().HaveCount(1);
65+
page.Parent.Should().BeAssignableTo<DatabaseParent>();
66+
((DatabaseParent)page.Parent).DatabaseId.Should().Be("e6c6f8ff-c70e-4970-91ba-98f03e0d7fc6");
67+
}
68+
);
69+
}
70+
}
71+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
{
2+
"has_more": false,
3+
"next_cursor": null,
4+
"object": "list",
5+
"results": [
6+
{
7+
"created_time": "2021-04-22T22:23:26.080Z",
8+
"id": "e6c6f8ff-c70e-4970-91ba-98f03e0d7fc6",
9+
"last_edited_time": "2021-04-23T04:21:00.000Z",
10+
"object": "database",
11+
"properties": {
12+
"Name": {
13+
"id": "title",
14+
"title": {},
15+
"type": "title"
16+
},
17+
"Task Type": {
18+
"id": "vd@l",
19+
"multi_select": {
20+
"options": []
21+
},
22+
"type": "multi_select"
23+
}
24+
},
25+
"title": [
26+
{
27+
"annotations": {
28+
"bold": false,
29+
"code": false,
30+
"color": "default",
31+
"italic": false,
32+
"strikethrough": false,
33+
"underline": false
34+
},
35+
"href": null,
36+
"plain_text": "Tasks",
37+
"text": {
38+
"content": "Tasks",
39+
"link": null
40+
},
41+
"type": "text"
42+
}
43+
]
44+
},
45+
{
46+
"archived": false,
47+
"created_time": "2021-04-23T04:21:00.000Z",
48+
"id": "4f555b50-3a9b-49cb-924c-3746f4ca5522",
49+
"last_edited_time": "2021-04-23T04:21:00.000Z",
50+
"object": "page",
51+
"parent": {
52+
"database_id": "e6c6f8ff-c70e-4970-91ba-98f03e0d7fc6",
53+
"type": "database_id"
54+
},
55+
"properties": {
56+
"Name": {
57+
"id": "title",
58+
"title": [
59+
{
60+
"annotations": {
61+
"bold": false,
62+
"code": false,
63+
"color": "default",
64+
"italic": false,
65+
"strikethrough": false,
66+
"underline": false
67+
},
68+
"href": null,
69+
"plain_text": "Task 1",
70+
"text": {
71+
"content": "Task1 1",
72+
"link": null
73+
},
74+
"type": "text"
75+
}
76+
],
77+
"type": "title"
78+
}
79+
}
80+
}
81+
]
82+
}

0 commit comments

Comments
 (0)