diff --git a/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs index cc0818ae..aeb3cd8e 100644 --- a/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs @@ -13,7 +13,7 @@ public class DatePropertyValue : PropertyValue /// /// Date /// - [JsonProperty("date")] + [JsonProperty("date", NullValueHandling = NullValueHandling.Include)] public Date Date { get; set; } } diff --git a/Test/Notion.IntegrationTests/IPageClientTests.cs b/Test/Notion.IntegrationTests/IPageClientTests.cs index ae1e317b..a2c73162 100644 --- a/Test/Notion.IntegrationTests/IPageClientTests.cs +++ b/Test/Notion.IntegrationTests/IPageClientTests.cs @@ -11,6 +11,7 @@ namespace Notion.IntegrationTests public class IPageClientTests { private readonly INotionClient _client; + private readonly string _databaseId; public IPageClientTests() { @@ -20,6 +21,7 @@ public IPageClientTests() }; _client = NotionClientFactory.Create(options); + _databaseId = Environment.GetEnvironmentVariable("DATABASE_ID") ?? "f86f2262-0751-40f2-8f63-e3f7a3c39fcb"; } [Fact] @@ -27,7 +29,7 @@ public async Task CreateAsync_CreatesANewPage() { PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput { - DatabaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb" + DatabaseId = _databaseId }) .AddProperty("Name", new TitlePropertyValue { @@ -48,7 +50,7 @@ public async Task CreateAsync_CreatesANewPage() page.Should().NotBeNull(); page.Parent.Should().BeOfType().Which - .DatabaseId.Should().Be("f86f2262-0751-40f2-8f63-e3f7a3c39fcb"); + .DatabaseId.Should().Be(_databaseId); page.Properties.Should().ContainKey("Name"); page.Properties["Name"].Should().BeOfType().Which @@ -65,7 +67,7 @@ public async Task Bug_unable_to_create_page_with_select_property() { PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput { - DatabaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb" + DatabaseId = _databaseId }) .AddProperty("Name", new TitlePropertyValue { @@ -93,7 +95,7 @@ public async Task Bug_unable_to_create_page_with_select_property() page.Should().NotBeNull(); page.Parent.Should().BeOfType().Which - .DatabaseId.Should().Be("f86f2262-0751-40f2-8f63-e3f7a3c39fcb"); + .DatabaseId.Should().Be(_databaseId); page.Properties.Should().ContainKey("Name"); page.Properties["Name"].Should().BeOfType().Which @@ -110,7 +112,7 @@ public async Task Test_RetrievePagePropertyItemAsync() { PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput { - DatabaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb" + DatabaseId = _databaseId }) .AddProperty("Name", new TitlePropertyValue { @@ -155,5 +157,70 @@ public async Task Test_RetrievePagePropertyItemAsync() Archived = true }); } + + [Fact] + public async Task Test_UpdatePageProperty_with_date_as_null() + { + // setup - add property to db and create a page with the property having a date + + string datePropertyName = "Test Date Property"; + var updateDatabaseParameters = new DatabasesUpdateParameters(); + updateDatabaseParameters.Properties = new Dictionary + { + { "Name", new TitleUpdatePropertySchema { Title = new Dictionary() } }, + { "Test Date Property", new DateUpdatePropertySchema{ Date = new Dictionary() } } + }; + + PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput + { + DatabaseId = _databaseId + }) + .AddProperty("Name", new TitlePropertyValue + { + Title = new List + { + new RichTextText + { + Text = new Text + { + Content = "Test Page Title" + } + } + } + }) + .AddProperty(datePropertyName, new DatePropertyValue + { + Date = new Date() + { + Start = Convert.ToDateTime("2020-12-08T12:00:00Z"), + End = Convert.ToDateTime("2025-12-08T12:00:00Z") + } + }) + .Build(); + + var updatedDb = await _client.Databases.UpdateAsync(_databaseId, updateDatabaseParameters); + + var page = await _client.Pages.CreateAsync(pagesCreateParameters); + + var setDate = page.Properties[datePropertyName] as DatePropertyValue; + + setDate?.Date?.Start.Should().Be(Convert.ToDateTime("2020-12-08T12:00:00Z")); + + // verify + IDictionary testProps = new Dictionary(); + testProps.Add(datePropertyName, new DatePropertyValue() { Date = null }); + + var updatedPage = await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters + { + Properties = testProps + }); + + var verifyDate = updatedPage.Properties[datePropertyName] as DatePropertyValue; + + verifyDate?.Date.Should().BeNull(); + + //cleanup + await _client.Blocks.DeleteAsync(page.Id); + } } }