Skip to content

Commit

Permalink
fix a, h2, h3. Add unit tests. pre6.
Browse files Browse the repository at this point in the history
  • Loading branch information
softlion committed Jan 12, 2024
1 parent 59b388e commit 99ebe20
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="notion-paragraph"><div class="notion-line">This content is written on a Notion page. It is a demo page for our csharp </div><div class="notion-line"><a href="http://notion.so/">notion.so</a></div><div class="notion-line"> api client.</div></div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"id":"a5a61607-488d-49ae-b2ee-60a8413deba1","parent":{"type":"page_id","page_id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585"},"type":"paragraph","created_time":"2020-04-30T13:38:00+00:00","created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_time":"2020-05-27T10:20:00+00:00","last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"archived":false,"has_children":false,"paragraph":{"rich_text":[{"type":"text","plain_text":"This content is written on a Notion page. It is a demo page for our csharp ","annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"text":{"content":"This content is written on a Notion page. It is a demo page for our csharp "}},{"type":"text","plain_text":"notion.so","href":"http://notion.so/","annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"text":{"content":"notion.so","link":{"url":"http://notion.so/"}}},{"type":"text","plain_text":" api client.","annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"text":{"content":" api client."}}]},"object":"block"},{"id":"5b08e855-e221-41db-a442-bdc6384414e2","parent":{"type":"page_id","page_id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585"},"type":"paragraph","created_time":"2020-05-27T10:21:00+00:00","created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_time":"2020-05-27T10:21:00+00:00","last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"archived":false,"has_children":false,"paragraph":{"rich_text":[]},"object":"block"},{"id":"78598042-5f17-4ae3-8ef7-270e86aa7ae6","parent":{"type":"page_id","page_id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585"},"type":"heading_1","created_time":"2020-05-27T10:20:00+00:00","created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_time":"2024-01-12T11:02:00+00:00","last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"archived":false,"has_children":false,"heading_1":{"rich_text":[{"type":"text","plain_text":"Title 1","annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"text":{"content":"Title 1"}}]},"object":"block"},{"id":"f58ac7ca-8059-4487-8997-59948dd98148","parent":{"type":"page_id","page_id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585"},"type":"heading_2","created_time":"2024-01-12T11:02:00+00:00","created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_time":"2024-01-12T11:02:00+00:00","last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"archived":false,"has_children":false,"heading_2":{"rich_text":[{"type":"text","plain_text":"Title 2","annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"text":{"content":"Title 2"}}]},"object":"block"},{"id":"7919eb3f-cffe-46cb-95d0-8a4f27830a88","parent":{"type":"page_id","page_id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585"},"type":"paragraph","created_time":"2020-04-30T13:39:00+00:00","created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_time":"2020-05-27T10:20:00+00:00","last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"archived":false,"has_children":false,"paragraph":{"rich_text":[{"type":"text","plain_text":"It contains some lines to test the api client, especially these methods:","annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"text":{"content":"It contains some lines to test the api client, especially these methods:"}}]},"object":"block"},{"id":"85148c18-9dcc-4b27-9ca9-b74a15957c40","parent":{"type":"page_id","page_id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585"},"type":"bulleted_list_item","created_time":"2020-04-30T13:39:00+00:00","created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_time":"2020-04-30T13:39:00+00:00","last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"archived":false,"has_children":false,"bulleted_list_item":{"rich_text":[{"type":"text","plain_text":"GetHtml","annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"text":{"content":"GetHtml"}}]},"object":"block"},{"id":"31a6469a-8509-49e8-9033-7d34dfdd11c1","parent":{"type":"page_id","page_id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585"},"type":"bulleted_list_item","created_time":"2020-04-30T13:39:00+00:00","created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_time":"2020-04-30T13:39:00+00:00","last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"archived":false,"has_children":false,"bulleted_list_item":{"rich_text":[{"type":"text","plain_text":"LoadPageChunk","annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"text":{"content":"LoadPageChunk"}}]},"object":"block"},{"id":"72dd306a-1c1e-4c8a-afb0-424c7138cf60","parent":{"type":"page_id","page_id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585"},"type":"bulleted_list_item","created_time":"2020-04-30T13:40:00+00:00","created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_time":"2020-04-30T13:40:00+00:00","last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"archived":false,"has_children":false,"bulleted_list_item":{"rich_text":[{"type":"text","plain_text":"GetSyndicationFeed","annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"text":{"content":"GetSyndicationFeed"}}]},"object":"block"},{"id":"977c714e-b1a4-4911-8afd-6653ae54cd1b","parent":{"type":"page_id","page_id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585"},"type":"paragraph","created_time":"2020-05-27T10:20:00+00:00","created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_time":"2020-05-27T10:20:00+00:00","last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"archived":false,"has_children":false,"paragraph":{"rich_text":[]},"object":"block"},{"id":"1e1c8000-dcfa-4dd0-a955-8fe7fd5c6fdf","parent":{"type":"page_id","page_id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585"},"type":"paragraph","created_time":"2020-04-30T13:40:00+00:00","created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_time":"2023-11-26T17:53:00+00:00","last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"archived":false,"has_children":false,"paragraph":{"rich_text":[{"type":"text","plain_text":"\u2653 The last one is the most powerful: it creates a rss like feed from a ","annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"text":{"content":"\u2653 The last one is the most powerful: it creates a rss like feed from a "}},{"type":"text","plain_text":"notion","href":"http://notion.so/","annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"text":{"content":"notion","link":{"url":"http://notion.so/"}}},{"type":"text","plain_text":" collection. It opens cool things like creating a full website from a notion page hierarchy.","annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"text":{"content":" collection. It opens cool things like creating a full website from a notion page hierarchy."}}]},"object":"block"},{"id":"2866f22f-16b3-4cb3-a381-f91f52c9b443","parent":{"type":"page_id","page_id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585"},"type":"paragraph","created_time":"2020-05-27T10:20:00+00:00","created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_time":"2023-11-26T16:03:00+00:00","last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"archived":false,"has_children":false,"paragraph":{"rich_text":[]},"object":"block"},{"id":"19766178-d501-4a42-890f-2af001d9f05c","parent":{"type":"page_id","page_id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585"},"type":"callout","created_time":"2020-05-27T10:20:00+00:00","created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_time":"2023-11-26T16:04:00+00:00","last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"archived":false,"has_children":false,"callout":{"rich_text":[{"type":"text","plain_text":"This is a CallOut !","annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"text":{"content":"This is a CallOut !"}}],"color":"gray_background","icon":{"emoji":"\uD83D\uDCE2","type":"emoji"}},"object":"block"},{"id":"9a68013d-d6ec-4a3f-96ed-2f392bad52b8","parent":{"type":"page_id","page_id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585"},"type":"paragraph","created_time":"2023-11-26T16:03:00+00:00","created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_time":"2023-11-26T16:04:00+00:00","last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"archived":false,"has_children":false,"paragraph":{"rich_text":[]},"object":"block"},{"id":"66930c42-ed4c-48dd-be36-2e8e1b9a4459","parent":{"type":"page_id","page_id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585"},"type":"column_list","created_time":"2023-11-26T16:05:00+00:00","created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_time":"2023-11-26T16:05:00+00:00","last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"archived":false,"has_children":true,"object":"block"},{"id":"d3ca09fc-48da-41ef-afb8-a1307a1e9cfa","parent":{"type":"page_id","page_id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585"},"type":"paragraph","created_time":"2023-11-26T16:06:00+00:00","created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_time":"2023-11-26T16:07:00+00:00","last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"archived":false,"has_children":false,"paragraph":{"rich_text":[]},"object":"block"},{"id":"a8fd2706-3222-467e-a9c5-3cb47df50b43","parent":{"type":"page_id","page_id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585"},"type":"quote","created_time":"2023-11-26T16:06:00+00:00","created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_time":"2023-11-26T16:07:00+00:00","last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"archived":false,"has_children":false,"quote":{"color":"default","rich_text":[{"type":"text","plain_text":"The End Quote","annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"text":{"content":"The End Quote"}}]},"object":"block"},{"id":"502ec809-7326-4a71-a546-89a6d1e92cf8","parent":{"type":"page_id","page_id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585"},"type":"paragraph","created_time":"2023-11-26T16:07:00+00:00","created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_time":"2023-11-26T16:07:00+00:00","last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"archived":false,"has_children":false,"paragraph":{"rich_text":[]},"object":"block"}]
1 change: 1 addition & 0 deletions NotionSharp.ApiClient.Tests/JsonData/AboutThis.full.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"id":"c7b44455-3d31-4a5b-b82c-b7e3d85ba585","created_time":"2020-04-30T13:37:00+00:00","last_edited_time":"2023-11-26T17:53:00+00:00","archived":false,"created_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"last_edited_by":{"id":"ab9257e1-d027-4494-8792-71d90b63dd35","object":"user"},"url":"https://www.notion.so/About-this-c7b444553d314a5bb82cb7e3d85ba585","public_url":"https://wise-spirit-737.notion.site/About-this-c7b444553d314a5bb82cb7e3d85ba585","parent":{"page_id":"18dfbe55-5d7c-416e-9485-7855d4a3949e","type":"page_id"},"properties":{"title":{"title":[{"type":"text","plain_text":"About this","annotations":{"bold":false,"italic":false,"strikethrough":false,"underline":false,"code":false,"color":"default"},"text":{"content":"About this"}}],"id":"title","type":"title"}},"object":"page"}
4 changes: 2 additions & 2 deletions NotionSharp.ApiClient.Tests/Lib/TestUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class TestUtils
public static NotionSessionInfo CreateOfficialNotionSessionInfo()
{
//notioncsharp@yopmail.com
//http://yopmail.com/notioncsharp
return new NotionSessionInfo
//https://yopmail.com / notioncsharp
return new()
{
Token = "secret_jbPRU7vdj8hmpKFnT3ntld4mcXg4dTOYuqsVc7hj9KF",
};
Expand Down
34 changes: 34 additions & 0 deletions NotionSharp.ApiClient.Tests/TestNotionBase.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
Expand Down Expand Up @@ -250,6 +251,39 @@ public async Task TestPageAndChildrenDeserialization()
var blocks = JsonSerializer.Deserialize<PaginationResult<Block>>(blocksJson, HttpNotionSession.NotionJsonSerializationOptions);
Assert.IsNotNull(blocks);
}

[TestMethod]
[Ignore("Run this manually to create the json files")]
public async Task TestPageAndChildrenSerialization()
{
var session = new NotionSession(TestUtils.CreateOfficialNotionSessionInfo());
var page = await session.Search(query: "About this", filterOptions: FilterOptions.ObjectPage).FirstAsync();
Assert.AreEqual("About this", page?.Title()?.Title.FirstOrDefault()?.PlainText);

var blocks = await session.GetBlockChildren(page.Id).ToListAsync();
var blockWithChildren = new Queue<Block>(blocks.Where(b => b.HasChildren && BlockTypes.BlocksWithChildren.Contains(b.Type)));
while (blockWithChildren.Count != 0)
{
var block = blockWithChildren.Dequeue();
await session.GetChildren(block);
//recursive
var children = block.Children.Where(b => b.HasChildren && BlockTypes.BlocksWithChildren.Contains(b.Type));
foreach (var child in children)
blockWithChildren.Enqueue(child);
}

var pageJson = JsonSerializer.Serialize(page, HttpNotionSession.NotionJsonSerializationOptions);
var blocksJson = JsonSerializer.Serialize(blocks, HttpNotionSession.NotionJsonSerializationOptions);
var path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
await File.WriteAllTextAsync(Path.Combine(path, "AboutThis.full.json"), pageJson);
await File.WriteAllTextAsync(Path.Combine(path, "AboutThis.full.children.json"), blocksJson);

var page2 = JsonSerializer.Deserialize<Page>(pageJson, HttpNotionSession.NotionJsonSerializationOptions);
Assert.IsNotNull(page2);
var blocks2 = JsonSerializer.Deserialize<List<Block>>(blocksJson, HttpNotionSession.NotionJsonSerializationOptions);
Assert.IsNotNull(blocks2);
Assert.AreEqual(blocks.Count,blocks2.Count);
}

[TestMethod]
public void TestNotionUtils()
Expand Down
Loading

0 comments on commit 99ebe20

Please sign in to comment.