8000 Merge pull request #197 from notion-dotnet/feature/193-add-support-fo… · notion-dotnet/notion-sdk-net@2ed2006 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2ed2006

Browse files
Merge pull request #197 from notion-dotnet/feature/193-add-support-for-updating-bookmark-block
Add support for updating bookmark block
2 parents 6aae5e2 + 06b2d87 commit 2ed2006

File tree

3 files changed

+123
-1
lines changed

3 files changed

+123
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System.Collections.Generic;
2+
using Newtonsoft.Json;
3+
4+
namespace Notion.Client
5+
{
6+
public class BookmarkUpdateBlock : IUpdateBlock
7+
{
8+
public bool Archived { get; set; }
9+
10+
[JsonProperty("bookmark")]
11+
public Data Bookmark { get; set; }
12+
13+
public class Data
14+
{
15+
[JsonProperty("url")]
16+
public string Url { get; set; }
17+
18+
[JsonProperty("caption")]
19+
public IEnumerable<RichTextBaseInput> Caption { get; set; }
20+
}
21+
}
22+
}

Src/Notion.Client/Models/Blocks/BookmarkBlock.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Newtonsoft.Json;
1+
using System.Collections.Generic;
2+
using Newtonsoft.Json;
23

34
namespace Notion.Client
45
{
@@ -13,6 +14,9 @@ public class Info
1314
{
1415
[JsonProperty("url")]
1516
public string Url { get; set; }
17+
18+
[JsonProperty("caption")]
19+
public IEnumerable<RichTextBase> Caption { get; set; }
1620
}
1721
}
1822
}

Test/Notion.IntegrationTests/IBlocksClientTests.cs

Lines changed: 96 additions & 0 deletions
74DB
Original file line numberDiff line numberDiff line change
@@ -146,5 +146,101 @@ public async Task DeleteAsync_DeleteBlockWithGivenId()
146146
Archived = true
147147
});
148148
}
149+
150+
[Theory]
151+
[MemberData(nameof(BlockData))]
152+
public async Task UpdateAsync_UpdatesGivenBlock(Block block, IUpdateBlock updateBlock, Action<Block> assert)
153+
{
154+
var options = new ClientOptions
155+
{
156+
AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN")
157+
};
158+
INotionClient _client = NotionClientFactory.Create(options);
159+
160+
var pageParentId = "3c357473a28149a488c010d2b245a589";
161+
162+
var page = await _client.Pages.CreateAsync(
163+
PagesCreateParametersBuilder.Create(
164+
new ParentPageInput
165+
{
166+
PageId = pageParentId
167+
}
168+
).Build()
169+
);
170+
171+
var blocks = await _client.Blocks.AppendChildrenAsync(
172+
page.Id,
173+
new BlocksAppendChildrenParameters
174+
{
175+
Children = new List<Block>()
176+
{
177+
block
178+
}
179+
}
180+
);
181+
182+
var blockId = blocks.Results.First().Id;
183+
await _client.Blocks.UpdateAsync(blockId, updateBlock);
184+
185+
blocks = await _client.Blocks.RetrieveChildrenAsync(page.Id);
186+
blocks.Results.Should().HaveCount(1);
187+
188+
var updatedBlock = blocks.Results.First();
189+
190+
assert.Invoke(updatedBlock);
191+
192+
// cleanup
193+
await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters
194+
{
195+
Archived = true
196+
});
197+
}
198+
199+
private static IEnumerable<object[]> BlockData()
200+
{
201+
return new List<object[]>
202+
{
203+
new object[] {
204+
new BookmarkBlock
205+
{
206+
Bookmark = new BookmarkBlock.Info
207+
{
208+
Url = "https://developers.notion.com/reference/rich-text",
209+
Caption = new List<RichTextBase>
210+
{
211+
new RichTextTextInput
212+
{
213+
Text = new Text
214+
{
215+
Content = "Notion API"
216+
}
217+
}
218+
}
219+
}
220+
},
221+
new BookmarkUpdateBlock {
222+
Bookmark = new BookmarkUpdateBlock.Data
223+
{
224+
Url = "https://github.com/notion-dotnet/notion-sdk-net",
225+
Caption = new List<RichTextBaseInput>
226+
{
227+
new RichTextTextInput
228+
{
229+
Text = new Text
230+
{
231+
Content = "Github"
232+
}
233+
}
234+
}
235+
}
236+
},
237+
new Action<Block>((block) => {
238+
var updatedBlock = (BookmarkBlock)block;
239+
Assert.Equal("https://github.com/notion-dotnet/notion-sdk-net", updatedBlock.Bookmark.Url);
240+
Assert.Equal("Github", updatedBlock.Bookmark.Caption.OfType<RichTextText>().First().Text.Content);
241+
})
242+
}
243+
};
244+
}
149245
}
150246
}

0 commit comments

Comments
 (0)
0