8000 Merge pull request #296 from notion-dotnet/258-update-page-object-onl… · notion-dotnet/notion-sdk-net@8f2eb91 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8f2eb91

Browse files
Merge pull request #296 from notion-dotnet/258-update-page-object-only-has-property-id
Update page properties to only return property id
2 parents 3e54645 + 42368c5 commit 8f2eb91

File tree

6 files changed

+78
-9
lines changed

6 files changed

+78
-9
lines changed

Src/Notion.Client/Models/Page/Page.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class Page : IObject, IObjectModificationData
4444
/// Property values of this page.
4545
/// </summary>
4646
[JsonProperty("properties")]
47-
public IDictionary<string, PropertyValue> Properties { get; set; }
47+
public IDictionary<string, PagePropertyOnId> Properties { get; set; }
4848

4949
/// <summary>
5050
/// The URL of the Notion page.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Notion.Client
4+
{
5+
public class PagePropertyOnId
6+
{
7+
[JsonProperty("id")]
8+
public string Id { get; set; }
9+
}
10+
}

Test/Notion.IntegrationTests/IPageClientTests.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,11 @@ public async Task Test_UpdatePageProperty_with_date_as_null()
202202

203203
var page = await _client.Pages.CreateAsync(pagesCreateParameters);
204204

205-
var setDate = page.Properties[datePropertyName] as DatePropertyValue;
205+
var setDate = (DatePropertyValue)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters
206+
{
207+
PageId = page.Id,
208+
PropertyId = page.Properties[datePropertyName].Id
209+
});
206210

207211
setDate?.Date?.Start.Should().Be(Convert.ToDateTime("2020-12-08T12:00:00Z"));
208212

@@ -215,7 +219,11 @@ public async Task Test_UpdatePageProperty_with_date_as_null()
215219
Properties = testProps
216220
});
217221

218-
var verifyDate = updatedPage.Properties[datePropertyName] as DatePropertyValue;
222+
var verifyDate = (DatePropertyValue)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters
223+
{
224+
PageId = page.Id,
225+
PropertyId = updatedPage.Properties[datePropertyName].Id
226+
});
219227

220228
verifyDate?.Date.Should().BeNull();
221229

Test/Notion.UnitTests/DatabasesClientTests.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ namespace Notion.UnitTests
1212
public class DatabasesClientTests : ApiTestBase
1313
{
1414
private readonly IDatabasesClient _client;
15-
15+
private readonly IPagesClient _pagesClient;
1616
public DatabasesClientTests()
1717
{
1818
_client = new DatabasesClient(new RestClient(ClientOptions));
19+
_pagesClient = new PagesClient(new RestClient(ClientOptions));
1920
}
2021

2122
[Fact]
@@ -463,7 +464,20 @@ public async Task Fix123_QueryAsync_DateFormulaValue_Returns_Null()
463464
page.Parent.Should().BeAssignableTo<IPageParent>();
464465
page.Object.Should().Be(ObjectType.Page);
465466

466-
var formulaPropertyValue = (FormulaPropertyValue)page.Properties["FormulaProp"];
467+
Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(page.Id, page.Properties["FormulaProp"].Id)))
468+
.RespondWith(
469+
Response.Create()
470+
.WithStatusCode(200)
471+
.WithBody("{\"object\":\"property_item\",\"id\":\"JwY^\",\"type\":\"formula\",\"formula\":{\"type\":\"date\",\"date\":{\"start\":\"2021-06-28\",\"end\":null}}}")
472+
);
473+
474+
var formulaPropertyValue = (FormulaPropertyItem)await _pagesClient.RetrievePagePropertyItem(new RetrievePropertyItemParameters
475+
{
476+
PageId = page.Id,
477+
PropertyId = page.Properties["FormulaProp"].Id
478+
});
479+
480+
//var formulaPropertyValue = (FormulaPropertyValue)page.Properties["FormulaProp"];
467481
formulaPropertyValue.Formula.Date.Start.Should().Be(DateTime.Parse("2021-06-28"));
468482
formulaPropertyValue.Formula.Date.End.Should().BeNull();
469483
}

Test/Notion.UnitTests/PagesClientTests.cs

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public async Task CreateAsync()
8888
public async Task UpdatePropertiesAsync()
8989
{
9090
var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c";
91+
var propertyId = "{>U;";
9192
var path = ApiEndpoints.PagesApiUrls.UpdateProperties(pageId);
9293

9394
var jsonData = await File.ReadAllTextAsync("data/pages/UpdatePagePropertiesResponse.json");
@@ -99,6 +100,10 @@ public async Task UpdatePropertiesAsync()
99100
.WithBody(jsonData)
100101
);
101102

