10000 Formula property can now be created and updated in database by KoditkarVedant · Pull Request #119 · notion-dotnet/notion-sdk-net · GitHub
[go: up one dir, main page]

Skip to content

Formula property can now be created and updated in database #119

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
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
@@ -0,0 +1,7 @@
namespace Notion.Client
{
public class FormulaPropertySchema : IPropertySchema
{
public Formula Formula { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Notion.Client
{
public class FormulaUpdatePropertySchema : IUpdatePropertySchema
{
public Formula Formula { get; set; }
}
}
51 changes: 51 additions & 0 deletions Test/Notion.UnitTests/DatabasesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,5 +356,56 @@ public async Task UpdateDatabaseAsync()
var price = (NumberProperty)database.Properties["Price"];
price.Number.Format.Should().Be(NumberFormat.Yen);
}

[Fact]
public async Task FormulaPropertyCanBeSetWhenCreatingDatabase()
{
var pageId = "98ad959b-2b6a-4774-80ee-00246fb0ea9b";
var path = ApiEndpoints.DatabasesApiUrls.Create;
var jsonData = await File.ReadAllTextAsync("data/databases/FormulaPropertyCanBeSetWhenCreatingDatabaseResponse.json");

Server.Given(CreatePostRequestBuilder(path))
.RespondWith(
Response.Create()
.WithStatusCode(200)
.WithBody(jsonData)
);

var createDatabaseParameters = new DatabasesCreateParameters();

createDatabaseParameters.Parent = new ParentPageInput
{
PageId = pageId
};

createDatabaseParameters.Title = new List<RichTextBaseInput>
{
new RichTextTextInput
{
Text = new Text
{
Content = "Grocery List",
Link = null
}
}
};

createDatabaseParameters.Properties = new Dictionary<string, IPropertySchema>
{
{ "Cost of next trip", new FormulaPropertySchema { Formula = new Formula { Expression = "if(prop(\"In stock\"), 0, prop(\"Price\"))" } } },
{ "Price", new NumberPropertySchema { Number = new Number { Format = NumberFormat.Dollar } } }
};

var database = await _client.CreateAsync(createDatabaseParameters);

database.Parent.Type.Should().Be(ParentType.PageId);
database.Parent.Should().BeOfType<PageParent>();
((PageParent)database.Parent).PageId.Should().Be(pageId);

database.Properties.Should().HaveCount(2);

var formulaProperty = (FormulaProperty)database.Properties["Cost of next trip"];
formulaProperty.Formula.Expression.Should().Be("if(prop(\"In stock\"), 0, prop(\"Price\"))");
}
}
}
3 changes: 3 additions & 0 deletions Test/Notion.UnitTests/Notion.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@
<None Update="data\search\SearchResponse.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\databases\FormulaPropertyCanBeSetWhenCreatingDatabaseResponse.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"object": "database",
"id": "c23f0085-a061-41c0-b8a6-cbe14d15a4de",
"created_time": "2021-08-20T16:08:00.000Z",
"last_edited_time": "2021-08-20T16:08:00.000Z",
"title": [
{
"type": "text",
"text": {
"content": "Grocery List",
"link": null
},
"annotations": {
"bold": false,
"italic": false,
"strikethrough": false,
"underline": false,
"code": false,
"color": "default"
},
"plain_text": "Grocery List",
"href": null
}
],
"properties": {
"Cost of next trip": {
"id": "Rbq\\",
"name": "Cost of next trip",
"type": "formula",
"formula": {
"expression": "if(prop(\"In stock\"), 0, prop(\"Price\"))"
}
},
"Price": {
"id": "u|<{",
"name": "Price",
"type": "number",
"number": {
"format": "dollar"
}
}
},
"parent": {
"type": "page_id",
"page_id": "98ad959b-2b6a-4774-80ee-00246fb0ea9b"
}
}
0