Skip to content

Commit e4c104c

Browse files
Merge pull request #108 from notion-dotnet/test/add-unit-or-integration-tests-for-users-client
Add tests for Users client ✅
2 parents ad24fcc + c8097b3 commit e4c104c

File tree

4 files changed

+101
-14
lines changed

4 files changed

+101
-14
lines changed

Test/Notion.UnitTests/Notion.UnitTests.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@
6666
<None Update="data\databases\DatabasesQueryResponse.json">
6767
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
6868
</None>
69+
<None Update="data\users\ListUsersResponse.json">
70+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
71+
</None>
72+
<None Update="data\users\RetrieveUserResponse.json">
73+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
74+
</None>
6975
</ItemGroup>
7076

7177
</Project>
Lines changed: 60 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,82 @@
1-
using System.Threading.Tasks;
1+
using System.IO;
2+
using System.Threading.Tasks;
3+
using FluentAssertions;
24
using Notion.Client;
5+
using WireMock.ResponseBuilders;
36
using Xunit;
47

58
namespace Notion.UnitTests
69
{
7-
public class UserClientTest
10+
public class UserClientTest : ApiTestBase
811
{
912
private readonly IUsersClient _client;
1013

1114
public UserClientTest()
1215
{
13-
var options = new ClientOptions
14-
{
15-
AuthToken = "<Token>"
16-
};
17-
18-
_client = new UsersClient(new RestClient(options));
16+
_client = new UsersClient(new RestClient(ClientOptions));
1917
}
2018

21-
[Fact(Skip = "Internal testing purpose")]
19+
[Fact]
2220
public async Task ListUsers()
2321
{
24-
var usersList = await _client.ListAsync();
25-
Assert.NotNull(usersList);
22+
// Arrange
23+
var jsonData = await File.ReadAllTextAsync("data/users/ListUsersResponse.json");
24+
var path = ApiEndpoints.UsersApiUrls.List();
25+
26+
Server.Given(CreateGetRequestBuilder(path))
27+
.RespondWith(
28+
Response.Create()
29+
.WithStatusCode(200)
30+
.WithBody(jsonData)
31+
);
32+
33+
// Act
34+
var users = await _client.ListAsync();
35+
36+
// Assert
37+
users.Results.Should().SatisfyRespectively(
38+
user =>
39+
{
40+
user.Id.Should().Be("5e37c1b4-630f-4e81-bd6b-296af31e345f");
41+
user.Name.Should().Be("Vedant Koditkar");
42+
user.Type.Should().Be("person");
43+
user.Person.Email.Should().Be("vedkoditkar@gmail.com");
44+
user.Bot.Should().BeNull();
45+
},
46+
user =>
47+
{
48+
user.Id.Should().Be("590693f3-797f-4970-98ff-7284106393e5");
49+
user.Name.Should().Be("Test");
50+
user.Type.Should().Be("bot");
51+
user.Person.Should().BeNull();
52+
}
53+
);
2654
}
2755

28-
[Fact(Skip = "Internal testing purpose")]
56+
[Fact]
2957
public async Task RetrieveUser()
3058
{
31-
string userId = "5e37c1b4-630f-4e81-bd6b-296af31e345f";
59+
// Arrange
60+
var jsonData = await File.ReadAllTextAsync("data/users/RetrieveUserResponse.json");
61+
var userId = "5e37c1b4-630f-4e81-bd6b-296af31e345f";
62+
var path = ApiEndpoints.UsersApiUrls.Retrieve(userId);
63+
64+
Server.Given(CreateGetRequestBuilder(path))
65+
.RespondWith(
66+
Response.Create()
67+
.WithStatusCode(200)
68+
.WithBody(jsonData)
69+
);
70+
71+
// Act
3272
var user = await _client.RetrieveAsync(userId);
33-
Assert.NotNull(user);
73+
74+
// Assert
75+
user.Id.Should().Be("5e37c1b4-630f-4e81-bd6b-296af31e345f");
76+
user.Name.Should().Be("Vedant Koditkar");
77+
user.Type.Should().Be("person");
78+
user.Person.Email.Should().Be("vedkoditkar@gmail.com");
79+
user.Bot.Should().BeNull();
3480
}
3581
}
3682
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"object": "list",
3+
"results": [
4+
{
5+
"object": "user",
6+
"id": "5e37c1b4-630f-4e81-bd6b-296af31e345f",
7+
"name": "Vedant Koditkar",
8+
"avatar_url": "https://lh3.googleusercontent.com/a-/AOh14Gg4lnfwJviST_tKZZpMfKrgmjp8wRzPBg9ec6sG7w=s100",
9+
"type": "person",
10+
"person": {
11+
"email": "vedkoditkar@gmail.com"
12+
}
13+
},
14+
{
15+
"object": "user",
16+
"id": "590693f3-797f-4970-98ff-7284106393e5",
17+
"name": "Test",
18+
"avatar_url": null,
19+
"type": "bot",
20+
"bot": {}
21+
}
22+
],
23+
"next_cursor": null,
24+
"has_more": false
25+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"object": "user",
3+
"id": "5e37c1b4-630f-4e81-bd6b-296af31e345f",
4+
"name": "Vedant Koditkar",
5+
"avatar_url": "https://lh3.googleusercontent.com/a-/AOh14Gg4lnfwJviST_tKZZpMfKrgmjp8wRzPBg9ec6sG7w=s100",
6+
"type": "person",
7+
"person": {
8+
"email": "vedkoditkar@gmail.com"
9+
}
10+
}

0 commit comments

Comments
 (0)