103+
Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(pageId, propertyId)))
104+
.RespondWith(
105+
Response.Create().WithStatusCode(200).WithBody("{\"object\":\"property_item\",\"id\":\"{>U;\",\"type\":\"checkbox\",\"checkbox\":true}"));
106+
102107
var updatedProperties = new Dictionary<string, PropertyValue>()
103108
{
104109
{ "In stock", new CheckboxPropertyValue() { Checkbox = true } }
@@ -109,7 +114,14 @@ public async Task UpdatePropertiesAsync()
109114
page.Id.Should().Be(pageId);
110115
page.Properties.Should().HaveCount(2);
111116
var updatedProperty = page.Properties.First(x => x.Key == "In stock");
112-
((CheckboxPropertyValue)updatedProperty.Value).Checkbox.Should().BeTrue();
117+
118+
var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem(new RetrievePropertyItemParameters
119+
{
120+
PageId = page.Id,
121+
PropertyId = updatedProperty.Value.Id
122+
});
123+
124+
checkboxPropertyValue.Checkbox.Should().BeTrue();
113125
}
114126

115127
[Fact]
@@ -135,6 +147,7 @@ public async Task PageObjectShouldHaveUrlProperty()
135147
public async Task UpdatePageAsync()
136148
{
137149
var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c";
150+
var propertyId = "{>U;";
138151
var path = ApiEndpoints.PagesApiUrls.UpdateProperties(pageId);
139152

140153
var jsonData = await File.ReadAllTextAsync("data/pages/UpdatePagePropertiesResponse.json");
@@ -146,6 +159,10 @@ public async Task UpdatePageAsync()
146159
.WithBody(jsonData)
147160
);
148161

162+
Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(pageId, propertyId)))
163+
.RespondWith(
164+
Response.Create().WithStatusCode(200).WithBody("{\"object\":\"property_item\",\"id\":\"{>U;\",\"type\":\"checkbox\",\"checkbox\":true}"));
165+
149166
var pagesUpdateParameters = new PagesUpdateParameters
150167
{
151168
Properties = new Dictionary<string, PropertyValue>()
@@ -160,13 +177,22 @@ public async Task UpdatePageAsync()
160177
page.IsArchived.Should().BeFalse();
161178
page.Properties.Should().HaveCount(2);
162179
var updatedProperty = page.Properties.First(x => x.Key == "In stock");
163-
((CheckboxPropertyValue)updatedProperty.Value).Checkbox.Should().BeTrue();
180+
181+
var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem(new RetrievePropertyItemParameters
182+
{
183+
PageId = page.Id,
184+
PropertyId = updatedProperty.Value.Id
185+
});
186+
187+
checkboxPropertyValue.Checkbox.Should().BeTrue();
164188
}
165189

166190
[Fact]
167191
public async Task ArchivePageAsync()
168192
{
169193
var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c";
194+
var propertyId = "{>U;";
195+
170196
var path = ApiEndpoints.PagesApiUrls.UpdateProperties(pageId);
171197

172198
var jsonData = await File.ReadAllTextAsync("data/pages/ArchivePageResponse.json");
@@ -178,6 +204,10 @@ public async Task ArchivePageAsync()
178204
.WithBody(jsonData)
179205
);
180206

207+
Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(pageId, propertyId)))
208+
.RespondWith(
209+
Response.Create().WithStatusCode(200).WithBody("{\"object\":\"property_item\",\"id\":\"{>U;\",\"type\":\"checkbox\",\"checkbox\":true}"));
210+
181211
var pagesUpdateParameters = new PagesUpdateParameters
182212
{
183213
Archived = true,
@@ -193,7 +223,14 @@ public async Task ArchivePageAsync()
193223
page.IsArchived.Should().BeTrue();
194224
page.Properties.Should().HaveCount(2);
195225
var updatedProperty = page.Properties.First(x => x.Key == "In stock");
196-
((CheckboxPropertyValue)updatedProperty.Value).Checkbox.Should().BeTrue();
226+
227+
var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem(new RetrievePropertyItemParameters
228+
{
229+
PageId = page.Id,
230+
PropertyId = updatedProperty.Value.Id
231+
});
232+
233+
checkboxPropertyValue.Checkbox.Should().BeTrue();
197234
}
198235

199236
[Fact]

Test/Notion.UnitTests/data/databases/Fix123QueryAsyncDateFormulaValueReturnsNullResponse.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
}
3737
},
3838
"FormulaProp": {
39-
"id": "JwY^",
39+
"id": "JwY",
4040
"type": "formula",
4141
"formula": {
4242
"type": "date",

0 commit comments

Comments
 (0)
0