Skip to content

Commit 2180e24

Browse files
Remove Legacy/Breaking Create pages API method ⚰️
* Update the breaking unit tests
1 parent 8b769ab commit 2180e24

File tree

5 files changed

+21
-88
lines changed

5 files changed

+21
-88
lines changed

Src/Notion.Client/Api/Pages/IPagesClient.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ namespace Notion.Client
55
{
66
public interface IPagesClient
77
{
8-
Task<Page> CreateAsync(NewPage page);
9-
108
/// <summary>
119
/// Creates a new page in the specified database or as a child of an existing page.
1210
///

Src/Notion.Client/Api/Pages/PagesClient.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,6 @@ public PagesClient(IRestClient client)
1414
_client = client;
1515
}
1616

17-
public async Task<Page> CreateAsync(NewPage page)
18-
{
19-
if (page == null)
20-
{
21-
throw new ArgumentNullException(nameof(page));
22-
}
23-
24-
if (page.Parent == null)
25-
{
26-
throw new ArgumentNullException(nameof(page.Parent), "Parent is required!");
27-
}
28-
29-
if (page.Properties == null)
30-
{
31-
throw new ArgumentNullException(nameof(page.Properties), "Properties are required!");
32-
}
33-
34-
return await _client.PostAsync<Page>(PagesApiUrls.Create(), page);
35-
}
36-
3717
/// <summary>
3818
/// Creates a new page in the specified database or as a child of an existing page.
3919
///

Src/Notion.Client/Models/Page/NewPage.cs

Lines changed: 0 additions & 46 deletions
This file was deleted.

Test/Notion.UnitTests/PagesClientTests.cs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,10 @@ public async Task CreateAsync()
5656
.WithBody(jsonData)
5757
);
5858

59-
var newPage = new NewPage(new PageParent
59+
var pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput
6060
{
61-
PageId = "3c357473-a281-49a4-88c0-10d2b245a589"
62-
});
63-
64-
newPage.AddProperty("Name", new TitlePropertyValue()
61+
DatabaseId = "3c357473-a281-49a4-88c0-10d2b245a589"
62+
}).AddProperty("Name", new TitlePropertyValue()
6563
{
6664
Title = new List<RichTextBase>()
6765
{
@@ -73,17 +71,17 @@ public async Task CreateAsync()
7371
}
7472
}
7573
}
76-
});
74+
}).Build();
7775

78-
var page = await _client.CreateAsync(newPage);
76+
var page = await _client.CreateAsync(pagesCreateParameters);
7977

8078
page.Id.Should().NotBeNullOrEmpty();
8179
page.Url.Should().NotBeNullOrEmpty();
8280
page.Properties.Should().HaveCount(1);
8381
page.Properties.First().Key.Should().Be("Name");
8482
page.IsArchived.Should().BeFalse();
8583
page.Parent.Should().NotBeNull();
86-
((PageParent)page.Parent).PageId.Should().Be("3c357473-a281-49a4-88c0-10d2b245a589");
84+
((DatabaseParent)page.Parent).DatabaseId.Should().Be("3c357473-a281-49a4-88c0-10d2b245a589");
8785
}
8886

8987
[Fact]
@@ -201,32 +199,35 @@ public async Task ArchivePageAsync()
201199
[Fact]
202200
public async Task CreateAsync_Throws_ArgumentNullException_When_Parameter_Is_Null()
203201
{
204-
Func<Task> act = async () => await _client.CreateAsync(page: null);
202+
Func<Task> act = async () => await _client.CreateAsync(null);
205203

206-
(await act.Should().ThrowAsync<ArgumentNullException>()).And.ParamName.Should().Be("page");
204+
(await act.Should().ThrowAsync<ArgumentNullException>()).And.ParamName.Should().Be("pagesCreateParameters");
207205
}
208206

209207
[Fact]
210208
public async Task CreateAsync_Throws_ArgumentNullException_When_Parent_Is_Missing()
211209
{
212-
var newPage = new NewPage(null);
210+
var pagesCreateParameters = PagesCreateParametersBuilder.Create(null).Build();
213211

214-
Func<Task> act = async () => await _client.CreateAsync(newPage);
212+
Func<Task> act = async () => await _client.CreateAsync(pagesCreateParameters);
215213

216214
(await act.Should().ThrowAsync<ArgumentNullException>()).And.ParamName.Should().Be("Parent");
217215
}
218216

219217
[Fact]
220218
public async Task CreateAsync_Throws_ArgumentNullException_When_Properties_Is_Missing()
221219
{
222-
var newPage = new NewPage(new PageParent()
220+
var pagesCreateParameters = new PagesCreateParameters
223221
{
224-
PageId = "3c357473-a281-49a4-88c0-10d2b245a589"
225-
});
222+
Parent = new ParentPageInput()
223+
{
224+
PageId = "3c357473-a281-49a4-88c0-10d2b245a589",
226225

227-
newPage.Properties = null;
226+
},
227+
Properties = null
228+
};
228229

229-
Func<Task> act = async () => await _client.CreateAsync(newPage);
230+
Func<Task> act = async () => await _client.CreateAsync(pagesCreateParameters);
230231

231232
(await act.Should().ThrowAsync<ArgumentNullException>()).And.ParamName.Should().Be("Properties");
232233
}

Test/Notion.UnitTests/data/pages/CreatePageResponse.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
}
3232
},
3333
"parent": {
34-
"page_id": "3c357473-a281-49a4-88c0-10d2b245a589",
35-
"type": "page_id"
34+
"database_id": "3c357473-a281-49a4-88c0-10d2b245a589",
35+
"type": "database_id"
3636
}
37-
}
37+
}

0 commit comments

Comments
 (0)