diff --git a/Src/Notion.Client/Models/Page/IPageIcon.cs b/Src/Notion.Client/Models/Page/IPageIcon.cs index c85b3a4c..a89184fe 100644 --- a/Src/Notion.Client/Models/Page/IPageIcon.cs +++ b/Src/Notion.Client/Models/Page/IPageIcon.cs @@ -1,7 +1,12 @@ -using Newtonsoft.Json; +using JsonSubTypes; +using Newtonsoft.Json; namespace Notion.Client { + [JsonConverter(typeof(JsonSubtypes), "type")] + [JsonSubtypes.KnownSubType(typeof(EmojiObject), "emoji")] + [JsonSubtypes.KnownSubType(typeof(FileObject), "file")] + [JsonSubtypes.KnownSubType(typeof(FileObject), "external")] public interface IPageIcon { [JsonProperty("type")] diff --git a/Test/Notion.UnitTests/DatabasesClientTests.cs b/Test/Notion.UnitTests/DatabasesClientTests.cs index 37c02d30..d6a440a0 100644 --- a/Test/Notion.UnitTests/DatabasesClientTests.cs +++ b/Test/Notion.UnitTests/DatabasesClientTests.cs @@ -119,6 +119,9 @@ public async Task RetrieveDatabaseAsync() { property.Key.Should().Be(property.Value.Name); } + + HelperAsserts.IPageIconAsserts(database.Icon); + HelperAsserts.FileObjectAsserts(database.Cover); } [Fact] diff --git a/Test/Notion.UnitTests/HelperAsserts.cs b/Test/Notion.UnitTests/HelperAsserts.cs new file mode 100644 index 00000000..1b07fbf5 --- /dev/null +++ b/Test/Notion.UnitTests/HelperAsserts.cs @@ -0,0 +1,41 @@ +using FluentAssertions; +using Notion.Client; + +namespace Notion.UnitTests +{ + public static class HelperAsserts + { + public static void IPageIconAsserts(IPageIcon icon) + { + icon.Should().NotBeNull(); + + switch (icon) + { + case EmojiObject emoji: + emoji.Emoji.Should().NotBeNull(); + break; + case FileObject fileObject: + FileObjectAsserts(fileObject); + break; + } + } + + public static void FileObjectAsserts(FileObject fileObject) + { + fileObject.Should().NotBeNull(); + + switch (fileObject) + { + case UploadedFile uploadedFile: + uploadedFile.File.Should().NotBeNull(); + uploadedFile.File.Url.Should().NotBeNull(); + uploadedFile.File.ExpiryTime.Should().NotBeSameDateAs(default); + break; + case ExternalFile externalFile: + externalFile.External.Should().NotBeNull(); + externalFile.External.Url.Should().NotBeNull(); + break; + } + } + } +} diff --git a/Test/Notion.UnitTests/data/databases/DatabaseRetrieveResponse.json b/Test/Notion.UnitTests/data/databases/DatabaseRetrieveResponse.json index 5ed09bb1..ef374f2d 100644 --- a/Test/Notion.UnitTests/data/databases/DatabaseRetrieveResponse.json +++ b/Test/Notion.UnitTests/data/databases/DatabaseRetrieveResponse.json @@ -22,6 +22,17 @@ "href": null } ], + "icon": { + "type": "emoji", + "emoji": "🎉" + }, + "cover": { + "type": "external", + "external": { + "url": "https://website.domain/images/image.png" + } + }, + "url": "https://www.notion.so/668d797c76fa49349b05ad288df2d136", "properties": { "Tags": { "id": "YG~h",