-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from notion-dotnet/test/add-unit-or-integrati…
…on-tests-for-search-client Add unit or integration tests for search client ✅
- Loading branch information
Showing
4 changed files
with
157 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Notion.Client; | ||
using WireMock.ResponseBuilders; | ||
using Xunit; | ||
|
||
namespace Notion.UnitTests | ||
{ | ||
public class SearchClientTest : ApiTestBase | ||
{ | ||
private readonly SearchClient _client; | ||
|
||
public SearchClientTest() | ||
{ | ||
_client = new SearchClient(new RestClient(ClientOptions)); | ||
} | ||
|
||
[Fact] | ||
public async Task Search() | ||
{ | ||
// Arrange | ||
var path = ApiEndpoints.SearchApiUrls.Search(); | ||
var jsonData = await File.ReadAllTextAsync("data/search/SearchResponse.json"); | ||
|
||
Server.Given(CreatePostRequestBuilder(path)) | ||
.RespondWith( | ||
Response.Create() | ||
.WithStatusCode(200) | ||
.WithBody(jsonData) | ||
); | ||
|
||
SearchParameters searchParameters = new SearchParameters() | ||
{ | ||
Query = "External tasks", | ||
Sort = new SearchSort | ||
{ | ||
Direction = SearchDirection.Ascending, | ||
Timestamp = "last_edited_time" | ||
} | ||
}; | ||
|
||
// Act | ||
var searchResult = await _client.SearchAsync(searchParameters); | ||
|
||
// Assert | ||
var results = searchResult.Results; | ||
|
||
results.Should().SatisfyRespectively( | ||
obj => | ||
{ | ||
obj.Object.Should().Be(ObjectType.Database); | ||
|
||
var database = (Database)obj; | ||
database.Properties.Should().HaveCount(2); | ||
}, | ||
obj => | ||
{ | ||
obj.Object.Should().Be(ObjectType.Page); | ||
|
||
var page = (Page)obj; | ||
page.IsArchived.Should().BeFalse(); | ||
page.Properties.Should().HaveCount(1); | ||
page.Parent.Should().BeAssignableTo<DatabaseParent>(); | ||
((DatabaseParent)page.Parent).DatabaseId.Should().Be("e6c6f8ff-c70e-4970-91ba-98f03e0d7fc6"); | ||
} | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
{ | ||
"has_more": false, | ||
"next_cursor": null, | ||
"object": "list", | ||
"results": [ | ||
{ | ||
"created_time": "2021-04-22T22:23:26.080Z", | ||
"id": "e6c6f8ff-c70e-4970-91ba-98f03e0d7fc6", | ||
"last_edited_time": "2021-04-23T04:21:00.000Z", | ||
"object": "database", | ||
"properties": { | ||
"Name": { | ||
"id": "title", | ||
"title": {}, | ||
"type": "title" | ||
}, | ||
"Task Type": { | ||
"id": "vd@l", | ||
"multi_select": { | ||
"options": [] | ||
}, | ||
"type": "multi_select" | ||
} | ||
}, | ||
"title": [ | ||
{ | ||
"annotations": { | ||
"bold": false, | ||
"code": false, | ||
"color": "default", | ||
"italic": false, | ||
"strikethrough": false, | ||
"underline": false | ||
}, | ||
"href": null, | ||
"plain_text": "Tasks", | ||
"text": { | ||
"content": "Tasks", | ||
"link": null | ||
}, | ||
"type": "text" | ||
} | ||
] | ||
}, | ||
{ | ||
"archived": false, | ||
"created_time": "2021-04-23T04:21:00.000Z", | ||
"id": "4f555b50-3a9b-49cb-924c-3746f4ca5522", | ||
"last_edited_time": "2021-04-23T04:21:00.000Z", | ||
"object": "page", | ||
"parent": { | ||
"database_id": "e6c6f8ff-c70e-4970-91ba-98f03e0d7fc6", | ||
"type": "database_id" | ||
}, | ||
"properties": { | ||
"Name": { | ||
"id": "title", | ||
"title": [ | ||
{ | ||
"annotations": { | ||
"bold": false, | ||
"code": false, | ||
"color": "default", | ||
"italic": false, | ||
"strikethrough": false, | ||
"underline": false | ||
}, | ||
"href": null, | ||
"plain_text": "Task 1", | ||
"text": { | ||
"content": "Task1 1", | ||
"link": null | ||
}, | ||
"type": "text" | ||
} | ||
], | ||
"type": "title" | ||
} | ||
} | ||
} | ||
] | ||
} |