Skip to content

Commit d87d8a5

Browse files
Add integration tests for retrieve page property item ✅
1 parent 37de0a8 commit d87d8a5

File tree

1 file changed

+75
-26
lines changed

1 file changed

+75
-26
lines changed

Test/Notion.IntegrationTests/IPageClientTests.cs

Lines changed: 75 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,21 @@ namespace Notion.IntegrationTests
1010
{
1111
public class IPageClientTests
1212
{
13-
[Fact]
14-
public async Task CreateAsync_CreatesANewPage()
13+
private readonly INotionClient _client;
14+
15+
public IPageClientTests()
1516
{
1617
var options = new ClientOptions
1718
{
1819
AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN")
1920
};
2021

21-
IPagesClient _client = new PagesClient(new RestClient(options));
22+
_client = NotionClientFactory.Create(options);
23+
}
2224

25+
[Fact]
26+
public async Task CreateAsync_CreatesANewPage()
27+
{
2328
PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput
2429
{
2530
DatabaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb"
@@ -28,18 +33,18 @@ public async Task CreateAsync_CreatesANewPage()
2833
{
2934
Title = new List<RichTextBase>
3035
{
31-
new RichTextText
32-
{
33-
Text = new Text
34-
{
35-
Content = "Test Page Title"
36-
}
37-
}
36+
new RichTextText
37+
{
38+
Text = new Text
39+
{
40+
Content = "Test Page Title"
41+
}
42+
}
3843
}
3944
})
4045
.Build();
4146

42-
var page = await _client.CreateAsync(pagesCreateParameters);
47+
var page = await _client.Pages.CreateAsync(pagesCreateParameters);
4348

4449
page.Should().NotBeNull();
4550
page.Parent.Should().BeOfType<DatabaseParent>().Which
@@ -49,7 +54,7 @@ public async Task CreateAsync_CreatesANewPage()
4954
page.Properties["Name"].Should().BeOfType<TitlePropertyValue>().Which
5055
.Title.First().PlainText.Should().Be("Test Page Title");
5156

52-
await _client.UpdateAsync(page.Id, new PagesUpdateParameters
57+
await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters
5358
{
5459
Archived = true
5560
});
@@ -58,13 +63,6 @@ public async Task CreateAsync_CreatesANewPage()
5863
[Fact]
5964
public async Task Bug_unable_to_create_page_with_select_property()
6065
{
61-
var options = new ClientOptions
62-
{
63-
AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN")
64-
};
65-
66-
INotionClient _client = NotionClientFactory.Create(options);
67-
6866
PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput
6967
{
7068
DatabaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb"
@@ -73,13 +71,13 @@ public async Task Bug_unable_to_create_page_with_select_property()
7371
{
7472
Title = new List<RichTextBase>
7573
{
76-
new RichTextText
77-
{
78-
Text = new Text
79-
{
80-
Content = "Test Page Title"
81-
}
82-
}
74+
new RichTextText
75+
{
76+
Text = new Text
77+
{
78+
Content = "Test Page Title"
79+
}
80+
}
8381
}
8482
})
8583
.AddProperty("TestSelect", new SelectPropertyValue
@@ -106,5 +104,56 @@ public async Task Bug_unable_to_create_page_with_select_property()
106104
Archived = true
107105
});
108106
}
107+
108+
[Fact]
109+
public async Task Test_RetrievePagePropertyItemAsync()
110+
{
111+
PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput
112+
{
113+
DatabaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb"
114+
})
115+
.AddProperty("Name", new TitlePropertyValue
116+
{
117+
Title = new List<RichTextBase>
118+
{
119+
new RichTextText
120+
{
121+
Text = new Text
122+
{
123+
Content = "Test Page Title"
124+
}
125+
}
126+
}
127+
})
128+
.Build();
129+
130+
var page = await _client.Pages.CreateAsync(pagesCreateParameters);
131+
132+
var property = await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters
133+
{
134+
PageId = page.Id,
135+
PropertyId = "title"
136+
});
137+
138+
property.Should().NotBeNull();
139+
property.Should().BeOfType<ListPropertyItem>();
140+
141+
var listProperty = (ListPropertyItem)property;
142+
143+
listProperty.Type.Should().BeNull();
144+
listProperty.Results.Should().SatisfyRespectively(p =>
145+
{
146+
p.Should().BeOfType<TitlePropertyItem>();
147+
var titleProperty = (TitlePropertyItem)p;
148+
149+
titleProperty.Title.PlainText.Should().Be("Test Page Title");
150+
});
151+
152+
// cleanup
153+
await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters
154+
{
155+
Archived = true
156+
});
157+
}
109158
}
110159
}

0 commit comments

Comments
 (0)