Skip to content

Commit 0c6c67a

Browse files
Merge pull request #434 from notion-dotnet/413-fix-date-mention-creation-and-deserialization
413 fix date mention creation and deserialization
2 parents 78cec41 + 3ea8bc4 commit 0c6c67a

File tree

4 files changed

+54
-17
lines changed

4 files changed

+54
-17
lines changed

Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/MentionInput.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ public class MentionInput
1717
public ObjectId Database { get; set; }
1818

1919
[JsonProperty("date")]
20-
public DatePropertyValue Date { get; set; }
20+
public Date Date { get; set; }
2121
}
2222
}

Src/Notion.Client/Models/Database/RichText/RichTextMention.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class Mention
2525
public ObjectId Database { get; set; }
2626

2727
[JsonProperty("date")]
28-
public DatePropertyValue Date { get; set; }
28+
public Date Date { get; set; }
2929
}
3030

3131
public class ObjectId

Test/Notion.IntegrationTests/DatabasesClientTests.cs

+46-1
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.Linq;
34
using System.Threading.Tasks;
45
using FluentAssertions;
@@ -140,4 +141,48 @@ private async Task<Database> CreateDatabaseWithAPageAsync(string databaseName)
140141

141142
return createdDatabase;
142143
}
144+
145+
[Fact]
146+
public async Task Verify_mention_date_property_parsed_properly()
147+
{
148+
// Arrange
149+
var createDbRequest = new DatabasesCreateParameters
150+
{
151+
Title = new List<RichTextBaseInput>
152+
{
153+
new RichTextTextInput
154+
{
155+
Text = new Text
156+
{
157+
Content = "Test DB",
158+
Link = null
159+
}
160+
},
161+
new RichTextMentionInput
162+
{
163+
Mention = new MentionInput
164+
{
165+
Date = new Date
166+
{
167+
Start = DateTime.UtcNow,
168+
End = DateTime.UtcNow.AddDays(1)
169+
}
170+
}
171+
}
172+
},
173+
Properties = new Dictionary<string, IPropertySchema>
174+
{
175+
{ "Name", new TitlePropertySchema { Title = new Dictionary<string, object>() } },
176+
},
177+
Parent = new ParentPageInput { PageId = _page.Id }
178+
};
179+
180+
// Act
181+
var createdDatabase = await Client.Databases.CreateAsync(createDbRequest);
182+
183+
// Assert
184+
var mention = createdDatabase.Title.OfType<RichTextMention>().First().Mention;
185+
mention.Date.Start.Should().NotBeNull();
186+
mention.Date.End.Should().NotBeNull();
187+
}
143188
}

Test/Notion.IntegrationTests/PageClientTests.cs

+6-14
Original file line numberDiff line numberDiff line change
@@ -400,23 +400,16 @@ public async Task Verify_date_property_is_parsed_correctly_in_mention_object()
400400
{
401401
Mention = new Mention()
402402
{
403-
Page = new ObjectId()
403+
Date = new Date()
404404
{
405-
Id = _page.Id,
406-
},
407-
Date = new DatePropertyValue()
408-
{
409-
Date = new Date()
410-
{
411-
Start = DateTime.UtcNow
412-
}
405+
Start = DateTime.UtcNow
413406
}
414407
}
415408
}
416409
}
417410
})
418411
.Build();
419-
412+
420413
var page = await Client.Pages.CreateAsync(pageRequest);
421414

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

437-
titleProperty.Results.First()
438-
.As<TitlePropertyItem>()
439-
.Title.As<RichTextMention>()
440-
.Mention.Date.Date.Should().NotBeNull();
430+
var mention = titleProperty.Results.First().As<TitlePropertyItem>().Title.As<RichTextMention>().Mention;
431+
mention.Date.Start.Should().NotBeNull();
432+
mention.Date.End.Should().BeNull();
441433
}
442434
}

0 commit comments

Comments
 (0)