@@ -75,5 +75,101 @@ public async Task UpdateBlobkAsync_UpdatesGivenBlock()
7575 var tasks = blocks . Results . Select ( x => _client . Blocks . DeleteAsync ( x . Id ) ) ;
7676 await Task . WhenAll ( tasks ) ;
7777 }
78+
79+ [ Theory ]
80+ [ MemberData ( nameof ( BlockData ) ) ]
81+ public async Task UpdateAsync_UpdatesGivenBlock ( Block block , IUpdateBlock updateBlock , Action < Block > assert )
82+ {
83+ var options = new ClientOptions
84+ {
85+ AuthToken = Environment . GetEnvironmentVariable ( "NOTION_AUTH_TOKEN" )
86+ } ;
87+ INotionClient _client = NotionClientFactory . Create ( options ) ;
88+
89+ var pageParentId = "3c357473a28149a488c010d2b245a589" ;
90+
91+ var page = await _client . Pages . CreateAsync (
92+ PagesCreateParametersBuilder . Create (
93+ new ParentPageInput
94+ {
95+ PageId = pageParentId
96+ }
97+ ) . Build ( )
98+ ) ;
99+
100+ var blocks = await _client . Blocks . AppendChildrenAsync (
101+ page . Id ,
102+ new BlocksAppendChildrenParameters
103+ {
104+ Children = new List < Block > ( )
105+ {
106+ block
107+ }
108+ }
109+ ) ;
110+
111+ var blockId = blocks . Results . First ( ) . Id ;
112+ await _client . Blocks . UpdateAsync ( blockId , updateBlock ) ;
113+
114+ blocks = await _client . Blocks . RetrieveChildrenAsync ( page . Id ) ;
115+ blocks . Results . Should ( ) . HaveCount ( 1 ) ;
116+
117+ var updatedBlock = blocks . Results . First ( ) ;
118+
119+ assert . Invoke ( updatedBlock ) ;
120+
121+ // cleanup
122+ await _client . Pages . UpdateAsync ( page . Id , new PagesUpdateParameters
123+ {
124+ Archived = true
125+ } ) ;
126+ }
127+
128+ private static IEnumerable < object [ ] > BlockData ( )
129+ {
130+ return new List < object [ ] >
131+ {
132+ new object [ ] {
133+ new BookmarkBlock
134+ {
135+ Bookmark = new BookmarkBlock . Info
136+ {
137+ Url = "https://developers.notion.com/reference/rich-text" ,
138+ Caption = new List < RichTextBase >
139+ {
140+ new RichTextTextInput
141+ {
142+ Text = new Text
143+ {
144+ Content = "Notion API"
145+ }
146+ }
147+ }
148+ }
149+ } ,
150+ new BookmarkUpdateBlock {
151+ Bookmark = new BookmarkUpdateBlock . Data
152+ {
153+ Url = "https://github.com/notion-dotnet/notion-sdk-net" ,
154+ Caption = new List < RichTextBaseInput >
155+ {
156+ new RichTextTextInput
157+ {
158+ Text = new Text
159+ {
160+ Content = "Github"
161+ }
162+ }
163+ }
164+ }
165+ } ,
166+ new Action < Block > ( ( block ) => {
167+ var updatedBlock = ( BookmarkBlock ) block ;
168+ Assert . Equal ( "https://github.com/notion-dotnet/notion-sdk-net" , updatedBlock . Bookmark . Url ) ;
169+ Assert . Equal ( "Github" , updatedBlock . Bookmark . Caption . OfType < RichTextText > ( ) . First ( ) . Text . Content ) ;
170+ } )
171+ }
172+ } ;
173+ }
78174 }
79175}
0 commit comments