aboutsummaryrefslogtreecommitdiff
path: root/src/models
diff options
context:
space:
mode:
authorGravatar Jake Swenson <jake@jakeswenson.com> 2022-05-17 22:36:03 -0700
committerGravatar Jake Swenson <jake@jakeswenson.com> 2022-05-17 22:36:03 -0700
commit3261af8d715d05d1b4a25c54dbb81ddb9d5ce5f7 (patch)
treeda87200eb39553f4390c9d6e8f74166df6e5de13 /src/models
parent3ca93ff3315b317384e72914367905cee9cabc57 (diff)
downloadnotion-3261af8d715d05d1b4a25c54dbb81ddb9d5ce5f7.tar.gz
notion-3261af8d715d05d1b4a25c54dbb81ddb9d5ce5f7.tar.zst
notion-3261af8d715d05d1b4a25c54dbb81ddb9d5ce5f7.zip
style(cargo fmt): Format code
Diffstat (limited to '')
-rw-r--r--src/models/mod.rs11
-rw-r--r--src/models/properties.rs2
-rw-r--r--src/models/tests.rs707
-rw-r--r--src/models/text.rs16
4 files changed, 392 insertions, 344 deletions
diff --git a/src/models/mod.rs b/src/models/mod.rs
index 175f3c5..aca6cfe 100644
--- a/src/models/mod.rs
+++ b/src/models/mod.rs
@@ -249,7 +249,6 @@ pub enum FileObject {
External { external: ExternalFileObject },
}
-
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
pub struct Callout {
pub rich_text: Vec<RichText>,
@@ -413,12 +412,8 @@ pub struct TemplateFields {
#[serde(tag = "type")]
#[serde(rename_all = "snake_case")]
pub enum LinkToPageFields {
- PageId {
- page_id: PageId
- },
- DatabaseId {
- database_id: DatabaseId
- },
+ PageId { page_id: PageId },
+ DatabaseId { database_id: DatabaseId },
}
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
@@ -649,7 +644,7 @@ impl AsIdentifier<BlockId> for Block {
| SyncedBlock { common, .. }
| Table { common, .. }
| TableRow { common, .. }
- | Unsupported { common, .. } => { &common.id }
+ | Unsupported { common, .. } => &common.id,
Unknown => {
panic!("Trying to reference identifier for unknown block!")
}
diff --git a/src/models/properties.rs b/src/models/properties.rs
index 948a0a0..3fa5935 100644
--- a/src/models/properties.rs
+++ b/src/models/properties.rs
@@ -206,7 +206,7 @@ pub enum DateOrDateTime {
pub struct DateValue {
pub start: DateOrDateTime,
pub end: Option<DateOrDateTime>,
- pub time_zone: Option<String>
+ pub time_zone: Option<String>,
}
/// Formula property value objects represent the result of evaluating a formula
diff --git a/src/models/tests.rs b/src/models/tests.rs
index fa58d54..67e952d 100644
--- a/src/models/tests.rs
+++ b/src/models/tests.rs
@@ -1,11 +1,16 @@
-use std::str::FromStr;
-use chrono::{DateTime, NaiveDate};
-use crate::{Block, BlockId, models};
use crate::ids::UserId;
-use crate::models::text::{Annotations, Link, MentionObject, RichText, RichTextCommon, Text, TextColor};
-use crate::models::{BlockCommon, Callout, ExternalFileObject, InternalFileObject, FileOrEmojiObject, ListResponse, Object, Page};
use crate::models::properties::{DateOrDateTime, DateValue};
+use crate::models::text::{
+ Annotations, Link, MentionObject, RichText, RichTextCommon, Text, TextColor,
+};
use crate::models::users::{Person, User, UserCommon};
+use crate::models::{
+ BlockCommon, Callout, ExternalFileObject, FileOrEmojiObject, InternalFileObject, ListResponse,
+ Object, Page,
+};
+use crate::{models, Block, BlockId};
+use chrono::{DateTime, NaiveDate};
+use std::str::FromStr;
#[test]
fn deserialize_page() {
@@ -26,32 +31,37 @@ fn deserialize_number_format() {
#[test]
fn rich_text() {
- let rich_text_text: RichText = serde_json::from_str(include_str!("tests/rich_text_text.json")).unwrap();
- assert_eq!(rich_text_text, RichText::Text {
- rich_text: RichTextCommon {
- plain_text: "Rich".to_string(),
- href: Some("https://github.com/jakeswenson/notion".to_string()),
- annotations: Some(Annotations {
- bold: Some(true),
- code: Some(true),
- color: Some(TextColor::Default),
- italic: Some(true),
- strikethrough: Some(true),
- underline: Some(true),
- }),
- },
- text: Text {
- content: "Rich".to_string(),
- link: Some(Link {
- url: "https://github.com/jakeswenson/notion".to_string()
- }),
- },
- })
+ let rich_text_text: RichText =
+ serde_json::from_str(include_str!("tests/rich_text_text.json")).unwrap();
+ assert_eq!(
+ rich_text_text,
+ RichText::Text {
+ rich_text: RichTextCommon {
+ plain_text: "Rich".to_string(),
+ href: Some("https://github.com/jakeswenson/notion".to_string()),
+ annotations: Some(Annotations {
+ bold: Some(true),
+ code: Some(true),
+ color: Some(TextColor::Default),
+ italic: Some(true),
+ strikethrough: Some(true),
+ underline: Some(true),
+ }),
+ },
+ text: Text {
+ content: "Rich".to_string(),
+ link: Some(Link {
+ url: "https://github.com/jakeswenson/notion".to_string()
+ }),
+ },
+ }
+ )
}
#[test]
fn rich_text_mention_user_person() {
- let rich_text_mention_user_person: RichText = serde_json::from_str(include_str!("tests/rich_text_mention_user_person.json")).unwrap();
+ let rich_text_mention_user_person: RichText =
+ serde_json::from_str(include_str!("tests/rich_text_mention_user_person.json")).unwrap();
assert_eq!(rich_text_mention_user_person, RichText::Mention {
rich_text: RichTextCommon {
plain_text: "@John Doe".to_string(),
@@ -80,308 +90,343 @@ fn rich_text_mention_user_person() {
#[test]
fn rich_text_mention_date() {
- let rich_text_mention_date: RichText = serde_json::from_str(include_str!("tests/rich_text_mention_date.json")).unwrap();
- assert_eq!(rich_text_mention_date, RichText::Mention {
- rich_text: RichTextCommon {
- plain_text: "2022-04-16 → ".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),
- }),
- },
- mention: MentionObject::Date {
- date: DateValue {
- start: DateOrDateTime::Date(NaiveDate::from_str("2022-04-16").unwrap()),
- end: None,
- time_zone: None,
- }
- },
- })
+ let rich_text_mention_date: RichText =
+ serde_json::from_str(include_str!("tests/rich_text_mention_date.json")).unwrap();
+ assert_eq!(
+ rich_text_mention_date,
+ RichText::Mention {
+ rich_text: RichTextCommon {
+ plain_text: "2022-04-16 → ".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),
+ }),
+ },
+ mention: MentionObject::Date {
+ date: DateValue {
+ start: DateOrDateTime::Date(NaiveDate::from_str("2022-04-16").unwrap()),
+ end: None,
+ time_zone: None,
+ }
+ },
+ }
+ )
}
#[test]
fn rich_text_mention_date_with_time() {
- let rich_text_mention_date_with_time: RichText = serde_json::from_str(include_str!("tests/rich_text_mention_date_with_time.json")).unwrap();
- assert_eq!(rich_text_mention_date_with_time, RichText::Mention {
- rich_text: RichTextCommon {
- plain_text: "2022-05-14T09:00:00.000-04:00 → ".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),
- }),
- },
- mention: MentionObject::Date {
- date: DateValue {
- start: DateOrDateTime::DateTime(DateTime::from_str("2022-05-14T09:00:00.000-04:00").unwrap()),
- end: None,
- time_zone: None,
- }
- },
- })
+ let rich_text_mention_date_with_time: RichText =
+ serde_json::from_str(include_str!("tests/rich_text_mention_date_with_time.json")).unwrap();
+ assert_eq!(
+ rich_text_mention_date_with_time,
+ RichText::Mention {
+ rich_text: RichTextCommon {
+ plain_text: "2022-05-14T09:00:00.000-04:00 → ".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),
+ }),
+ },
+ mention: MentionObject::Date {
+ date: DateValue {
+ start: DateOrDateTime::DateTime(
+ DateTime::from_str("2022-05-14T09:00:00.000-04:00").unwrap()
+ ),
+ end: None,
+ time_zone: None,
+ }
+ },
+ }
+ )
}
#[test]
fn rich_text_mention_date_with_end() {
- let rich_text_mention_date_with_end: RichText = serde_json::from_str(include_str!("tests/rich_text_mention_date_with_end.json")).unwrap();
- assert_eq!(rich_text_mention_date_with_end, RichText::Mention {
- rich_text: RichTextCommon {
- plain_text: "2022-05-12 → 2022-05-13".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),
- }),
- },
- mention: MentionObject::Date {
- date: DateValue {
- start: DateOrDateTime::Date(NaiveDate::from_str("2022-05-12").unwrap()),
- end: Some(DateOrDateTime::Date(NaiveDate::from_str("2022-05-13").unwrap())),
- time_zone: None,
- }
- },
- })
+ let rich_text_mention_date_with_end: RichText =
+ serde_json::from_str(include_str!("tests/rich_text_mention_date_with_end.json")).unwrap();
+ assert_eq!(
+ rich_text_mention_date_with_end,
+ RichText::Mention {
+ rich_text: RichTextCommon {
+ plain_text: "2022-05-12 → 2022-05-13".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),
+ }),
+ },
+ mention: MentionObject::Date {
+ date: DateValue {
+ start: DateOrDateTime::Date(NaiveDate::from_str("2022-05-12").unwrap()),
+ end: Some(DateOrDateTime::Date(
+ NaiveDate::from_str("2022-05-13").unwrap()
+ )),
+ time_zone: None,
+ }
+ },
+ }
+ )
}
#[test]
fn rich_text_mention_date_with_end_and_time() {
- let rich_text_mention_date_with_end_and_time: RichText = serde_json::from_str(include_str!("tests/rich_text_mention_date_with_end_and_time.json")).unwrap();
- assert_eq!(rich_text_mention_date_with_end_and_time, RichText::Mention {
- rich_text: RichTextCommon {
- plain_text: "2022-04-16T12:00:00.000-04:00 → 2022-04-16T12:00:00.000-04:00".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),
- }),
- },
- mention: MentionObject::Date {
- date: DateValue {
- start: DateOrDateTime::DateTime(DateTime::from_str("2022-04-16T12:00:00.000-04:00").unwrap()),
- end: Some(DateOrDateTime::DateTime(DateTime::from_str("2022-04-16T12:00:00.000-04:00").unwrap())),
- time_zone: None,
- }
- },
- })
+ let rich_text_mention_date_with_end_and_time: RichText = serde_json::from_str(include_str!(
+ "tests/rich_text_mention_date_with_end_and_time.json"
+ ))
+ .unwrap();
+ assert_eq!(
+ rich_text_mention_date_with_end_and_time,
+ RichText::Mention {
+ rich_text: RichTextCommon {
+ plain_text: "2022-04-16T12:00:00.000-04:00 → 2022-04-16T12:00:00.000-04:00"
+ .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),
+ }),
+ },
+ mention: MentionObject::Date {
+ date: DateValue {
+ start: DateOrDateTime::DateTime(
+ DateTime::from_str("2022-04-16T12:00:00.000-04:00").unwrap()
+ ),
+ end: Some(DateOrDateTime::DateTime(
+ DateTime::from_str("2022-04-16T12:00:00.000-04:00").unwrap()
+ )),
+ time_zone: None,
+ }
+ },
+ }
+ )
}
#[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: models::Text {
- 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,
- },
+ 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,
},
- 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,
- },
+ last_edited_by: UserCommon {
+ id: UserId::from_str("6419f912-5293-4ea8-b2c8-9c3ce44f90e3").unwrap(),
+ name: None,
+ avatar_url: 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,
+ },
+ heading_1: models::Text {
+ 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),
- }),
+ 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,
+ },
},
- 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: "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),
- }),
+ 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,
+ },
},
- text: Text {
- content: "Heading".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),
- }),
+ 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,
+ },
},
- 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: "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),
- }),
+ 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,
+ },
},
- text: Text {
- content: "1".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()
- })
+ 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();
+ 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(),
@@ -392,38 +437,43 @@ fn file_object() {
#[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(),
+ 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,
+ 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 {
+ callout: Callout {
+ rich_text: vec![RichText::Text {
rich_text: RichTextCommon {
plain_text: "Test callout".to_string(),
href: None,
@@ -436,14 +486,17 @@ fn callout() {
underline: Some(false),
}),
},
- text: Text { content: "Test callout".to_string(), link: None },
- }
- ],
- icon: FileOrEmojiObject::Emoji {
- emoji: "💡".to_string()
+ text: Text {
+ content: "Test callout".to_string(),
+ link: None
+ },
+ }],
+ icon: FileOrEmojiObject::Emoji {
+ emoji: "💡".to_string()
+ },
+ color: TextColor::Green,
},
- color: TextColor::Green,
- },
+ }
}
- })
-} \ No newline at end of file
+ )
+}
diff --git a/src/models/text.rs b/src/models/text.rs
index 4169374..4188dbf 100644
--- a/src/models/text.rs
+++ b/src/models/text.rs
@@ -1,7 +1,7 @@
-use serde::{Deserialize, Serialize};
+use crate::models::properties::DateValue;
use crate::models::users::User;
use crate::{Database, Page};
-use crate::models::properties::DateValue;
+use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Copy, Clone)]
#[serde(rename_all = "snake_case")]
@@ -65,25 +65,25 @@ pub struct Text {
#[serde(rename_all = "snake_case")]
pub enum MentionObject {
User {
- user: User
+ user: User,
},
// TODO: need to add tests
Page {
- page: Page
+ page: Page,
},
// TODO: need to add tests
Database {
- database: Database
+ database: Database,
},
Date {
- date: DateValue
+ date: DateValue,
},
// TODO: need to add LinkPreview
// LinkPreview {
//
// },
#[serde(other)]
- Unknown
+ Unknown,
}
/// Rich text objects contain data for displaying formatted text, mentions, and equations.
@@ -104,7 +104,7 @@ pub enum RichText {
Mention {
#[serde(flatten)]
rich_text: RichTextCommon,
- mention: MentionObject
+ mention: MentionObject,
},
/// See <https://developers.notion.com/reference/rich-text#equation-objects>
Equation {