Skip to content

Commit 0693e64

Browse files
Add integration tests for BlocksClient ✅
1 parent c9bb91b commit 0693e64

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using FluentAssertions;
6+
using Notion.Client;
7+
using Xunit;
8+
9+
namespace Notion.IntegrationTests
10+
{
11+
public class IBlocksClientTests
12+
{
13+
[Fact]
14+
public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks()
15+
{
16+
var options = new ClientOptions
17+
{
18+
AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN")
19+
};
20+
INotionClient _client = new NotionClient(options);
21+
22+
var pageId = "3c357473a28149a488c010d2b245a589";
23+
var blocks = await _client.Blocks.AppendChildrenAsync(
24+
pageId,
25+
new BlocksAppendChildrenParameters
26+
{
27+
Children = new List<Block>()
28+
{
29+
new BreadcrumbBlock
30+
{
31+
Breadcrumb = new BreadcrumbBlock.Data()
32+
}
33+
}
34+
}
35+
);
36+
37+
blocks.Results.Should().HaveCount(1);
38+
39+
// cleanup
40+
var tasks = blocks.Results.Select(x => _client.Blocks.DeleteAsync(x.Id));
41+
await Task.WhenAll(tasks);
42+
}
43+
44+
[Fact]
45+
public async Task UpdateBlobkAsync_UpdatesGivenBlock()
46+
{
47+
var options = new ClientOptions
48+
{
49+
AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN")
50+
};
51+
INotionClient _client = new NotionClient(options);
52+
53+
var pageId = "3c357473a28149a488c010d2b245a589";
54+
var blocks = await _client.Blocks.AppendChildrenAsync(
55+
pageId,
56+
new BlocksAppendChildrenParameters
57+
{
58+
Children = new List<Block>()
59+
{
60+
new BreadcrumbBlock
61+
{
62+
Breadcrumb = new BreadcrumbBlock.Data()
63+
}
64+
}
65+
}
66+
);
67+
68+
var blockId = blocks.Results.First().Id;
69+
await _client.Blocks.UpdateAsync(blockId, new BreadcrumbUpdateBlock());
70+
71+
72+
blocks = await _client.Blocks.RetrieveChildrenAsync(pageId);
73+
blocks.Results.Should().HaveCount(1);
74+
75+
// cleanup
76+
var tasks = blocks.Results.Select(x => _client.Blocks.DeleteAsync(x.Id));
77+
await Task.WhenAll(tasks);
78+
}
79+
}
80+
}

0 commit comments

Comments
 (0)