Skip to content

Commit

Permalink
Merge branch 'main' into notion-version-2022-02-22
Browse files Browse the repository at this point in the history
  • Loading branch information
KoditkarVedant committed Jul 16, 2022
2 parents 331819d + 07d09c4 commit f309683
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public class Info

[JsonProperty("language")]
public string Language { get; set; }

[JsonProperty("caption")]
public IEnumerable<RichTextBaseInput> Caption { get; set; }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Notion.Client
{
public class TableRowUpdateBlock : UpdateBlock, IUpdateBlock
{
[JsonProperty("table_row")]
public Info TableRow { get; set; }

public class Info
{
[JsonProperty("cells")]
public IEnumerable<IEnumerable<RichTextTextInput>> Cells { get; set; }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Newtonsoft.Json;

namespace Notion.Client
{
public class TableUpdateBlock : UpdateBlock, IUpdateBlock
{
[JsonProperty("table")]
public Info Table { get; set; }

public class Info
{
[JsonProperty("has_column_header")]
public bool HasColumnHeader { get; set; }

[JsonProperty("has_row_header")]
public bool HasRowHeader { get; set; }
}
}
}
6 changes: 6 additions & 0 deletions Src/Notion.Client/Models/Blocks/BlockType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ public enum BlockType
[EnumMember(Value = "synced_block")]
SyncedBlock,

[EnumMember(Value = "table")]
Table,

[EnumMember(Value = "table_row")]
TableRow,

[EnumMember(Value = "unsupported")]
Unsupported
}
Expand Down
3 changes: 3 additions & 0 deletions Src/Notion.Client/Models/Blocks/CodeBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public class Info

[JsonProperty("language")]
public string Language { get; set; }

[JsonProperty("caption")]
public IEnumerable<RichTextBase> Caption { get; set; }
}
}
}
2 changes: 2 additions & 0 deletions Src/Notion.Client/Models/Blocks/IBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ namespace Notion.Client
[JsonSubtypes.KnownSubType(typeof(ParagraphBlock), BlockType.Paragraph)]
[JsonSubtypes.KnownSubType(typeof(PDFBlock), BlockType.PDF)]
[JsonSubtypes.KnownSubType(typeof(QuoteBlock), BlockType.Quote)]
[JsonSubtypes.KnownSubType(typeof(TableBlock), BlockType.Table)]
[JsonSubtypes.KnownSubType(typeof(TableRowBlock), BlockType.TableRow)]
[JsonSubtypes.KnownSubType(typeof(TableOfContentsBlock), BlockType.TableOfContents)]
[JsonSubtypes.KnownSubType(typeof(TemplateBlock), BlockType.Template)]
[JsonSubtypes.KnownSubType(typeof(ToDoBlock), BlockType.ToDo)]
Expand Down
27 changes: 27 additions & 0 deletions Src/Notion.Client/Models/Blocks/TableBlock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Newtonsoft.Json;

namespace Notion.Client
{
public class TableBlock : Block, IColumnChildrenBlock, INonColumnBlock
{
public override BlockType Type => BlockType.Table;

[JsonProperty("table")]
public TableInfo Table { get; set; }

public class TableInfo
{
[JsonProperty("table_width")]
public int TableWidth { get; set; }

[JsonProperty("has_column_header")]
public bool HasColumnHeader { get; set; }

[JsonProperty("has_row_header")]
public bool HasRowHeader { get; set; }

[JsonProperty("children")]
public TableRowBlock Children { get; set; }
}
}
}
19 changes: 19 additions & 0 deletions Src/Notion.Client/Models/Blocks/TableRowBlock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Notion.Client
{
public class TableRowBlock : Block, IColumnChildrenBlock, INonColumnBlock
{
public override BlockType Type => BlockType.TableRow;

[JsonProperty("table_row")]
public Info TableRow { get; set; }

public class Info
{
[JsonProperty("cells")]
public IEnumerable<IEnumerable<RichTextText>> Cells { get; set; }
}
}
}
8 changes: 7 additions & 1 deletion Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class DatePropertyValue : PropertyValue
/// <summary>
/// Date
/// </summary>
[JsonProperty("date")]
[JsonProperty("date", NullValueHandling = NullValueHandling.Include)]
public Date Date { get; set; }
}

Expand All @@ -33,5 +33,11 @@ public class Date
/// </summary>
[JsonProperty("end")]
public DateTime? End { get; set; }

