Skip to content

Commit 6615bf7

Browse files
Merge pull request #404 from gehongyan/main
Fix broken database relation request parameters.
2 parents 2293f45 + b72aca9 commit 6615bf7

File tree

3 files changed

+64
-33
lines changed

3 files changed

+64
-33
lines changed
Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,10 @@
1-
using System;
2-
using Newtonsoft.Json;
1+
using Newtonsoft.Json;
32

43
namespace Notion.Client
54
{
65
public class RelationPropertySchema : IPropertySchema
76
{
87
[JsonProperty("relation")]
9-
public RelationInfo Relation { get; set; }
10-
11-
public class RelationInfo
12-
{
13-
[JsonProperty("database_id")]
14-
public Guid DatabaseId { get; set; }
15-
16-
[JsonProperty("synced_property_id")]
17-
public string SyncedPropertyId { get; set; }
18-
19-
[JsonProperty("synced_property_name")]
20-
public string SyncedPropertyName { get; set; }
21-
}
8+
public RelationData Relation { get; set; }
229
}
2310
}
Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,10 @@
1-
using System;
2-
using Newtonsoft.Json;
1+
using Newtonsoft.Json;
32

43
namespace Notion.Client
54
{
65
public class RelationUpdatePropertySchema : UpdatePropertySchema
76
{
87
[JsonProperty("relation")]
9-
public RelationInfo Relation { get; set; }
10-
11-
public class RelationInfo
12-
{
13-
[JsonProperty("database_id")]
14-
public Guid DatabaseId { get; set; }
15-
16-
[JsonProperty("synced_property_id")]
17-
public string SyncedPropertyId { get; set; }
18-
19-
[JsonProperty("synced_property_name")]
20-
public string SyncedPropertyName { get; set; }
21-
}
8+
public RelationData Relation { get; set; }
229
}
2310
}

Test/Notion.IntegrationTests/DatabasesClientTests.cs

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public async Task DisposeAsync()
2929
public async Task QueryDatabase()
3030
{
3131
// Arrange
32-
var createdDatabase = await CreateDatabaseWithAPageAsync();
32+
var createdDatabase = await CreateDatabaseWithAPageAsync("Test List");
3333

3434
// Act
3535
var response = await Client.Databases.QueryAsync(createdDatabase.Id, new DatabasesQueryParameters());
@@ -43,7 +43,64 @@ public async Task QueryDatabase()
4343
.Text.Content.Should().Be("Test Title");
4444
}
4545

46-
private async Task<Database> CreateDatabaseWithAPageAsync()
46+
[Fact]
47+
public async Task UpdateDatabaseRelationProperties()
48+
{
49+
// Arrange
50+
var createdSourceDatabase = await CreateDatabaseWithAPageAsync("Test Relation Source");
51+
var createdDestinationDatabase = await CreateDatabaseWithAPageAsync("Test Relation Destination");
52+
53+
// Act
54+
var response = await Client.Databases.UpdateAsync(createdDestinationDatabase.Id,
55+
new DatabasesUpdateParameters
56+
{
57+
Properties = new Dictionary<string, IUpdatePropertySchema>
58+
{
59+
{
60+
"Single Relation",
61+
new RelationUpdatePropertySchema
62+
{
63+
Relation = new SinglePropertyRelation
64+
{
65+
DatabaseId = createdSourceDatabase.Id,
66+
SingleProperty = new Dictionary<string, object>()
67+
}
68+
}
69+
},
70+
{
71+
"Dual Relation",
72+
new RelationUpdatePropertySchema
73+
{
74+
Relation = new DualPropertyRelation
75+
{
76+
DatabaseId = createdSourceDatabase.Id,
77+
DualProperty = new DualPropertyRelation.Data()
78+
}
79+
}
80+
}
81+
}
82+
});
83+
84+
// Assert
85+
response.Properties.Should().NotBeNull();
86+
87+
response.Properties.Should().ContainKey("Single Relation");
88+
var singleRelation = response.Properties["Single Relation"].As<RelationProperty>().Relation;
89+
singleRelation.Should().BeEquivalentTo(
90+
new SinglePropertyRelation
91+
{
92+
DatabaseId = createdSourceDatabase.Id,
93+
SingleProperty = new Dictionary<string, object>()
94+
});
95+
96+
response.Properties.Should().ContainKey("Dual Relation");
97+
var dualRelation = response.Properties["Dual Relation"].As<RelationProperty>().Relation;
98+
dualRelation.DatabaseId.Should().Be(createdSourceDatabase.Id);
99+
dualRelation.Type.Should().Be(RelationType.Dual);
100+
dualRelation.Should().BeOfType<DualPropertyRelation>();
101+
}
102+
103+
private async Task<Database> CreateDatabaseWithAPageAsync(string databaseName)
47104
{
48105
var createDbRequest = new DatabasesCreateParameters
49106
{
@@ -53,7 +110,7 @@ private async Task<Database> CreateDatabaseWithAPageAsync()
53110
{
54111
Text = new Text
55112
{
56-
Content = "Test List",
113+
Content = databaseName,
57114
Link = null
58115
}
59116
}

0 commit comments

Comments
 (0)