Skip to content
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
});
}
}
}