|
1 | | -using System.Threading.Tasks; |
| 1 | +using System.IO; |
| 2 | +using System.Threading.Tasks; |
| 3 | +using FluentAssertions; |
2 | 4 | using Notion.Client; |
| 5 | +using WireMock.ResponseBuilders; |
3 | 6 | using Xunit; |
4 | 7 |
|
5 | 8 | namespace Notion.UnitTests |
6 | 9 | { |
7 | | - public class UserClientTest |
| 10 | + public class UserClientTest : ApiTestBase |
8 | 11 | { |
9 | 12 | private readonly IUsersClient _client; |
10 | 13 |
|
11 | 14 | public UserClientTest() |
12 | 15 | { |
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)); |
19 | 17 | } |
20 | 18 |
|
21 | | - [Fact(Skip = "Internal testing purpose")] |
| 19 | + [Fact] |
22 | 20 | public async Task ListUsers() |
23 | 21 | { |
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 | + ); |
26 | 54 | } |
27 | 55 |
|
28 | | - [Fact(Skip = "Internal testing purpose")] |
| 56 | + [Fact] |
29 | 57 | public async Task RetrieveUser() |
30 | 58 | { |
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 |
32 | 72 | 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(); |
34 | 80 | } |
35 | 81 | } |
36 | 82 | } |
0 commit comments