Skip to content

Commit 7d19d4e

Browse files
Add unit test for Retrieve block api ✅
1 parent 4b62a88 commit 7d19d4e

File tree

3 files changed

+65
-7
lines changed

3 files changed

+65
-7
lines changed

Test/Notion.UnitTests/BlocksClientTests.cs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
using System.Collections.Generic;
2+
using System.IO;
3+
using System.Linq;
24
using System.Threading.Tasks;
5+
using FluentAssertions;
36
using Notion.Client;
7+
using WireMock.ResponseBuilders;
48
using Xunit;
59

610
namespace Notion.UnitTests
711
{
8-
public class BlocksClientTests
12+
public class BlocksClientTests : ApiTestBase
913
{
1014
private readonly IBlocksClient _client;
1115

1216
public BlocksClientTests()
1317
{
14-
var options = new ClientOptions()
15-
{
16-
AuthToken = "<Token>"
17-
};
18-
19-
_client = new BlocksClient(new RestClient(options));
18+
_client = new BlocksClient(new RestClient(ClientOptions));
2019
}
2120

2221
[Fact(Skip = "Dev only")]
@@ -61,5 +60,31 @@ public async Task AppendBlockChildren()
6160

6261
Assert.NotNull(block);
6362
}
63+
64+
[Fact]
65+
public async Task RetrieveAsync()
66+
{
67+
string blockId = "9bc30ad4-9373-46a5-84ab-0a7845ee52e6";
68+
var path = ApiEndpoints.BlocksApiUrls.Retrieve(blockId);
69+
var jsonData = await File.ReadAllTextAsync("data/blocks/RetrieveBlockResponse.json");
70+
71+
Server.Given(CreateGetRequestBuilder(path))
72+
.RespondWith(
73+
Response.Create()
74+
.WithStatusCode(200)
75+
.WithBody(jsonData)
76+
);
77+
78+
var block = await _client.Retrieve(blockId);
79+
80+
block.Id.Should().Be(blockId);
81+
block.HasChildren.Should().BeFalse();
82+
block.Type.Should().Be(BlockType.ToDo);
83+
84+
var todoBlock = ((ToDoBlock)block);
85+
todoBlock.ToDo.Text.Should().ContainSingle();
86+
todoBlock.ToDo.Text.First().Should().BeAssignableTo<RichTextText>();
87+
((RichTextText)todoBlock.ToDo.Text.First()).Text.Content.Should().Be("Lacinato kale");
88+
}
6489
}
6590
}

Test/Notion.UnitTests/Notion.UnitTests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
</ItemGroup>
2828

2929
<ItemGroup>
30+
<None Update="data\blocks\RetrieveBlockResponse.json">
31+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
32+
</None>
3033
<None Update="data\databases\CreateDatabaseResponse.json">
3134
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
3235
</None>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"object": "block",
3+
"id": "9bc30ad4-9373-46a5-84ab-0a7845ee52e6",
4+
"created_time": "2021-03-16T16:31:00.000Z",
5+
"last_edited_time": "2021-03-16T16:32:00.000Z",
6+
"has_children": false,
7+
"type": "to_do",
8+
"to_do": {
9+
"text": [
10+
{
11+
"type": "text",
12+
"text": {
13+
"content": "Lacinato kale",
14+
"link": null
15+
},
16+
"annotations": {
17+
"bold": false,
18+
"italic": false,
19+
"strikethrough": false,
20+
"underline": false,
21+
"code": false,
22+
"color": "default"
23+
},
24+
"plain_text": "Lacinato kale",
25+
"href": null
26+
}
27+
],
28+
"checked": false
29+
}
30+
}

0 commit comments

Comments
 (0)