Skip to content

Commit 4e41fd0

Browse files
add integration test for create page endpoint ✅
1 parent ac09562 commit 4e41fd0

File tree

4 files changed

+88
-1
lines changed

4 files changed

+88
-1
lines changed

Test/Notion.UnitTests/ApiTestBase.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,14 @@ protected IRequestBuilder CreateGetRequestBuilder(string path)
4848
.WithHeader("Authorization", $"Bearer {ClientOptions.AuthToken}", MatchBehaviour.AcceptOnMatch)
4949
.WithHeader("Notion-Version", Constants.DEFAULT_NOTION_VERSION, MatchBehaviour.AcceptOnMatch);
5050
}
51+
52+
protected IRequestBuilder CreatePostRequestBuilder(string path)
53+
{
54+
return Request.Create()
55+
.WithPath(path)
56+
.UsingPost()
57+
.WithHeader("Authorization", $"Bearer {ClientOptions.AuthToken}", MatchBehaviour.AcceptOnMatch)
58+
.WithHeader("Notion-Version", Constants.DEFAULT_NOTION_VERSION, MatchBehaviour.AcceptOnMatch);
59+
}
5160
}
5261
}

Test/Notion.UnitTests/Notion.UnitTests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
</ItemGroup>
2828

2929
<ItemGroup>
30+
<None Update="data\pages\CreatePageResponse.json">
31+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
32+
</None>
3033
<None Update="data\pages\PageObjectShouldHaveUrlPropertyResponse.json">
3134
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
3235
</None>

Test/Notion.UnitTests/PagesClientTests.cs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using System.IO;
1+
using System.Collections.Generic;
2+
using System.IO;
3+
using System.Linq;
24
using System.Threading.Tasks;
35
using FluentAssertions;
46
using Notion.Client;
@@ -40,6 +42,46 @@ public async Task RetrieveAsync()
4042

4143
}
4244

45+
[Fact]
46+
public async Task CreateAsync()
47+
{
48+
var path = ApiEndpoints.PagesApiUrls.Create();
49+
50+
var jsonData = await File.ReadAllTextAsync("data/pages/CreatePageResponse.json");
51+
52+
53+
Server.Given(CreatePostRequestBuilder(path))
54+
.RespondWith(
55+
Response.Create()
56+
.WithStatusCode(200)
57+
.WithBody(jsonData)
58+
);
59+
60+
var newPage = new NewPage();
61+
newPage.AddProperty("Name", new TitlePropertyValue()
62+
{
63+
Title = new List<RichTextBase>()
64+
{
65+
new RichTextText()
66+
{
67+
Text = new Text
68+
{
69+
Content = "Test"
70+
}
71+
}
72+
}
73+
});
74+
75+
var page = await _client.CreateAsync(newPage);
76+
77+
page.Id.Should().NotBeNullOrEmpty();
78+
page.Url.Should().NotBeNullOrEmpty();
79+
page.Properties.Should().HaveCount(1);
80+
page.Properties.First().Key.Should().Be("Name");
81+
page.IsArchived.Should().BeFalse();
82+
83+
}
84+
4385
[Fact]
4486
public async Task PageObjectShouldHaveUrlProperty()
4587
{
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"object": "page",
3+
"id": "251d2b5f-268c-4de2-afe9-c71ff92ca95c",
4+
"created_time": "2020-03-17T19:10:04.968Z",
5+
"last_edited_time": "2020-03-17T21:49:37.913Z",
6+
"archived": false,
7+
"url": "https://www.notion.so/Test-251d2b5f268c4de2afe9c71ff92ca95c",
8+
"properties": {
9+
"Name": {
10+
"id": "title",
11+
"type": "title",
12+
"title": [
13+
{
14+
"type": "text",
15+
"text": {
16+
"content": "Test",
17+
"link": null
18+
},
19+
"annotations": {
20+
"bold": false,
21+
"italic": false,
22+
"strikethrough": false,
23+
"underline": false,
24+
"code": false,
25+
"color": "default"
26+
},
27+
"plain_text": "Test",
28+
"href": null
29+
}
30+
]
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)