Skip to content

Commit

Permalink
Merge pull request #186 from notion-dotnet/feature/181-add-support-fo…
Browse files Browse the repository at this point in the history
…r-breadcrumb-block

Add support for breadcrumb block ✨
  • Loading branch information
KoditkarVedant authored Nov 1, 2021
2 parents 957bd85 + 6b96d39 commit 809ea31
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Newtonsoft.Json;

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

[JsonProperty("breadcrumb")]
public Data Breadcrumb { get; set; }

public class Data
{
}

public BreadcrumbUpdateBlock()
{
Breadcrumb = 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 @@ -58,6 +58,9 @@ public enum BlockType
[EnumMember(Value = "equation")]
Equation,

[EnumMember(Value = "breadcrumb")]
Breadcrumb,

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

namespace Notion.Client
{
public class BreadcrumbBlock : Block
{
public override BlockType Type => BlockType.Breadcrumb;

[JsonProperty("breadcrumb")]
public Data Breadcrumb { get; set; }

public class Data
{
}
}
}
79 changes: 79 additions & 0 deletions Test/Notion.IntegrationTests/IBlocksClientTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using FluentAssertions;
using Notion.Client;
using Xunit;

namespace Notion.IntegrationTests
{
public class IBlocksClientTests
{
[Fact]
public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks()
{
var options = new ClientOptions
{
AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN")
};
INotionClient _client = NotionClientFactory.Create(options);

var pageId = "3c357473a28149a488c010d2b245a589";
var blocks = await _client.Blocks.AppendChildrenAsync(
pageId,
new BlocksAppendChildrenParameters
{
Children = new List<Block>()
{
new BreadcrumbBlock
{
Breadcrumb = new BreadcrumbBlock.Data()
}
}
}
);

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

// cleanup
var tasks = blocks.Results.Select(x => _client.Blocks.DeleteAsync(x.Id));
await Task.WhenAll(tasks);
}

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

var pageId = "3c357473a28149a488c010d2b245a589";
var blocks = await _client.Blocks.AppendChildrenAsync(
pageId,
new BlocksAppendChildrenParameters
{
Children = new List<Block>()
{
new BreadcrumbBlock
{
Breadcrumb = new BreadcrumbBlock.Data()
}
}
}
);

var blockId = blocks.Results.First().Id;
await _client.Blocks.UpdateAsync(blockId, new BreadcrumbUpdateBlock());

blocks = await _client.Blocks.RetrieveChildrenAsync(pageId);
blocks.Results.Should().HaveCount(1);

// cleanup
var tasks = blocks.Results.Select(x => _client.Blocks.DeleteAsync(x.Id));
await Task.WhenAll(tasks);
}
}
}

0 comments on commit 809ea31

Please sign in to comment.