Skip to content

413 fix date mention creation and deserialization #434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public class MentionInput
public ObjectId Database { get; set; }

[JsonProperty("date")]
public DatePropertyValue Date { get; set; }
public Date Date { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class Mention
public ObjectId Database { get; set; }

[JsonProperty("date")]
public DatePropertyValue Date { get; set; }
public Date Date { get; set; }
}

public class ObjectId
Expand Down
47 changes: 46 additions & 1 deletion Test/Notion.IntegrationTests/DatabasesClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using FluentAssertions;
Expand Down Expand Up @@ -140,4 +141,48 @@ private async Task<Database> CreateDatabaseWithAPageAsync(string databaseName)

return createdDatabase;
}

[Fact]
public async Task Verify_mention_date_property_parsed_properly()
{
// Arrange
var createDbRequest = new DatabasesCreateParameters
{
Title = new List<RichTextBaseInput>
{
new RichTextTextInput
{
Text = new Text
{
Content = "Test DB",
Link = null
}
},
new RichTextMentionInput
{
Mention = new MentionInput
{
Date = new Date
{
Start = DateTime.UtcNow,
End = DateTime.UtcNow.AddDays(1)
}
}
}
},
Properties = new Dictionary<string, IPropertySchema>
{
{ "Name", new TitlePropertySchema { Title = new Dictionary<string, object>() } },
},
Parent = new ParentPageInput { PageId = _page.Id }
};

// Act
var createdDatabase = await Client.Databases.CreateAsync(createDbRequest);

// Assert
var mention = createdDatabase.Title.OfType<RichTextMention>().First().Mention;
mention.Date.Start.Should().NotBeNull();
mention.Date.End.Should().NotBeNull();
}
}
20 changes: 6 additions & 14 deletions Test/Notion.IntegrationTests/PageClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -400,23 +400,16 @@ public async Task Verify_date_property_is_parsed_correctly_in_mention_object()
{
Mention = new Mention()
{
Page = new ObjectId()
Date = new Date()
{
Id = _page.Id,
},
Date = new DatePropertyValue()
{
Date = new Date()
{
Start = DateTime.UtcNow
}
Start = DateTime.UtcNow
}
}
}
}
})
.Build();

var page = await Client.Pages.CreateAsync(pageRequest);

page.Should().NotBeNull();
Expand All @@ -434,9 +427,8 @@ public async Task Verify_date_property_is_parsed_correctly_in_mention_object()
PropertyId = pageProperty.Id
});

titleProperty.Results.First()
.As<TitlePropertyItem>()
.Title.As<RichTextMention>()
.Mention.Date.Date.Should().NotBeNull();
var mention = titleProperty.Results.First().As<TitlePropertyItem>().Title.As<RichTextMention>().Mention;
mention.Date.Start.Should().NotBeNull();
mention.Date.End.Should().BeNull();
}
}
Loading