From 09ff9194a934ed2b24ffed7cbaac130cad9fae5d Mon Sep 17 00:00:00 2001 From: Gehongyan Date: Wed, 8 Nov 2023 18:00:03 +0800 Subject: [PATCH 1/2] Fix broken database relation request parameters. --- .../PropertySchema/RelationPropertySchema.cs | 17 ++--------------- .../RelationUpdatePropertySchema.cs | 17 ++--------------- 2 files changed, 4 insertions(+), 30 deletions(-) diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/RelationPropertySchema.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/RelationPropertySchema.cs index fa6a3249..4c278ac2 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/RelationPropertySchema.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/RelationPropertySchema.cs @@ -1,23 +1,10 @@ -using System; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Notion.Client { public class RelationPropertySchema : IPropertySchema { [JsonProperty("relation")] - public RelationInfo Relation { get; set; } - - public class RelationInfo - { - [JsonProperty("database_id")] - public Guid DatabaseId { get; set; } - - [JsonProperty("synced_property_id")] - public string SyncedPropertyId { get; set; } - - [JsonProperty("synced_property_name")] - public string SyncedPropertyName { get; set; } - } + public RelationData Relation { get; set; } } } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/RelationUpdatePropertySchema.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/RelationUpdatePropertySchema.cs index 4f6a74a3..25f65cd4 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/RelationUpdatePropertySchema.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/RelationUpdatePropertySchema.cs @@ -1,23 +1,10 @@ -using System; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Notion.Client { public class RelationUpdatePropertySchema : UpdatePropertySchema { [JsonProperty("relation")] - public RelationInfo Relation { get; set; } - - public class RelationInfo - { - [JsonProperty("database_id")] - public Guid DatabaseId { get; set; } - - [JsonProperty("synced_property_id")] - public string SyncedPropertyId { get; set; } - - [JsonProperty("synced_property_name")] - public string SyncedPropertyName { get; set; } - } + public RelationData Relation { get; set; } } } From 34ecf9d7f706a53f453be34ddb9ccfb44b4a3b7f Mon Sep 17 00:00:00 2001 From: Gehongyan Date: Sat, 22 Feb 2025 11:22:16 +0800 Subject: [PATCH 2/2] Add UpdateDatabaseRelationProperties Test --- .../DatabasesClientTests.cs | 63 ++++++++++++++++++- 1 file changed, 60 insertions(+), 3 deletions(-) diff --git a/Test/Notion.IntegrationTests/DatabasesClientTests.cs b/Test/Notion.IntegrationTests/DatabasesClientTests.cs index 31b611f1..d5278519 100644 --- a/Test/Notion.IntegrationTests/DatabasesClientTests.cs +++ b/Test/Notion.IntegrationTests/DatabasesClientTests.cs @@ -29,7 +29,7 @@ public async Task DisposeAsync() public async Task QueryDatabase() { // Arrange - var createdDatabase = await CreateDatabaseWithAPageAsync(); + var createdDatabase = await CreateDatabaseWithAPageAsync("Test List"); // Act var response = await Client.Databases.QueryAsync(createdDatabase.Id, new DatabasesQueryParameters()); @@ -43,7 +43,64 @@ public async Task QueryDatabase() .Text.Content.Should().Be("Test Title"); } - private async Task CreateDatabaseWithAPageAsync() + [Fact] + public async Task UpdateDatabaseRelationProperties() + { + // Arrange + var createdSourceDatabase = await CreateDatabaseWithAPageAsync("Test Relation Source"); + var createdDestinationDatabase = await CreateDatabaseWithAPageAsync("Test Relation Destination"); + + // Act + var response = await Client.Databases.UpdateAsync(createdDestinationDatabase.Id, + new DatabasesUpdateParameters + { + Properties = new Dictionary + { + { + "Single Relation", + new RelationUpdatePropertySchema + { + Relation = new SinglePropertyRelation + { + DatabaseId = createdSourceDatabase.Id, + SingleProperty = new Dictionary() + } + } + }, + { + "Dual Relation", + new RelationUpdatePropertySchema + { + Relation = new DualPropertyRelation + { + DatabaseId = createdSourceDatabase.Id, + DualProperty = new DualPropertyRelation.Data() + } + } + } + } + }); + + // Assert + response.Properties.Should().NotBeNull(); + + response.Properties.Should().ContainKey("Single Relation"); + var singleRelation = response.Properties["Single Relation"].As().Relation; + singleRelation.Should().BeEquivalentTo( + new SinglePropertyRelation + { + DatabaseId = createdSourceDatabase.Id, + SingleProperty = new Dictionary() + }); + + response.Properties.Should().ContainKey("Dual Relation"); + var dualRelation = response.Properties["Dual Relation"].As().Relation; + dualRelation.DatabaseId.Should().Be(createdSourceDatabase.Id); + dualRelation.Type.Should().Be(RelationType.Dual); + dualRelation.Should().BeOfType(); + } + + private async Task CreateDatabaseWithAPageAsync(string databaseName) { var createDbRequest = new DatabasesCreateParameters { @@ -53,7 +110,7 @@ private async Task CreateDatabaseWithAPageAsync() { Text = new Text { - Content = "Test List", + Content = databaseName, Link = null } }