diff --git a/src/models/tests.rs b/src/models/tests.rs index 1f41991..6514cf2 100644 --- a/src/models/tests.rs +++ b/src/models/tests.rs @@ -1,7 +1,7 @@ -use crate::ids::UserId; +use crate::ids::{DatabaseId, PageId, UserId}; use crate::models::properties::{DateOrDateTime, DateValue}; use crate::models::text::{ - Annotations, Link, MentionObject, RichText, RichTextCommon, Text, TextColor, + Annotations, Link, MentionId, MentionObject, RichText, RichTextCommon, Text, TextColor, }; use crate::models::users::{Person, User, UserCommon}; use crate::models::{ @@ -92,6 +92,7 @@ fn rich_text_mention_user_person() { }, } }, + href: None, } ) } @@ -122,6 +123,7 @@ fn rich_text_mention_date() { time_zone: None, } }, + href: None, } ) } @@ -154,6 +156,7 @@ fn rich_text_mention_date_with_time() { time_zone: None, } }, + href: None, } ) } @@ -186,6 +189,7 @@ fn rich_text_mention_date_with_end() { time_zone: None, } }, + href: None, } ) } @@ -223,10 +227,69 @@ fn rich_text_mention_date_with_end_and_time() { time_zone: None, } }, + href: None, } ) } +#[test] +fn rich_text_mention_page() { + let rich_text_mention_page: RichText = + serde_json::from_str(include_str!("tests/rich_text_mention_page.json")).unwrap(); + assert_eq!( + rich_text_mention_page, + RichText::Mention { + rich_text: RichTextCommon { + plain_text: "Shopping List 2023-01-20 ".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::Page { + page: MentionId { + id: PageId::from_str("c81ee776-2752-4e98-aa66-c37bd4ba9b8d").unwrap() + } + }, + href: Some("https://www.notion.so/c81ee77627524e98aa66c37bd4ba9b8d".to_string()) + } + ); +} + +#[test] +fn rich_text_mention_database() { + let rich_text_mention_database: RichText = + serde_json::from_str(include_str!("tests/rich_text_mention_database.json")).unwrap(); + assert_eq!( + rich_text_mention_database, + RichText::Mention { + rich_text: RichTextCommon { + plain_text: "Shopping lists".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), + }), + }, + href: Some("https://www.notion.so/baa9d74593254088a992721dc2fa21dd".to_string()), + mention: MentionObject::Database { + database: MentionId { + id: DatabaseId::from_str("baa9d745-9325-4088-a992-721dc2fa21dd").unwrap() + } + }, + } + ); +} + #[test] fn heading_1() { let heading_1: Block = serde_json::from_str(include_str!("tests/heading_1.json")).unwrap(); diff --git a/src/models/tests/rich_text_mention_database.json b/src/models/tests/rich_text_mention_database.json new file mode 100644 index 0000000..d10e0c5 --- /dev/null +++ b/src/models/tests/rich_text_mention_database.json @@ -0,0 +1,19 @@ +{ + "type": "mention", + "mention": { + "type": "database", + "database": { + "id": "baa9d745-9325-4088-a992-721dc2fa21dd" + } + }, + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "plain_text": "Shopping lists", + "href": "https://www.notion.so/baa9d74593254088a992721dc2fa21dd" +} diff --git a/src/models/tests/rich_text_mention_page.json b/src/models/tests/rich_text_mention_page.json new file mode 100644 index 0000000..7e2a445 --- /dev/null +++ b/src/models/tests/rich_text_mention_page.json @@ -0,0 +1,19 @@ +{ + "type": "mention", + "mention": { + "type": "page", + "page": { + "id": "c81ee776-2752-4e98-aa66-c37bd4ba9b8d" + } + }, + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "plain_text": "Shopping List 2023-01-20 ", + "href": "https://www.notion.so/c81ee77627524e98aa66c37bd4ba9b8d" +} diff --git a/src/models/text.rs b/src/models/text.rs index 841e7d7..c6a2133 100644 --- a/src/models/text.rs +++ b/src/models/text.rs @@ -1,6 +1,6 @@ +use crate::ids::{DatabaseId, PageId}; use crate::models::properties::DateValue; use crate::models::users::User; -use crate::{Database, Page}; use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Copy, Clone)] @@ -61,6 +61,11 @@ pub struct Text { pub link: Option, } +#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)] +pub struct MentionId { + pub id: T, +} + /// See https://developers.notion.com/reference/rich-text#mention-objects #[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)] #[serde(tag = "type")] @@ -69,13 +74,11 @@ pub enum MentionObject { User { user: User, }, - // TODO: need to add tests Page { - page: Page, + page: MentionId, }, - // TODO: need to add tests Database { - database: Database, + database: MentionId, }, Date { date: DateValue, @@ -107,6 +110,7 @@ pub enum RichText { #[serde(flatten)] rich_text: RichTextCommon, mention: MentionObject, + href: Option, }, /// See Equation {