Skip to content

Commit

Permalink
Merge pull request #126 from notion-dotnet/bfix/123-date-formula-valu…
Browse files Browse the repository at this point in the history
…e-is-always-null

Fix date formula value is always null 🐛
  • Loading branch information
KoditkarVedant authored Sep 17, 2021
2 parents 067a89a + b3cc030 commit 572197e
Show file tree
Hide file tree
Showing 5 changed files with 199 additions and 5 deletions.
8 changes: 5 additions & 3 deletions Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Notion.Client
using System;

namespace Notion.Client
{
public class DatePropertyValue : PropertyValue
{
Expand All @@ -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; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
57 changes: 56 additions & 1 deletion Test/Notion.UnitTests/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.IO;
using System.Threading.Tasks;
using FluentAssertions;
Expand Down Expand Up @@ -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<Filter> {
new CheckboxFilter(
"In stock",
true
),
new NumberFilter(
"Cost of next trip",
greaterThanOrEqualTo: 2
)
},
},
Sorts = new List<Sort>
{
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<IPageParent>();
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();
}
}
}
}
3 changes: 3 additions & 0 deletions Test/Notion.UnitTests/Notion.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
<None Update="data\databases\DatabasePropertyObjectContainParentProperty.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\databases\Fix123QueryAsyncDateFormulaValueReturnsNullResponse.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\databases\UpdateDatabaseResponse.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
@@ -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<z",
"type": "rich_text",
"rich_text": []
},
"DateProp": {
"id": "E:|Y",
"type": "date",
"date": {
"start": "2021-05-24",
"end": "2021-05-27"
}
},
"FormulaProp": {
"id": "JwY^",
"type": "formula",
"formula": {
"type": "date",
"date": {
"start": "2021-06-28",
"end": null
}
}
},
"Rock": {
"id": "QhVM",
"type": "rich_text",
"rich_text": [
{
"type": "text",
"text": {
"content": "Rolling Stone",
"link": null
},
"annotations": {
"bold": false,
"italic": false,
"strikethrough": false,
"underline": false,
"code": false,
"color": "default"
},
"plain_text": "Rolling Stone",
"href": null
}
]
},
"Related to sample table (Property)": {
"id": "VQ}{",
"type": "relation",
"relation": [
{
"id": "e4f62d6f-b5b9-4c41-b073-b5fe833b6249"
}
]
},
"Column 1": {
"id": "Vure",
"type": "people",
"people": [
{
"object": "user",
"id": "5e37c1b4-630f-4e81-bd6b-296af31e345f",
"name": "Vedant Koditkar",
"avatar_url": "https://lh3.googleusercontent.com/a-/AOh14Gg4lnfwJviST_tKZZpMfKrgmjp8wRzPBg9ec6sG7w=s100",
"type": "person",
"person": {
"email": "[email protected]"
}
},
{
"object": "user",
"id": "590693f3-797f-4970-98ff-7284106393e5",
"name": "Test",
"avatar_url": null,
"type": "bot",
"bot": {}
}
]
},
"Name": {
"id": "title",
"type": "title",
"title": [
{
"type": "text",
"text": {
"content": "Nice",
"link": null
},
"annotations": {
"bold": false,
"italic": false,
"strikethrough": false,
"underline": false,
"code": false,
"color": "default"
},
"plain_text": "Nice",
"href": null
}
]
}
},
"url": "https://www.notion.so/Nice-50b4321cafc14468b2785a578643989c"
}
],
"next_cursor": null,
"has_more": false
}

0 comments on commit 572197e

Please sign in to comment.