Skip to content

Commit 6aae5e2

Browse files
Merge pull request #192 from notion-dotnet/feature/191-add-support-for-divider-block-type
Adds support for updating divider block type ✨
2 parents 82e978d + c45b484 commit 6aae5e2

File tree

4 files changed

+119
-8
lines changed

4 files changed

+119
-8
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Notion.Client
4+
{
5+
public class DividerUpdateBlock : IUpdateBlock
6+
{
7+
public bool Archived { get; set; }
8+
9+
[JsonProperty("divider")]
10+
public Data Divider { get; set; }
11+
12+
public class Data
13+
{
14+
}
15+
16+
public DividerUpdateBlock()
17+
{
18+
Divider = new Data();
19+
}
20+
}
21+
}

Src/Notion.Client/Models/Blocks/BlockType.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ public enum BlockType
6161
[EnumMember(Value = "breadcrumb")]
6262
Breadcrumb,
6363

64+
[EnumMember(Value = "divider")]
65+
Divider,
66+
6467
[EnumMember(Value = "unsupported")]
6568
Unsupported
6669
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Notion.Client
4+
{
5+
public class DividerBlock : Block
6+
{
7+
public override BlockType Type => BlockType.Divider;
8+
9+
[JsonProperty("divider")]
10+
public Data Divider { get; set; }
11+
12+
public class Data
13+
{
14+
}
15+
}
16+
}

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)