8000 Adds support for divider block type by KoditkarVedant · Pull Request #192 · notion-dotnet/notion-sdk-net · GitHub
[go: up one dir, main page]

Skip to content

Adds support for divider block type #192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Newtonsoft.Json;

namespace Notion.Client
{
public class DividerUpdateBlock : IUpdateBlock
{
public bool Archived { get; set; }

[JsonProperty("divider")]
public Data Divider { get; set; }

public class Data
{
}

public DividerUpdateBlock()
{
Divider = new Data();
}
}
}
3 changes: 3 additions & 0 deletions Src/Notion.Client/Models/Blocks/BlockType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public enum BlockType
[EnumMember(Value = "breadcrumb")]
Breadcrumb,

[EnumMember(Value = "divider")]
Divider,

[EnumMember(Value = "unsupported")]
Unsupported
}
Expand Down
16 changes: 16 additions & 0 deletions Src/Notion.Client/Models/Blocks/DividerBlock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Newtonsoft.Json;

namespace Notion.Client
{
public class DividerBlock : Block
{
public override BlockType Type => BlockType.Divider;

[JsonProperty("divider")]
public Data Divider { get; set; }

public class Data
{
}
}
}
87 changes: 79 additions & 8 deletions Test/Notion.IntegrationTests/IBlocksClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,45 @@ public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks()
INotionClient _client = NotionClientFactory.Create(options);

var pageId = "3c357473a28149a488c010d2b245a589";

var page = await _client.Pages.CreateAsync(
PagesCreateParametersBuilder.Create(
new ParentPageInput()
{
PageId = pageId
}
).Build()
);

var blocks = await _client.Blocks.AppendChildrenAsync(
pageId,
page.Id,
new BlocksAppendChildrenParameters
{
Children = new List<Block>()
{
new BreadcrumbBlock
{
Breadcrumb = new BreadcrumbBlock.Data()
},
new DividerBlock
{
Divider = new DividerBlock.Data()
}
}
}
);

blocks.Results.Should().HaveCount(1);
blocks.Results.Should().HaveCount(2);

// cleanup
var tasks = blocks.Results.Select(x => _client.Blocks.DeleteAsync(x.Id));
await Task.WhenAll(tasks);
await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters
{
Archived = true
});
}

[Fact]
public async Task UpdateBlobkAsync_UpdatesGivenBlock()
public async Task UpdateBlockAsync_UpdatesGivenBlock()
{
var options = new ClientOptions
{
Expand All @@ -51,8 +67,18 @@ public async Task UpdateBlobkAsync_UpdatesGivenBlock()
INotionClient _client = NotionClientFactory.Create(options);

var pageId = "3c357473a28149a488c010d2b245a589";

var page = await _client.Pages.CreateAsync(
PagesCreateParametersBuilder.Create(
new ParentPageInput()
{
PageId = pageId
}
).Build()
);

var blocks = await _client.Blocks.AppendChildrenAsync(
pageId,
page.Id,
new BlocksAppendChildrenParameters
{
Children = new List<Block>()
Expand All @@ -72,8 +98,53 @@ public async Task UpdateBlobkAsync_UpdatesGivenBlock()
blocks.Results.Should().HaveCount(1);

// cleanup
var tasks = blocks.Results.Select(x => _client.Blocks.DeleteAsync(x.Id));
await Task.WhenAll(tasks);
await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters
{
Archived = true
});
}

[Fact]
public async Task DeleteAsync_DeleteBlockWithGivenId()
{
var options = new ClientOptions
{
AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN")
};
INotionClient _client = NotionClientFactory.Create(options);

var pageId = "3c357473a28149a488c010d2b245a589";

var page = await _client.Pages.CreateAsync(
PagesCreateParametersBuilder.Create(
new ParentPageInput()
{
PageId = pageId
}
).Build()
);

var blocks = await _client.Blocks.AppendChildrenAsync(
page.Id,
new BlocksAppendChildrenParameters
{
Children = new List<Block>()
{
new DividerBlock
{
Divider = new DividerBlock.Data()
}
}
}
);

blocks.Results.Should().HaveCount(1);

// cleanup
await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters
{
Archived = true
});
}
}
}
0