Skip to content

Commit

Permalink
Merge pull request #162 from notion-dotnet/bfix/161-fix-IPageIcon-par…
Browse files Browse the repository at this point in the history
…sing

Fix IPageIcon parsing 🐛
  • Loading branch information
KoditkarVedant authored Oct 3, 2021
2 parents e51fce1 + 65674aa commit 052c527
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Src/Notion.Client/Models/Page/IPageIcon.cs
Original file line number Diff line number Diff line change
@@ -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")]
Expand Down
3 changes: 3 additions & 0 deletions Test/Notion.UnitTests/DatabasesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ public async Task RetrieveDatabaseAsync()
{
property.Key.Should().Be(property.Value.Name);
}

HelperAsserts.IPageIconAsserts(database.Icon);
HelperAsserts.FileObjectAsserts(database.Cover);
}

[Fact]
Expand Down
41 changes: 41 additions & 0 deletions Test/Notion.UnitTests/HelperAsserts.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
}
11 changes: 11 additions & 0 deletions Test/Notion.UnitTests/data/databases/DatabaseRetrieveResponse.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 052c527

Please sign in to comment.