aboutsummaryrefslogtreecommitdiff
path: root/src/models/block
diff options
context:
space:
mode:
Diffstat (limited to 'src/models/block')
-rw-r--r--src/models/block/tests.rs296
-rw-r--r--src/models/block/tests/callout.json43
-rw-r--r--src/models/block/tests/emoji_object.json4
-rw-r--r--src/models/block/tests/external_file_object.json6
-rw-r--r--src/models/block/tests/file_object.json7
-rw-r--r--src/models/block/tests/heading_1.json175
6 files changed, 531 insertions, 0 deletions
diff --git a/src/models/block/tests.rs b/src/models/block/tests.rs
new file mode 100644
index 0000000..18306a6
--- /dev/null
+++ b/src/models/block/tests.rs
@@ -0,0 +1,296 @@
+#[cfg(test)]
+mod tests {
+ use crate::ids::{BlockId, UserId};
+ use crate::models::block::{
+ Block, BlockCommon, Callout, ExternalFileObject, FileOrEmojiObject, InternalFileObject,
+ Text as TextBlockModel,
+ };
+ use crate::models::text::{Annotations, RichText, RichTextCommon, Text, TextColor};
+ use crate::models::users::UserCommon;
+ use crate::models::Object;
+ use chrono::DateTime;
+ use std::str::FromStr;
+
+ #[test]
+ fn heading_1() {
+ let heading_1: Block = serde_json::from_str(include_str!("tests/heading_1.json")).unwrap();
+ assert_eq!(
+ heading_1,
+ Block::Heading1 {
+ common: BlockCommon {
+ id: BlockId::from_str("9e891834-6a03-475c-a2b8-421e17f0f3aa").unwrap(),
+ created_time: DateTime::from_str("2022-05-12T21:15:00.000Z").unwrap(),
+ last_edited_time: DateTime::from_str("2022-05-12T22:10:00.000Z").unwrap(),
+ has_children: false,
+ created_by: UserCommon {
+ id: UserId::from_str("6419f912-5293-4ea8-b2c8-9c3ce44f90e3").unwrap(),
+ name: None,
+ avatar_url: None,
+ },
+ last_edited_by: UserCommon {
+ id: UserId::from_str("6419f912-5293-4ea8-b2c8-9c3ce44f90e3").unwrap(),
+ name: None,
+ avatar_url: None,
+ },
+ },
+ heading_1: TextBlockModel {
+ rich_text: vec![
+ RichText::Text {
+ rich_text: RichTextCommon {
+ plain_text: "This".to_string(),
+ href: None,
+ annotations: Some(Annotations {
+ bold: Some(false),
+ code: Some(true),
+ color: Some(TextColor::Default),
+ italic: Some(false),
+ strikethrough: Some(false),
+ underline: Some(false),
+ }),
+ },
+ text: Text {
+ content: "This".to_string(),
+ link: None,
+ },
+ },
+ RichText::Text {
+ rich_text: RichTextCommon {
+ plain_text: " ".to_string(),
+ href: None,
+ annotations: Some(Annotations {
+ bold: Some(false),
+ code: Some(false),
+ color: Some(TextColor::Default),
+ italic: Some(false),
+ strikethrough: Some(false),
+ underline: Some(false),
+ }),
+ },
+ text: Text {
+ content: " ".to_string(),
+ link: None,
+ },
+ },
+ RichText::Text {
+ rich_text: RichTextCommon {
+ plain_text: "is".to_string(),
+ href: None,
+ annotations: Some(Annotations {
+ bold: Some(false),
+ code: Some(false),
+ color: Some(TextColor::Default),
+ italic: Some(false),
+ strikethrough: Some(false),
+ underline: Some(true),
+ }),
+ },
+ text: Text {
+ content: "is".to_string(),
+ link: None,
+ },
+ },
+ RichText::Text {
+ rich_text: RichTextCommon {
+ plain_text: " ".to_string(),
+ href: None,
+ annotations: Some(Annotations {
+ bold: Some(false),
+ code: Some(false),
+ color: Some(TextColor::Default),
+ italic: Some(false),
+ strikethrough: Some(false),
+ underline: Some(false),
+ }),
+ },
+ text: Text {
+ content: " ".to_string(),
+ link: None,
+ },
+ },
+ RichText::Text {
+ rich_text: RichTextCommon {
+ plain_text: "a".to_string(),
+ href: None,
+ annotations: Some(Annotations {
+ bold: Some(false),
+ code: Some(false),
+ color: Some(TextColor::Default),
+ italic: Some(true),
+ strikethrough: Some(false),
+ underline: Some(true),
+ }),
+ },
+ text: Text {
+ content: "a".to_string(),
+ link: None,
+ },
+ },
+ RichText::Text {
+ rich_text: RichTextCommon {
+ plain_text: " ".to_string(),
+ href: None,
+ annotations: Some(Annotations {
+ bold: Some(false),
+ code: Some(false),
+ color: Some(TextColor::Default),
+ italic: Some(false),
+ strikethrough: Some(false),
+ underline: Some(false),
+ }),
+ },
+ text: Text {
+ content: " ".to_string(),
+ link: None,
+ },
+ },
+ RichText::Text {
+ rich_text: RichTextCommon {
+ plain_text: "Heading".to_string(),
+ href: None,
+ annotations: Some(Annotations {
+ bold: Some(false),
+ code: Some(false),
+ color: Some(TextColor::Default),
+ italic: Some(true),
+ strikethrough: Some(false),
+ underline: Some(false),
+ }),
+ },
+ text: Text {
+ content: "Heading".to_string(),
+ link: None,
+ },
+ },
+ RichText::Text {
+ rich_text: RichTextCommon {
+ plain_text: " ".to_string(),
+ href: None,
+ annotations: Some(Annotations {
+ bold: Some(false),
+ code: Some(false),
+ color: Some(TextColor::Default),
+ italic: Some(false),
+ strikethrough: Some(false),
+ underline: Some(false),
+ }),
+ },
+ text: Text {
+ content: " ".to_string(),
+ link: None,
+ },
+ },
+ RichText::Text {
+ rich_text: RichTextCommon {
+ plain_text: "1".to_string(),
+ href: None,
+ annotations: Some(Annotations {
+ bold: Some(false),
+ code: Some(false),
+ color: Some(TextColor::Default),
+ italic: Some(false),
+ strikethrough: Some(true),
+ underline: Some(false),
+ }),
+ },
+ text: Text {
+ content: "1".to_string(),
+ link: None,
+ },
+ },
+ ]
+ },
+ }
+ )
+ }
+
+ #[test]
+ fn emoji_object() {
+ let emoji_object: FileOrEmojiObject =
+ serde_json::from_str(include_str!("tests/emoji_object.json")).unwrap();
+ assert_eq!(
+ emoji_object,
+ FileOrEmojiObject::Emoji {
+ emoji: "💡".to_string()
+ }
+ )
+ }
+
+ #[test]
+ fn file_object() {
+ let file_object: FileOrEmojiObject =
+ serde_json::from_str(include_str!("tests/file_object.json")).unwrap();
+ assert_eq!(file_object, FileOrEmojiObject::File {
+ file: InternalFileObject {
+ url: "https://s3.us-west-2.amazonaws.com/secure.notion-static.com/2703e742-ace5-428c-a74d-1c587ceddc32/DiRT_Rally.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45EIPT3X45%2F20220513%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20220513T201035Z&X-Amz-Expires=3600&X-Amz-Signature=714b49bde0b499fb8f3aae1a88a8cbd374f2b09c1d128e91cac49e85ce0e00fb&X-Amz-SignedHeaders=host&x-id=GetObject".to_string(),
+ expiry_time: DateTime::from_str("2022-05-13T21:10:35.817Z").unwrap(),
+ }
+ })
+ }
+
+ #[test]
+ fn external_file_object() {
+ let external_file_object: FileOrEmojiObject =
+ serde_json::from_str(include_str!("tests/external_file_object.json")).unwrap();
+ assert_eq!(
+ external_file_object,
+ FileOrEmojiObject::External {
+ external: ExternalFileObject {
+ url: "https://nerdist.com/wp-content/uploads/2020/07/maxresdefault.jpg"
+ .to_string(),
+ }
+ }
+ )
+ }
+
+ #[test]
+ fn callout() {
+ let callout: Object = serde_json::from_str(include_str!("tests/callout.json")).unwrap();
+ assert_eq!(
+ callout,
+ Object::Block {
+ block: Block::Callout {
+ common: BlockCommon {
+ id: BlockId::from_str("00e8829a-a7b8-4075-884a-8f53be145d2f").unwrap(),
+ created_time: DateTime::from_str("2022-05-13T20:08:00.000Z").unwrap(),
+ last_edited_time: DateTime::from_str("2022-05-13T20:08:00.000Z").unwrap(),
+ has_children: true,
+ created_by: UserCommon {
+ id: UserId::from_str("e2507360-468c-4e0f-a928-7bbcbbb45353").unwrap(),
+ name: None,
+ avatar_url: None,
+ },
+ last_edited_by: UserCommon {
+ id: UserId::from_str("e2507360-468c-4e0f-a928-7bbcbbb45353").unwrap(),
+ name: None,
+ avatar_url: None,
+ },
+ },
+ callout: Callout {
+ rich_text: vec![RichText::Text {
+ rich_text: RichTextCommon {
+ plain_text: "Test callout".to_string(),
+ href: None,
+ annotations: Some(Annotations {
+ bold: Some(false),
+ code: Some(false),
+ color: Some(TextColor::Default),
+ italic: Some(false),
+ strikethrough: Some(false),
+ underline: Some(false),
+ }),
+ },
+ text: Text {
+ content: "Test callout".to_string(),
+ link: None
+ },
+ }],
+ icon: FileOrEmojiObject::Emoji {
+ emoji: "💡".to_string()
+ },
+ color: TextColor::Green,
+ },
+ }
+ }
+ )
+ }
+}
diff --git a/src/models/block/tests/callout.json b/src/models/block/tests/callout.json
new file mode 100644
index 0000000..e4d884d
--- /dev/null
+++ b/src/models/block/tests/callout.json
@@ -0,0 +1,43 @@
+{
+ "object": "block",
+ "id": "00e8829a-a7b8-4075-884a-8f53be145d2f",
+ "created_time": "2022-05-13T20:08:00.000Z",
+ "last_edited_time": "2022-05-13T20:08:00.000Z",
+ "created_by": {
+ "object": "user",
+ "id": "e2507360-468c-4e0f-a928-7bbcbbb45353"
+ },
+ "last_edited_by": {
+ "object": "user",
+ "id": "e2507360-468c-4e0f-a928-7bbcbbb45353"
+ },
+ "has_children": true,
+ "archived": false,
+ "type": "callout",
+ "callout": {
+ "rich_text": [
+ {
+ "type": "text",
+ "text": {
+ "content": "Test callout",
+ "link": null
+ },
+ "annotations": {
+ "bold": false,
+ "italic": false,
+ "strikethrough": false,
+ "underline": false,
+ "code": false,
+ "color": "default"
+ },
+ "plain_text": "Test callout",
+ "href": null
+ }
+ ],
+ "icon": {
+ "type": "emoji",
+ "emoji": "💡"
+ },
+ "color": "green"
+ }
+} \ No newline at end of file
diff --git a/src/models/block/tests/emoji_object.json b/src/models/block/tests/emoji_object.json
new file mode 100644
index 0000000..1fb3b56
--- /dev/null
+++ b/src/models/block/tests/emoji_object.json
@@ -0,0 +1,4 @@
+{
+ "type": "emoji",
+ "emoji": "💡"
+} \ No newline at end of file
diff --git a/src/models/block/tests/external_file_object.json b/src/models/block/tests/external_file_object.json
new file mode 100644
index 0000000..b5d4b85
--- /dev/null
+++ b/src/models/block/tests/external_file_object.json
@@ -0,0 +1,6 @@
+{
+ "type": "external",
+ "external": {
+ "url": "https://nerdist.com/wp-content/uploads/2020/07/maxresdefault.jpg"
+ }
+} \ No newline at end of file
diff --git a/src/models/block/tests/file_object.json b/src/models/block/tests/file_object.json
new file mode 100644
index 0000000..650cf9b
--- /dev/null
+++ b/src/models/block/tests/file_object.json
@@ -0,0 +1,7 @@
+{
+ "type": "file",
+ "file": {
+ "url": "https://s3.us-west-2.amazonaws.com/secure.notion-static.com/2703e742-ace5-428c-a74d-1c587ceddc32/DiRT_Rally.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45EIPT3X45%2F20220513%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20220513T201035Z&X-Amz-Expires=3600&X-Amz-Signature=714b49bde0b499fb8f3aae1a88a8cbd374f2b09c1d128e91cac49e85ce0e00fb&X-Amz-SignedHeaders=host&x-id=GetObject",
+ "expiry_time": "2022-05-13T21:10:35.817Z"
+ }
+} \ No newline at end of file
diff --git a/src/models/block/tests/heading_1.json b/src/models/block/tests/heading_1.json
new file mode 100644
index 0000000..ab2d7e1
--- /dev/null
+++ b/src/models/block/tests/heading_1.json
@@ -0,0 +1,175 @@
+{
+ "object": "block",
+ "id": "9e891834-6a03-475c-a2b8-421e17f0f3aa",
+ "created_time": "2022-05-12T21:15:00.000Z",
+ "last_edited_time": "2022-05-12T22:10:00.000Z",
+ "created_by": {
+ "object": "user",
+ "id": "6419f912-5293-4ea8-b2c8-9c3ce44f90e3"
+ },
+ "last_edited_by": {
+ "object": "user",
+ "id": "6419f912-5293-4ea8-b2c8-9c3ce44f90e3"
+ },
+ "has_children": false,
+ "archived": false,
+ "type": "heading_1",
+ "heading_1": {
+ "rich_text": [
+ {
+ "type": "text",
+ "text": {
+ "content": "This",
+ "link": null
+ },
+ "annotations": {
+ "bold": false,
+ "italic": false,
+ "strikethrough": false,
+ "underline": false,
+ "code": true,
+ "color": "default"
+ },
+ "plain_text": "This",
+ "href": null
+ },
+ {
+ "type": "text",
+ "text": {
+ "content": " ",
+ "link": null
+ },
+ "annotations": {
+ "bold": false,
+ "italic": false,
+ "strikethrough": false,
+ "underline": false,
+ "code": false,
+ "color": "default"
+ },
+ "plain_text": " ",
+ "href": null
+ },
+ {
+ "type": "text",
+ "text": {
+ "content": "is",
+ "link": null
+ },
+ "annotations": {
+ "bold": false,
+ "italic": false,
+ "strikethrough": false,
+ "underline": true,
+ "code": false,
+ "color": "default"
+ },
+ "plain_text": "is",
+ "href": null
+ },
+ {
+ "type": "text",
+ "text": {
+ "content": " ",
+ "link": null
+ },
+ "annotations": {
+ "bold": false,
+ "italic": false,
+ "strikethrough": false,
+ "underline": false,
+ "code": false,
+ "color": "default"
+ },
+ "plain_text": " ",
+ "href": null
+ },
+ {
+ "type": "text",
+ "text": {
+ "content": "a",
+ "link": null
+ },
+ "annotations": {
+ "bold": false,
+ "italic": true,
+ "strikethrough": false,
+ "underline": true,
+ "code": false,
+ "color": "default"
+ },
+ "plain_text": "a",
+ "href": null
+ },
+ {
+ "type": "text",
+ "text": {
+ "content": " ",
+ "link": null
+ },
+ "annotations": {
+ "bold": false,
+ "italic": false,
+ "strikethrough": false,
+ "underline": false,
+ "code": false,
+ "color": "default"
+ },
+ "plain_text": " ",
+ "href": null
+ },
+ {
+ "type": "text",
+ "text": {
+ "content": "Heading",
+ "link": null
+ },
+ "annotations": {
+ "bold": false,
+ "italic": true,
+ "strikethrough": false,
+ "underline": false,
+ "code": false,
+ "color": "default"
+ },
+ "plain_text": "Heading",
+ "href": null
+ },
+ {
+ "type": "text",
+ "text": {
+ "content": " ",
+ "link": null
+ },
+ "annotations": {
+ "bold": false,
+ "italic": false,
+ "strikethrough": false,
+ "underline": false,
+ "code": false,
+ "color": "default"
+ },
+ "plain_text": " ",
+ "href": null
+ },
+ {
+ "type": "text",
+ "text": {
+ "content": "1",
+ "link": null
+ },
+ "annotations": {
+ "bold": false,
+ "italic": false,
+ "strikethrough": true,
+ "underline": false,
+ "code": false,
+ "color": "default"
+ },
+ "plain_text": "1",
+ "href": null
+ }
+ ],
+ "color": "default"
+ }
+} \ No newline at end of file