/// <summary>
/// Optional time zone information for start and end. Possible values are extracted from the IANA database and they are based on the time zones from Moment.js.
/// </summary>
[JsonProperty("time_zone")]
public string TimeZone { get; set; }
}
}
77 changes: 72 additions & 5 deletions Test/Notion.IntegrationTests/IPageClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Notion.IntegrationTests
public class IPageClientTests
{
private readonly INotionClient _client;
private readonly string _databaseId;

public IPageClientTests()
{
Expand All @@ -20,14 +21,15 @@ public IPageClientTests()
};

_client = NotionClientFactory.Create(options);
_databaseId = Environment.GetEnvironmentVariable("DATABASE_ID") ?? "f86f2262-0751-40f2-8f63-e3f7a3c39fcb";
}

[Fact]
public async Task CreateAsync_CreatesANewPage()
{
PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput
{
DatabaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb"
DatabaseId = _databaseId
})
.AddProperty("Name", new TitlePropertyValue
{
Expand All @@ -48,7 +50,7 @@ public async Task CreateAsync_CreatesANewPage()

page.Should().NotBeNull();
page.Parent.Should().BeOfType<DatabaseParent>().Which
.DatabaseId.Should().Be("f86f2262-0751-40f2-8f63-e3f7a3c39fcb");
.DatabaseId.Should().Be(_databaseId);

page.Properties.Should().ContainKey("Name");
page.Properties["Name"].Should().BeOfType<TitlePropertyValue>().Which
Expand All @@ -65,7 +67,7 @@ public async Task Bug_unable_to_create_page_with_select_property()
{
PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput
{
DatabaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb"
DatabaseId = _databaseId
})
.AddProperty("Name", new TitlePropertyValue
{
Expand Down Expand Up @@ -93,7 +95,7 @@ public async Task Bug_unable_to_create_page_with_select_property()

page.Should().NotBeNull();
page.Parent.Should().BeOfType<DatabaseParent>().Which
.DatabaseId.Should().Be("f86f2262-0751-40f2-8f63-e3f7a3c39fcb");
.DatabaseId.Should().Be(_databaseId);

page.Properties.Should().ContainKey("Name");
page.Properties["Name"].Should().BeOfType<TitlePropertyValue>().Which
Expand All @@ -110,7 +112,7 @@ public async Task Test_RetrievePagePropertyItemAsync()
{
PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput
{
DatabaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb"
DatabaseId = _databaseId
})
.AddProperty("Name", new TitlePropertyValue
{
Expand Down Expand Up @@ -155,5 +157,70 @@ public async Task Test_RetrievePagePropertyItemAsync()
Archived = true
});
}

[Fact]
public async Task Test_UpdatePageProperty_with_date_as_null()
{
// setup - add property to db and create a page with the property having a date

string datePropertyName = "Test Date Property";
var updateDatabaseParameters = new DatabasesUpdateParameters();
updateDatabaseParameters.Properties = new Dictionary<string, IUpdatePropertySchema>
{
{ "Name", new TitleUpdatePropertySchema { Title = new Dictionary<string, object>() } },
{ "Test Date Property", new DateUpdatePropertySchema{ Date = new Dictionary<string, object>() } }
};

PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput
{
DatabaseId = _databaseId
})
.AddProperty("Name", new TitlePropertyValue
{
Title = new List<RichTextBase>
{
new RichTextText
{
Text = new Text
{
Content = "Test Page Title"
}
}
}
})
.AddProperty(datePropertyName, new DatePropertyValue
{
Date = new Date()
{
Start = Convert.ToDateTime("2020-12-08T12:00:00Z"),
End = Convert.ToDateTime("2025-12-08T12:00:00Z")
}
})
.Build();

var updatedDb = await _client.Databases.UpdateAsync(_databaseId, updateDatabaseParameters);

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

var setDate = page.Properties[datePropertyName] as DatePropertyValue;

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

// verify
IDictionary<string, PropertyValue> testProps = new Dictionary<string, PropertyValue>();
testProps.Add(datePropertyName, new DatePropertyValue() { Date = null });

var updatedPage = await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters
{
Properties = testProps
});

var verifyDate = updatedPage.Properties[datePropertyName] as DatePropertyValue;

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

//cleanup
await _client.Blocks.DeleteAsync(page.Id);
}
}
}

0 comments on commit f309683

Please sign in to comment.