Skip to content

Commit 291adba

Browse files
Add tests & fix them to run in parallel ✅
1 parent cc8ff36 commit 291adba

File tree

1 file changed

+79
-8
lines changed

1 file changed

+79
-8
lines changed

Test/Notion.IntegrationTests/IBlocksClientTests.cs

Lines changed: 79 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,45 @@ public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks()
2020
INotionClient _client = NotionClientFactory.Create(options);
2121

2222
var pageId = "3c357473a28149a488c010d2b245a589";
23+
24+
var page = await _client.Pages.CreateAsync(
25+
PagesCreateParametersBuilder.Create(
26+
new ParentPageInput()
27+
{
28+
PageId = pageId
29+
}
30+
).Build()
31+
);
32+
2333
var blocks = await _client.Blocks.AppendChildrenAsync(
24-
pageId,
34+
page.Id,
2535
new BlocksAppendChildrenParameters
2636
{
2737
Children = new List<Block>()
2838
{
2939
new BreadcrumbBlock
3040
{
3141
Breadcrumb = new BreadcrumbBlock.Data()
42+
},
43+
new DividerBlock
44+
{
45+
Divider = new DividerBlock.Data()
3246
}
3347
}
3448
}
3549
);
3650

37-
blocks.Results.Should().HaveCount(1);
51+
blocks.Results.Should().HaveCount(2);
3852

3953
// cleanup
40-
var tasks = blocks.Results.Select(x => _client.Blocks.DeleteAsync(x.Id));
41-
await Task.WhenAll(tasks);
54+
await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters
55+
{
56+
Archived = true
57+
});
4258
}
4359

4460
[Fact]
45-
public async Task UpdateBlobkAsync_UpdatesGivenBlock()
61+
public async Task UpdateBlockAsync_UpdatesGivenBlock()
4662
{
4763
var options = new ClientOptions
4864
{
@@ -51,8 +67,18 @@ public async Task UpdateBlobkAsync_UpdatesGivenBlock()
5167
INotionClient _client = NotionClientFactory.Create(options);
5268

5369
var pageId = "3c357473a28149a488c010d2b245a589";
70+
71+
var page = await _client.Pages.CreateAsync(
72+
PagesCreateParametersBuilder.Create(
73+
new ParentPageInput()
74+
{
75+
PageId = pageId
76+
}
77+
).Build()
78+
);
79+
5480
var blocks = await _client.Blocks.AppendChildrenAsync(
55-
pageId,
81+
page.Id,
5682
new BlocksAppendChildrenParameters
5783
{
5884
Children = new List<Block>()
@@ -72,8 +98,53 @@ public async Task UpdateBlobkAsync_UpdatesGivenBlock()
7298
blocks.Results.Should().HaveCount(1);
7399

74100
// cleanup
75-
var tasks = blocks.Results.Select(x => _client.Blocks.DeleteAsync(x.Id));
76-
await Task.WhenAll(tasks);
101+
await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters
102+
{
103+
Archived = true
104+
});
105+
}
106+
107+
[Fact]
108+
public async Task DeleteAsync_DeleteBlockWithGivenId()
109+
{
110+
var options = new ClientOptions
111+
{
112+
AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN")
113+
};
114+
INotionClient _client = NotionClientFactory.Create(options);
115+
116+
var pageId = "3c357473a28149a488c010d2b245a589";
117+
118+
var page = await _client.Pages.CreateAsync(
119+
PagesCreateParametersBuilder.Create(
120+
new ParentPageInput()
121+
{
122+
PageId = pageId
123+
}
124+
).Build()
125+
);
126+
127+
var blocks = await _client.Blocks.AppendChildrenAsync(
128+
page.Id,
129+
new BlocksAppendChildrenParameters
130+
{
131+
Children = new List<Block>()
132+
{
133+
new DividerBlock
134+
{
135+
Divider = new DividerBlock.Data()
136+
}
137+
}
138+
}
139+
);
140+
141+
blocks.Results.Should().HaveCount(1);
142+
143+
// cleanup
144+
await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters
145+
{
146+
Archived = true
147+
});
77148
}
78149
}
79150
}

0 commit comments

Comments
 (0)