From 798f6782046db15480380ef12fa4edee338b5153 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Tue, 24 Jan 2023 17:30:14 +0530 Subject: [PATCH] 347 fix table block children property type --- Src/Notion.Client/Models/Blocks/TableBlock.cs | 9 ++- .../IBlocksClientTests.cs | 81 ++++++++++++++----- 2 files changed, 65 insertions(+), 25 deletions(-) diff --git a/Src/Notion.Client/Models/Blocks/TableBlock.cs b/Src/Notion.Client/Models/Blocks/TableBlock.cs index cf41440c..80fe72bc 100644 --- a/Src/Notion.Client/Models/Blocks/TableBlock.cs +++ b/Src/Notion.Client/Models/Blocks/TableBlock.cs @@ -1,15 +1,16 @@ -using Newtonsoft.Json; +using System.Collections.Generic; +using Newtonsoft.Json; namespace Notion.Client { public class TableBlock : Block, IColumnChildrenBlock, INonColumnBlock { [JsonProperty("table")] - public TableInfo Table { get; set; } + public Info Table { get; set; } public override BlockType Type => BlockType.Table; - public class TableInfo + public class Info { [JsonProperty("table_width")] public int TableWidth { get; set; } @@ -21,7 +22,7 @@ public class TableInfo public bool HasRowHeader { get; set; } [JsonProperty("children")] - public TableRowBlock Children { get; set; } + public IEnumerable Children { get; set; } } } } diff --git a/Test/Notion.IntegrationTests/IBlocksClientTests.cs b/Test/Notion.IntegrationTests/IBlocksClientTests.cs index 9aed7872..6f10189c 100644 --- a/Test/Notion.IntegrationTests/IBlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/IBlocksClientTests.cs @@ -104,7 +104,8 @@ public async Task DeleteAsync_DeleteBlockWithGivenId() [Theory] [MemberData(nameof(BlockData))] - public async Task UpdateAsync_UpdatesGivenBlock(IBlock block, IUpdateBlock updateBlock, Action assert) + public async Task UpdateAsync_UpdatesGivenBlock( + IBlock block, IUpdateBlock updateBlock, Action assert) { var page = await Client.Pages.CreateAsync( PagesCreateParametersBuilder.Create( @@ -125,7 +126,7 @@ public async Task UpdateAsync_UpdatesGivenBlock(IBlock block, IUpdateBlock updat var updatedBlock = blocks.Results.First(); - assert.Invoke(updatedBlock); + assert.Invoke(updatedBlock, Client); // cleanup await Client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); @@ -159,7 +160,7 @@ private static IEnumerable BlockData() } } }, - new Action(block => + new Action((block, client) => { var updatedBlock = (BookmarkBlock)block; Assert.Equal("https://github.com/notion-dotnet/notion-sdk-net", updatedBlock.Bookmark.Url); @@ -170,7 +171,7 @@ private static IEnumerable BlockData() { new EquationBlock { Equation = new EquationBlock.Info { Expression = "e=mc^3" } }, new EquationUpdateBlock { Equation = new EquationUpdateBlock.Info { Expression = "e=mc^2" } }, - new Action(block => + new Action((block, client) => { var updatedBlock = (EquationBlock)block; Assert.Equal("e=mc^2", updatedBlock.Equation.Expression); @@ -207,10 +208,10 @@ private static IEnumerable BlockData() } } }, - new Action(block => + new Action((block, client) => { block.Should().NotBeNull(); - + block.Should().BeOfType().Subject .Audio.Should().BeOfType().Subject .External.Url.Should().Be("https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3"); @@ -219,7 +220,7 @@ private static IEnumerable BlockData() new object[] { new TableOfContentsBlock { TableOfContents = new TableOfContentsBlock.Data() }, - new TableOfContentsUpdateBlock(), new Action(block => + new TableOfContentsUpdateBlock(), new Action((block, client) => { Assert.NotNull(block); _ = Assert.IsType(block); @@ -247,11 +248,11 @@ private static IEnumerable BlockData() } } }, - new Action(block => + new Action((block, client) => { Assert.NotNull(block); var calloutBlock = Assert.IsType(block); - + Assert.Equal("Test 2", calloutBlock.Callout.RichText.OfType().First().Text.Content); }) }, @@ -277,11 +278,11 @@ private static IEnumerable BlockData() } } }, - new Action(block => + new Action((block, client) => { Assert.NotNull(block); var quoteBlock = Assert.IsType(block); - + Assert.Equal("Test 2", quoteBlock.Quote.RichText.OfType().First().Text.Content); }) }, @@ -308,12 +309,12 @@ private static IEnumerable BlockData() } } }, - new Action(block => + new Action((block, client) => { Assert.NotNull(block); var imageBlock = Assert.IsType(block); var imageFile = Assert.IsType(imageBlock.Image); - + Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", imageFile.External.Url); }) @@ -334,11 +335,11 @@ private static IEnumerable BlockData() Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg" } }, - new Action(block => + new Action((block, client) => { Assert.NotNull(block); var embedBlock = Assert.IsType(block); - + Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", embedBlock.Embed.Url); }) @@ -376,14 +377,14 @@ private static IEnumerable BlockData() } } }, - new Action(block => + new Action((block, client) => { Assert.NotNull(block); var templateBlock = Assert.IsType(block); - + Assert.Single(templateBlock.Template.RichText); Assert.Null(templateBlock.Template.Children); - + Assert.Equal("Test Template 2", templateBlock.Template.RichText.OfType().First().Text.Content); }) @@ -402,17 +403,55 @@ private static IEnumerable BlockData() { LinkToPage = new ParentPageInput { PageId = "3c357473a28149a488c010d2b245a589" } }, - new Action(block => + new Action((block, client) => { Assert.NotNull(block); var linkToPageBlock = Assert.IsType(block); - + var pageParent = Assert.IsType(linkToPageBlock.LinkToPage); - + // TODO: Currently the api doesn't allow to update the link_to_page block type // This will change to updated ID once api start to support Assert.Equal(Guid.Parse("533578e3edf14c0a91a9da6b09bac3ee"), Guid.Parse(pageParent.PageId)); }) + }, + new object[] + { + new TableBlock + { + Table = new TableBlock.Info + { + TableWidth = 1, + Children = new[] + { + new TableRowBlock + { + TableRow = new TableRowBlock.Info + { + Cells = new[] + { + new[] { new RichTextText { Text = new Text { Content = "Data" } } } + } + } + } + } + } + }, + new TableUpdateBlock { Table = new TableUpdateBlock.Info { HasColumnHeader = false } }, + new Action((block, client) => + { + var tableBlock = block.Should().NotBeNull().And.BeOfType().Subject; + tableBlock.HasChildren.Should().BeTrue(); + + var children = client.Blocks.RetrieveChildrenAsync(tableBlock.Id).GetAwaiter().GetResult(); + + children.Results.Should().ContainSingle() + .Subject.Should().BeOfType() + .Subject.TableRow.Cells.Should().ContainSingle() + .Subject.Should().ContainSingle() + .Subject.Should().BeOfType() + .Subject.Text.Content.Should().Be("Data"); + }) } }; }