Skip to content

Commit b931a36

Browse files
Add Integration tests for comments API
1 parent 4bb2731 commit b931a36

File tree

1 file changed

+134
-0
lines changed

1 file changed

+134
-0
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Notion.Client;
6+
using Xunit;
7+
8+
namespace Notion.IntegrationTests
9+
{
10+
public class CommentsClientTests : IDisposable
11+
{
12+
private readonly INotionClient _client;
13+
private readonly string _pageParentId;
14+
private readonly Page _page;
15+
16+
public CommentsClientTests()
17+
{
18+
var options = new ClientOptions
19+
{
20+
AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN")
21+
};
22+
23+
_client = NotionClientFactory.Create(options);
24+
_pageParentId = Environment.GetEnvironmentVariable("NOTION_PAGE_PARENT_ID") ?? throw new ArgumentNullException("Page parent id is required.");
25+
26+
_page = _client.Pages.CreateAsync(
27+
PagesCreateParametersBuilder.Create(
28+
new ParentPageInput()
29+
{
30+
PageId = _pageParentId
31+
}
32+
).Build()
33+
).Result;
34+
}
35+
36+
[Fact]
37+
public async Task ShouldCreatePageComment()
38+
{
39+
// Arrange
40+
var parameters = CreateCommentParameters.CreatePageComment(
41+
new ParentPageInput
42+
{
43+
PageId = _page.Id
44+
},
45+
new List<RichTextBaseInput> {
46+
new RichTextTextInput
47+
{
48+
Text = new Text
49+
{
50+
Content = "This is a comment"
51+
}
52+
}
53+
}
54+
);
55+
56+
// Act
57+
var response = await _client.Comments.Create(parameters);
58+
59+
// Arrange
60+
61+
Assert.NotNull(response.Parent);
62+
Assert.NotNull(response.Id);
63+
Assert.NotNull(response.DiscussionId);
64+
65+
Assert.NotNull(response.RichText);
66+
Assert.Single(response.RichText);
67+
var richText = Assert.IsType<RichTextText>(response.RichText.First());
68+
Assert.Equal("This is a comment", richText.Text.Content);
69+
70+
var pageParent = Assert.IsType<PageParent>(response.Parent);
71+
Assert.Equal(_page.Id, pageParent.PageId);
72+
}
73+
74+
[Fact]
75+
public async Task ShouldCreateADiscussionComment()
76+
{
77+
// Arrange
78+
var comment = await _client.Comments.Create(
79+
CreateCommentParameters.CreatePageComment(
80+
new ParentPageInput
81+
{
82+
PageId = _page.Id
83+
},
84+
new List<RichTextBaseInput> {
85+
new RichTextTextInput
86+
{
87+
Text = new Text
88+
{
89+
Content = "This is a comment"
90+
}
91+
}
92+
}
93+
)
94+
);
95+
96+
// Act
97+
var response = await _client.Comments.Create(
98+
CreateCommentParameters.CreateDiscussionComment(
99+
comment.DiscussionId,
100+
new List<RichTextBaseInput> {
101+
new RichTextTextInput
102+
{
103+
Text = new Text
104+
{
105+
Content = "This is a sub comment"
106+
}
107+
}
108+
}
109+
)
110+
);
111+
112+
// Arrange
113+
Assert.Null(response.Parent);
114+
Assert.NotNull(response.Id);
115+
Assert.Equal(comment.DiscussionId, response.DiscussionId);
116+
117+
Assert.NotNull(response.RichText);
118+
Assert.Single(response.RichText);
119+
var richText = Assert.IsType<RichTextText>(response.RichText.First());
120+
Assert.Equal("This is a sub comment", richText.Text.Content);
121+
122+
var pageParent = Assert.IsType<PageParent>(response.Parent);
123+
Assert.Equal(_page.Id, pageParent.PageId);
124+
}
125+
126+
public void Dispose()
127+
{
128+
_client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters
129+
{
130+
Archived = true,
131+
}).Wait();
132+
}
133+
}
134+
}

0 commit comments

Comments
 (0)