Skip to content

Fix broken database relation request parameters. #404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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; }
}
}
Original file line number Diff line number Diff line change
@@ -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; }
}
}
63 changes: 60 additions & 3 deletions Test/Notion.IntegrationTests/DatabasesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -43,7 +43,64 @@ public async Task QueryDatabase()
.Text.Content.Should().Be("Test Title");
}

private async Task<Database> 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<string, IUpdatePropertySchema>
{
{
"Single Relation",
new RelationUpdatePropertySchema
{
Relation = new SinglePropertyRelation
{
DatabaseId = createdSourceDatabase.Id,
SingleProperty = new Dictionary<string, object>()
}
}
},
{
"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<RelationProperty>().Relation;
singleRelation.Should().BeEquivalentTo(
new SinglePropertyRelation
{
DatabaseId = createdSourceDatabase.Id,
SingleProperty = new Dictionary<string, object>()
});

response.Properties.Should().ContainKey("Dual Relation");
var dualRelation = response.Properties["Dual Relation"].As<RelationProperty>().Relation;
dualRelation.DatabaseId.Should().Be(createdSourceDatabase.Id);
dualRelation.Type.Should().Be(RelationType.Dual);
dualRelation.Should().BeOfType<DualPropertyRelation>();
}

private async Task<Database> CreateDatabaseWithAPageAsync(string databaseName)
{
var createDbRequest = new DatabasesCreateParameters
{
Expand All @@ -53,7 +110,7 @@ private async Task<Database> CreateDatabaseWithAPageAsync()
{
Text = new Text
{
Content = "Test List",
Content = databaseName,
Link = null
}
}
Expand Down