Skip to content

Commit ff6f6bb

Browse files
add integration test for update page properties endpoint ✅
1 parent 4e41fd0 commit ff6f6bb

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

Test/Notion.UnitTests/ApiTestBase.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,14 @@ protected IRequestBuilder CreatePostRequestBuilder(string path)
5757
.WithHeader("Authorization", $"Bearer {ClientOptions.AuthToken}", MatchBehaviour.AcceptOnMatch)
5858
.WithHeader("Notion-Version", Constants.DEFAULT_NOTION_VERSION, MatchBehaviour.AcceptOnMatch);
5959
}
60+
61+
protected IRequestBuilder CreatePatchRequestBuilder(string path)
62+
{
63+
return Request.Create()
64+
.WithPath(path)
65+
.UsingPatch()
66+
.WithHeader("Authorization", $"Bearer {ClientOptions.AuthToken}", MatchBehaviour.AcceptOnMatch)
67+
.WithHeader("Notion-Version", Constants.DEFAULT_NOTION_VERSION, MatchBehaviour.AcceptOnMatch);
68+
}
6069
}
6170
}

Test/Notion.UnitTests/Notion.UnitTests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
<None Update="data\pages\PageObjectShouldHaveUrlPropertyResponse.json">
3434
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
3535
</None>
36+
<None Update="data\pages\UpdatePagePropertiesResponse.json">
37+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
38+
</None>
3639
</ItemGroup>
3740

3841
</Project>

Test/Notion.UnitTests/PagesClientTests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,34 @@ public async Task CreateAsync()
8282

8383
}
8484

85+
[Fact]
86+
public async Task UpdatePropertiesAsync()
87+
{
88+
var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c";
89+
var path = ApiEndpoints.PagesApiUrls.UpdateProperties(pageId);
90+
91+
var jsonData = await File.ReadAllTextAsync("data/pages/UpdatePagePropertiesResponse.json");
92+
93+
Server.Given(CreatePatchRequestBuilder(path))
94+
.RespondWith(
95+
Response.Create()
96+
.WithStatusCode(200)
97+
.WithBody(jsonData)
98+
);
99+
100+
var updatedProperties = new Dictionary<string, PropertyValue>()
101+
{
102+
{ "In stock", new CheckboxPropertyValue() { Checkbox = true } }
103+
};
104+
105+
var page = await _client.UpdatePropertiesAsync(pageId, updatedProperties);
106+
107+
page.Id.Should().Be(pageId);
108+
page.Properties.Should().HaveCount(2);
109+
var updatedProperty = page.Properties.First(x => x.Key == "In stock");
110+
((CheckboxPropertyValue)updatedProperty.Value).Checkbox.Should().BeTrue();
111+
}
112+
85113
[Fact]
86114
public async Task PageObjectShouldHaveUrlProperty()
87115
{
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
"In stock": {
10+
"id": "{>U;",
11+
"type": "checkbox",
12+
"checkbox": true
13+
},
14+
"Name": {
15+
"id": "title",
16+
"type": "title",
17+
"title": [
18+
{
19+
"type": "text",
20+
"text": {
21+
"content": "Test",
22+
"link": null
23+
},
24+
"annotations": {
25+
"bold": false,
26+
"italic": false,
27+
"strikethrough": false,
28+
"underline": false,
29+
"code": false,
30+
"color": "default"
31+
},
32+
"plain_text": "Test",
33+
"href": null
34+
}
35+
]
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)