8000 Fix table block children property type by KoditkarVedant · Pull Request #354 · notion-dotnet/notion-sdk-net · GitHub
[go: up one dir, main page]

Skip to content

Fix table block children property type #354

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
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
9 changes: 5 additions & 4 deletions Src/Notion.Client/Models/Blocks/TableBlock.cs
Original file line number Diff line number Diff line change
@@ -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; }
Expand All @@ -21,7 +22,7 @@ public class TableInfo
public bool HasRowHeader { get; set; }

[JsonProperty("children")]
public TableRowBlock Children { get; set; }
public IEnumerable<TableRowBlock> Children { get; set; }
}
}
}
81 changes: 60 additions & 21 deletions Test/Notion.IntegrationTests/IBlocksClientTests.cs
8000
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public async Task DeleteAsync_DeleteBlockWithGivenId()

[Theory]
[MemberData(nameof(BlockData))]
public async Task UpdateAsync_UpdatesGivenBlock(IBlock block, IUpdateBlock updateBlock, Action<IBlock> assert)
public async Task UpdateAsync_UpdatesGivenBlock(
IBlock block, IUpdateBlock updateBlock, Action<IBlock, INotionClient> assert)
{
var page = await Client.Pages.CreateAsync(
PagesCreateParametersBuilder.Create(
Expand All @@ -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 });
Expand Down Expand Up @@ -159,7 +160,7 @@ private static IEnumerable<object[]> BlockData()
}
}
},
new Action<IBlock>(block =>
new Action<IBlock, INotionClient>((block, client) =>
{
var updatedBlock = (BookmarkBlock)block;
Assert.Equal("https://github.com/notion-dotnet/notion-sdk-net", updatedBlock.Bookmark.Url);
Expand All @@ -170,7 +171,7 @@ private static IEnumerable<object[]> BlockData()
{
new EquationBlock { Equation = new EquationBlock.Info { Expression = "e=mc^3" } },
new EquationUpdateBlock { Equation = new EquationUpdateBlock.Info { Expression = "e=mc^2" } },
new Action<IBlock>(block =>
new Action<IBlock, INotionClient>((block, client) =>
{
var updatedBlock = (EquationBlock)block;
Assert.Equal("e=mc^2", updatedBlock.Equation.Expression);
Expand Down Expand Up @@ -207,10 +208,10 @@ private static IEnumerable<object[]> BlockData()
}
}
},
new Action<IBlock>(block =>
new Action<IBlock, INotionClient>((block, client) =>
{
block.Should().NotBeNull();

block.Should().BeOfType<AudioBlock>().Subject
.Audio.Should().BeOfType<ExternalFile>().Subject
.External.Url.Should().Be("https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3");
Expand All @@ -219,7 +220,7 @@ private static IEnumerable<object[]> BlockData()
new object[]
{
new TableOfContentsBlock { TableOfContents = new TableOfContentsBlock.Data() },
new TableOfContentsUpdateBlock(), new Action<IBlock>(block =>
new TableOfContentsUpdateBlock(), new Action<IBlock, INotionClient>((block, client) =>
{
Assert.NotNull(block);
_ = Assert.IsType<TableOfContentsBlock>(block);
Expand Down Expand Up @@ -247,11 +248,11 @@ private static IEnumerable<object[]> BlockData()
}
}
},
new Action<IBlock>(block =>
new Action<IBlock, INotionClient>((block, client) =>
{
Assert.NotNull(block);
var calloutBlock = Assert.IsType<CalloutBlock>(block);

Assert.Equal("Test 2", calloutBlock.Callout.RichText.OfType<RichTextText>().First().Text.Content);
})
},
Expand All @@ -277,11 +278,11 @@ private static IEnumerable<object[]> BlockData()
}
}
},
new Action<IBlock>(block =>
new Action<IBlock, INotionClient>((block, client) =>
{
Assert.NotNull(block);
var quoteBlock = Assert.IsType<QuoteBlock>(block);

Assert.Equal("Test 2", quoteBlock.Quote.RichText.OfType<RichTextText>().First().Text.Content);
})
},
Expand All @@ -308,12 +309,12 @@ private static IEnumerable<object[]> BlockData()
}
}
},
new Action<IBlock>(block =>
new Action<IBlock, INotionClient>((block, client) =>
{
Assert.NotNull(block);
var imageBlock = Assert.IsType<ImageBlock>(block);
var imageFile = Assert.IsType<ExternalFile>(imageBlock.Image);

Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg",
imageFile.External.Url);
})
Expand All @@ -334,11 +335,11 @@ private static IEnumerable<object[]> BlockData()
Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg"
}
},
new Action<IBlock>(block =>
new Action<IBlock, INotionClient>((block, client) =>
{
Assert.NotNull(block);
var embedBlock = Assert.IsType<EmbedBlock>(block);

Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg",
embedBlock.Embed.Url);
})
Expand Down Expand Up @@ -376,14 +377,14 @@ private static IEnumerable<object[]> BlockData()
}
}
},
new Action<IBlock>(block =>
new Action<IBlock, INotionClient>((block, client) =>
{
Assert.NotNull(block);
var templateBlock = Assert.IsType<TemplateBlock>(block);

Assert.Single(templateBlock.Template.RichText);
Assert.Null(templateBlock.Template.Children);

Assert.Equal("Test Template 2",
templateBlock.Template.RichText.OfType<RichTextText>().First().Text.Content);
})
Expand All @@ -402,17 +403,55 @@ private static IEnumerable<object[]> BlockData()
{
LinkToPage = new ParentPageInput { PageId = "3c357473a28149a488c010d2b245a589" }
},
new Action<IBlock>(block =>
new Action<IBlock, INotionClient>((block, client) =>
{
Assert.NotNull(block);
var linkToPageBlock = Assert.IsType<LinkToPageBlock>(block);

var pageParent = Assert.IsType<PageParent>(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<IBlock, INotionClient>((block, client) =>
{
var tableBlock = block.Should().NotBeNull().And.BeOfType<TableBlock>().Subject;
tableBlock.HasChildren.Should().BeTrue();

var children = client.Blocks.RetrieveChildrenAsync(tableBlock.Id).GetAwaiter().GetResult();

children.Results.Should().ContainSingle()
.Subject.Should().BeOfType<TableRowBlock>()
.Subject.TableRow.Cells.Should().ContainSingle()
.Subject.Should().ContainSingle()
.Subject.Should().BeOfType<RichTextText>()
.Subject.Text.Content.Should().Be("Data");
})
}
};
}
Expand Down
0