Skip to content

Commit b3cc030

Browse files
Fix date formula value is always null 🐛
1 parent 067a89a commit b3cc030

File tree

5 files changed

+199
-5
lines changed

5 files changed

+199
-5
lines changed
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace Notion.Client
1+
using System;
2+
3+
namespace Notion.Client
24
{
35
public class DatePropertyValue : PropertyValue
46
{
@@ -8,7 +10,7 @@ public class DatePropertyValue : PropertyValue
810

911
public class Date
1012
{
11-
public string Start { get; set; }
12-
public string End { get; set; }
13+
public DateTime? Start { get; set; }
14+
public DateTime? End { get; set; }
1315
}
1416
}

Src/Notion.Client/Models/PropertyValue/FormulaPropertyValue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ public class FormulaValue
1313
public string String { get; set; }
1414
public double? Number { get; set; }
1515
public bool? Boolean { get; set; }
16-
public DatePropertyValue Date { get; set; }
16+
public Date Date { get; set; }
1717
}
1818
}

Test/Notion.UnitTests/DatabasesClientTests.cs

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.IO;
34
using System.Threading.Tasks;
45
using FluentAssertions;
@@ -407,5 +408,59 @@ public async Task FormulaPropertyCanBeSetWhenCreatingDatabase()
407408
var formulaProperty = (FormulaProperty)database.Properties["Cost of next trip"];
408409
formulaProperty.Formula.Expression.Should().Be("if(prop(\"In stock\"), 0, prop(\"Price\"))");
409410
}
411+
412+
[Fact]
413+
public async Task Fix123_QueryAsync_DateFormulaValue_Returns_Null()
414+
{
415+
var databaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb";
416+
var path = ApiEndpoints.DatabasesApiUrls.Query(databaseId);
417+
var jsonData = await File.ReadAllTextAsync("data/databases/Fix123QueryAsyncDateFormulaValueReturnsNullResponse.json");
418+
419+
Server.Given(CreatePostRequestBuilder(path))
420+
.RespondWith(
421+
Response.Create()
422+
.WithStatusCode(200)
423+
.WithBody(jsonData)
424+
);
425+
426+
var databasesQueryParams = new DatabasesQueryParameters
427+
{
428+
Filter = new CompoundFilter
429+
{
430+
Or = new List<Filter> {
431+
new CheckboxFilter(
432+
"In stock",
433+
true
434+
),
435+
new NumberFilter(
436+
"Cost of next trip",
437+
greaterThanOrEqualTo: 2
438+
)
439+
},
440+
},
441+
Sorts = new List<Sort>
442+
{
443+
new Sort
444+
{
445+
Property = "Last ordered",
446+
Direction = Direction.Ascending
447+
}
448+
}
449+
};
450+
451+
var pagesPaginatedList = await _client.QueryAsync(databaseId, databasesQueryParams);
452+
453+
pagesPaginatedList.Results.Should().ContainSingle();
454+
455+
foreach (var page in pagesPaginatedList.Results)
456+
{
457+
page.Parent.Should().BeAssignableTo<IPageParent>();
458+
page.Object.Should().Be(ObjectType.Page);
459+
460+
var formulaPropertyValue = (FormulaPropertyValue)page.Properties["FormulaProp"];
461+
formulaPropertyValue.Formula.Date.Start.Should().Be(DateTime.Parse("2021-06-28"));
462+
formulaPropertyValue.Formula.Date.End.Should().BeNull();
463+
}
464+
}
410465
}
411466
}

Test/Notion.UnitTests/Notion.UnitTests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
<None Update="data\databases\DatabasePropertyObjectContainParentProperty.json">
4646
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
4747
</None>
48+
<None Update="data\databases\Fix123QueryAsyncDateFormulaValueReturnsNullResponse.json">
49+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
50+
</None>
4851
<None Update="data\databases\UpdateDatabaseResponse.json">
4952
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
5053
</None>
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
{
2+
"object": "list",
3+
"results": [
4+
{
5+
"object": "page",
6+
"id": "50b4321c-afc1-4468-b278-5a578643989c",
7+
"created_time": "2021-05-22T18:30:00.000Z",
8+
"last_edited_time": "2021-09-09T05:49:00.000Z",
9+
"cover": null,
10+
"icon": null,
11+
"parent": {
12+
"type": "database_id",
13+
"database_id": "f86f2262-0751-40f2-8f63-e3f7a3c39fcb"
14+
},
15+
"archived": false,
16+
"properties": {
17+
"Column": {
18+
"id": "B[\\E",
19+
"type": "rollup",
20+
"rollup": {
21+
"type": "array",
22+
"array": []
23+
}
24+
},
25+
"Property": {
26+
"id": "Cf<z",
27+
"type": "rich_text",
28+
"rich_text": []
29+
},
30+
"DateProp": {
31+
"id": "E:|Y",
32+
"type": "date",
33+
"date": {
34+
"start": "2021-05-24",
35+
"end": "2021-05-27"
36+
}
37+
},
38+
"FormulaProp": {
39+
"id": "JwY^",
40+
"type": "formula",
41+
"formula": {
42+
"type": "date",
43+
"date": {
44+
"start": "2021-06-28",
45+
"end": null
46+
}
47+
}
48+
},
49+
"Rock": {
50+
"id": "QhVM",
51+
"type": "rich_text",
52+
"rich_text": [
53+
{
54+
"type": "text",
55+
"text": {
56+
"content": "Rolling Stone",
57+
"link": null
58+
},
59+
"annotations": {
60+
"bold": false,
61+
"italic": false,
62+
"strikethrough": false,
63+
"underline": false,
64+
"code": false,
65+
"color": "default"
66+
},
67+
"plain_text": "Rolling Stone",
68+
"href": null
69+
}
70+
]
71+
},
72+
"Related to sample table (Property)": {
73+
"id": "VQ}{",
74+
"type": "relation",
75+
"relation": [
76+
{
77+
"id": "e4f62d6f-b5b9-4c41-b073-b5fe833b6249"
78+
}
79+
]
80+
},
81+
"Column 1": {
82+
"id": "Vure",
83+
"type": "people",
84+
"people": [
85+
{
86+
"object": "user",
87+
"id": "5e37c1b4-630f-4e81-bd6b-296af31e345f",
88+
"name": "Vedant Koditkar",
89+
"avatar_url": "https://lh3.googleusercontent.com/a-/AOh14Gg4lnfwJviST_tKZZpMfKrgmjp8wRzPBg9ec6sG7w=s100",
90+
"type": "person",
91+
"person": {
92+
"email": "vedkoditkar@gmail.com"
93+
}
94+
},
95+
{
96+
"object": "user",
97+
"id": "590693f3-797f-4970-98ff-7284106393e5",
98+
"name": "Test",
99+
"avatar_url": null,
100+
"type": "bot",
101+
"bot": {}
102+
}
103+
]
104+
},
105+
"Name": {
106+
"id": "title",
107+
"type": "title",
108+
"title": [
109+
{
110+
"type": "text",
111+
"text": {
112+
"content": "Nice",
113+
"link": null
114+
},
115+
"annotations": {
116+
"bold": false,
117+
"italic": false,
118+
"strikethrough": false,
119+
"underline": false,
120+
"code": false,
121+
"color": "default"
122+
},
123+
"plain_text": "Nice",
124+
"href": null
125+
}
126+
]
127+
}
128+
},
129+
"url": "https://www.notion.so/Nice-50b4321cafc14468b2785a578643989c"
130+
}
131+
],
132+
"next_cursor": null,
133+
"has_more": false
134+
}

0 commit comments

Comments
 (0)