Skip to content

Commit 7ec09bc

Browse files
Merge pull request #65 from notion-dotnet/feature/57-page-object-now-contain-url-property
Add URL property in Page object ✨
2 parents 310451e + bf3fcdf commit 7ec09bc

File tree

6 files changed

+140
-1
lines changed

6 files changed

+140
-1
lines changed

Src/Notion.Client/Constants.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
namespace Notion.Client
1+
using System.Runtime.CompilerServices;
2+
3+
[assembly: InternalsVisibleTo("Notion.UnitTests")]
4+
namespace Notion.Client
25
{
36
internal class Constants
47
{

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,7 @@ public class Page : IObject
2020
public bool IsArchived { get; set; }
2121

2222
public IDictionary<string, PropertyValue> Properties { get; set; }
23+
24+
public string Url { get; set; }
2325
}
2426
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using System.Linq;
3+
using Newtonsoft.Json;
4+
using Newtonsoft.Json.Serialization;
5+
using Notion.Client;
6+
using WireMock.Matchers;
7+
using WireMock.RequestBuilders;
8+
using WireMock.Server;
9+
10+
namespace Notion.UnitTests
11+
{
12+
public class ApiTestBase : IDisposable
13+
{
14+
protected readonly WireMockServer Server;
15+
16+
protected static readonly JsonSerializerSettings JsonSerializerSettings = new JsonSerializerSettings()
17+
{
18+
Formatting = Newtonsoft.Json.Formatting.Indented,
19+
ContractResolver = new DefaultContractResolver
20+
{
21+
NamingStrategy = new CamelCaseNamingStrategy()
22+
}
23+
};
24+
25+
protected readonly ClientOptions ClientOptions;
26+
27+
protected ApiTestBase()
28+
{
29+
Server = WireMockServer.Start();
30+
ClientOptions = new ClientOptions()
31+
{
32+
BaseUrl = Server.Urls.First(),
33+
AuthToken = "<Token>"
34+
};
35+
}
36+
37+
public void Dispose()
38+
{
39+
Server.Stop();
40+
Server.Dispose();
41+
}
42+
43+
protected IRequestBuilder CreateGetRequestBuilder(string path)
44+
{
45+
return Request.Create()
46+
.WithPath(path)
47+
.UsingGet()
48+
.WithHeader("Authorization", $"Bearer {ClientOptions.AuthToken}", MatchBehaviour.AcceptOnMatch)
49+
.WithHeader("Notion-Version", Constants.DEFAULT_NOTION_VERSION, MatchBehaviour.AcceptOnMatch);
50+
}
51+
}
52+
}

Test/Notion.UnitTests/Notion.UnitTests.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
<ItemGroup>
1010
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
11+
<PackageReference Include="Microsoft.VisualStudio.VsixColorCompiler" Version="16.0.0" />
12+
<PackageReference Include="WireMock.Net" Version="1.4.19" />
1113
<PackageReference Include="xunit" Version="2.4.1" />
1214
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
1315
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
@@ -23,4 +25,10 @@
2325
<ProjectReference Include="..\..\Src\Notion.Client\Notion.Client.csproj" />
2426
</ItemGroup>
2527

28+
<ItemGroup>
29+
<None Update="data\pages\PageObjectShouldHaveUrlPropertyResponse.json">
30+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
31+
</None>
32+
</ItemGroup>
33+
2634
</Project>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System.IO;
2+
using System.Threading.Tasks;
3+
using Notion.Client;
4+
using WireMock.ResponseBuilders;
5+
using Xunit;
6+
7+
namespace Notion.UnitTests
8+
{
9+
public class PagesClientTests : ApiTestBase
10+
{
11+
private readonly IPagesClient _client;
12+
13+
public PagesClientTests()
14+
{
15+
_client = new PagesClient(new RestClient(ClientOptions));
16+
}
17+
18+
[Fact]
19+
public async Task PageObjectShouldHaveUrlProperty()
20+
{
21+
var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c";
22+
var path = ApiEndpoints.PagesApiUrls.Retrieve(pageId);
23+
var jsonData = await File.ReadAllTextAsync("data/pages/PageObjectShouldHaveUrlPropertyResponse.json");
24+
25+
Server.Given(CreateGetRequestBuilder(path))
26+
.RespondWith(
27+
Response.Create()
28+
.WithStatusCode(200)
29+
.WithBody(jsonData)
30+
);
31+
32+
var page = await _client.RetrieveAsync(pageId);
33+
34+
Assert.Equal("https://www.notion.so/Avocado-251d2b5f268c4de2afe9c71ff92ca95c", page.Url);
35+
}
36+
}
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
"parent": {
7+
"type": "database_id",
8+
"database_id": "48f8fee9-cd79-4180-bc2f-ec0398253067"
9+
},
10+
"archived": false,
11+
"url": "https://www.notion.so/Avocado-251d2b5f268c4de2afe9c71ff92ca95c",
12+
"properties": {
13+
"Name": {
14+
"id": "title",
15+
"type": "title",
16+
"title": [
17+
{
18+
"type": "text",
19+
"text": {
20+
"content": "Avocado",
21+
"link": null
22+
},
23+
"annotations": {
24+
"bold": false,
25+
"italic": false,
26+
"strikethrough": false,
27+
"underline": false,
28+
"code": false,
29+
"color": "default"
30+
},
31+
"plain_text": "Avocado",
32+
"href": null
33+
}
34+
]
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)