Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 052c527

Browse files
Merge pull request #162 from notion-dotnet/bfix/161-fix-IPageIcon-parsing
Fix IPageIcon parsing 🐛
2 parents e51fce1 + 65674aa commit 052c527

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
using Newtonsoft.Json;
1+
using JsonSubTypes;
2+
using Newtonsoft.Json;
23

34
namespace Notion.Client
45
{
6+
[JsonConverter(typeof(JsonSubtypes), "type")]
7+
[JsonSubtypes.KnownSubType(typeof(EmojiObject), "emoji")]
8+
[JsonSubtypes.KnownSubType(typeof(FileObject), "file")]
9+
[JsonSubtypes.KnownSubType(typeof(FileObject), "external")]
510
public interface IPageIcon
611
{
712
[JsonProperty("type")]

‎Test/Notion.UnitTests/DatabasesClientTests.cs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ public async Task RetrieveDatabaseAsync()
119119
{
120120
property.Key.Should().Be(property.Value.Name);
121121
}
122+
123+
HelperAsserts.IPageIconAsserts(database.Icon);
124+
HelperAsserts.FileObjectAsserts(database.Cover);
122125
}
123126

124127
[Fact]
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using FluentAssertions;
2+
using Notion.Client;
3+
4+
namespace Notion.UnitTests
5+
{
6+
public static class HelperAsserts
7+
{
8+
public static void IPageIconAsserts(IPageIcon icon)
9+
{
10+
icon.Should().NotBeNull();
11+
12+
switch (icon)
13+
{
14+
case EmojiObject emoji:
15+
emoji.Emoji.Should().NotBeNull();
16+
break;
17+
case FileObject fileObject:
18+
FileObjectAsserts(fileObject);
19+
break;
20+
}
21+
}
22+
23+
public static void FileObjectAsserts(FileObject fileObject)
24+
{
25+
fileObject.Should().NotBeNull();
26+
27+
switch (fileObject)
28+
{
29+
case UploadedFile uploadedFile:
30+
uploadedFile.File.Should().NotBeNull();
31+
uploadedFile.File.Url.Should().NotBeNull();
32+
uploadedFile.File.ExpiryTime.Should().NotBeSameDateAs(default);
33+
break;
34+
case ExternalFile externalFile:
35+
externalFile.External.Should().NotBeNull();
36+
externalFile.External.Url.Should().NotBeNull();
37+
break;
38+
}
39+
}
40+
}
41+
}

‎Test/Notion.UnitTests/data/databases/DatabaseRetrieveResponse.json‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@
2222
"href": null
2323
}
2424
],
25+
"icon": {
26+
"type": "emoji",
27+
"emoji": "🎉"
28+
},
29+
"cover": {
30+
"type": "external",
31+
"external": {
32+
"url": "https://website.domain/images/image.png"
33+
}
34+
},
35+
"url": "https://www.notion.so/668d797c76fa49349b05ad288df2d136",
2536
"properties": {
2637
"Tags": {
2738
"id": "YG~h",

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /