From b3cc03070484d7485e35befcabdd5d5aac73f490 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Fri, 17 Sep 2021 20:45:48 +0530 Subject: [PATCH] =?UTF-8?q?Fix=20date=20formula=20value=20is=20always=20nu?= =?UTF-8?q?ll=20=F0=9F=90=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Models/PropertyValue/DatePropertyValue.cs | 8 +- .../PropertyValue/FormulaPropertyValue.cs | 2 +- Test/Notion.UnitTests/DatabasesClientTests.cs | 57 +++++++- Test/Notion.UnitTests/Notion.UnitTests.csproj | 3 + ...ncDateFormulaValueReturnsNullResponse.json | 134 ++++++++++++++++++ 5 files changed, 199 insertions(+), 5 deletions(-) create mode 100644 Test/Notion.UnitTests/data/databases/Fix123QueryAsyncDateFormulaValueReturnsNullResponse.json diff --git a/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs index bac23af8..0fc98859 100644 --- a/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs @@ -1,4 +1,6 @@ -namespace Notion.Client +using System; + +namespace Notion.Client { public class DatePropertyValue : PropertyValue { @@ -8,7 +10,7 @@ public class DatePropertyValue : PropertyValue public class Date { - public string Start { get; set; } - public string End { get; set; } + public DateTime? Start { get; set; } + public DateTime? End { get; set; } } } diff --git a/Src/Notion.Client/Models/PropertyValue/FormulaPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/FormulaPropertyValue.cs index 89fd5a0a..49ce4c53 100644 --- a/Src/Notion.Client/Models/PropertyValue/FormulaPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/FormulaPropertyValue.cs @@ -13,6 +13,6 @@ public class FormulaValue public string String { get; set; } public double? Number { get; set; } public bool? Boolean { get; set; } - public DatePropertyValue Date { get; set; } + public Date Date { get; set; } } } diff --git a/Test/Notion.UnitTests/DatabasesClientTests.cs b/Test/Notion.UnitTests/DatabasesClientTests.cs index 10740a29..d6b66316 100644 --- a/Test/Notion.UnitTests/DatabasesClientTests.cs +++ b/Test/Notion.UnitTests/DatabasesClientTests.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.IO; using System.Threading.Tasks; using FluentAssertions; @@ -407,5 +408,59 @@ public async Task FormulaPropertyCanBeSetWhenCreatingDatabase() var formulaProperty = (FormulaProperty)database.Properties["Cost of next trip"]; formulaProperty.Formula.Expression.Should().Be("if(prop(\"In stock\"), 0, prop(\"Price\"))"); } + + [Fact] + public async Task Fix123_QueryAsync_DateFormulaValue_Returns_Null() + { + var databaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb"; + var path = ApiEndpoints.DatabasesApiUrls.Query(databaseId); + var jsonData = await File.ReadAllTextAsync("data/databases/Fix123QueryAsyncDateFormulaValueReturnsNullResponse.json"); + + Server.Given(CreatePostRequestBuilder(path)) + .RespondWith( + Response.Create() + .WithStatusCode(200) + .WithBody(jsonData) + ); + + var databasesQueryParams = new DatabasesQueryParameters + { + Filter = new CompoundFilter + { + Or = new List { + new CheckboxFilter( + "In stock", + true + ), + new NumberFilter( + "Cost of next trip", + greaterThanOrEqualTo: 2 + ) + }, + }, + Sorts = new List + { + new Sort + { + Property = "Last ordered", + Direction = Direction.Ascending + } + } + }; + + var pagesPaginatedList = await _client.QueryAsync(databaseId, databasesQueryParams); + + pagesPaginatedList.Results.Should().ContainSingle(); + + foreach (var page in pagesPaginatedList.Results) + { + page.Parent.Should().BeAssignableTo(); + page.Object.Should().Be(ObjectType.Page); + + var formulaPropertyValue = (FormulaPropertyValue)page.Properties["FormulaProp"]; + formulaPropertyValue.Formula.Date.Start.Should().Be(DateTime.Parse("2021-06-28")); + formulaPropertyValue.Formula.Date.End.Should().BeNull(); + } + } } } diff --git a/Test/Notion.UnitTests/Notion.UnitTests.csproj b/Test/Notion.UnitTests/Notion.UnitTests.csproj index 2cf488b2..8382e6bc 100644 --- a/Test/Notion.UnitTests/Notion.UnitTests.csproj +++ b/Test/Notion.UnitTests/Notion.UnitTests.csproj @@ -45,6 +45,9 @@ Always + + Always + Always diff --git a/Test/Notion.UnitTests/data/databases/Fix123QueryAsyncDateFormulaValueReturnsNullResponse.json b/Test/Notion.UnitTests/data/databases/Fix123QueryAsyncDateFormulaValueReturnsNullResponse.json new file mode 100644 index 00000000..bf54bf0b --- /dev/null +++ b/Test/Notion.UnitTests/data/databases/Fix123QueryAsyncDateFormulaValueReturnsNullResponse.json @@ -0,0 +1,134 @@ +{ + "object": "list", + "results": [ + { + "object": "page", + "id": "50b4321c-afc1-4468-b278-5a578643989c", + "created_time": "2021-05-22T18:30:00.000Z", + "last_edited_time": "2021-09-09T05:49:00.000Z", + "cover": null, + "icon": null, + "parent": { + "type": "database_id", + "database_id": "f86f2262-0751-40f2-8f63-e3f7a3c39fcb" + }, + "archived": false, + "properties": { + "Column": { + "id": "B[\\E", + "type": "rollup", + "rollup": { + "type": "array", + "array": [] + } + }, + "Property": { + "id": "Cf