-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #186 from notion-dotnet/feature/181-add-support-fo…
…r-breadcrumb-block Add support for breadcrumb block ✨
- Loading branch information
Showing
4 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
...ent/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BreadcrumbUpdateBlock.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |