Skip to content

update mention to use an id-only page and database struct and added tests #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 65 additions & 2 deletions src/models/tests.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -92,6 +92,7 @@ fn rich_text_mention_user_person() {
},
}
},
href: None,
}
)
}
Expand Down Expand Up @@ -122,6 +123,7 @@ fn rich_text_mention_date() {
time_zone: None,
}
},
href: None,
}
)
}
Expand Down Expand Up @@ -154,6 +156,7 @@ fn rich_text_mention_date_with_time() {
time_zone: None,
}
},
href: None,
}
)
}
Expand Down Expand Up @@ -186,6 +189,7 @@ fn rich_text_mention_date_with_end() {
time_zone: None,
}
},
href: None,
}
)
}
Expand Down Expand Up @@ -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();
Expand Down
19 changes: 19 additions & 0 deletions src/models/tests/rich_text_mention_database.json
Original file line number Diff line number Diff line change
@@ -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"
}
19 changes: 19 additions & 0 deletions src/models/tests/rich_text_mention_page.json
Original file line number Diff line number Diff line change
@@ -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"
}
14 changes: 9 additions & 5 deletions src/models/text.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -61,6 +61,11 @@ pub struct Text {
pub link: Option<Link>,
}

#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
pub struct MentionId<T> {
pub id: T,
}

/// See https://developers.notion.com/reference/rich-text#mention-objects
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
#[serde(tag = "type")]
Expand All @@ -69,13 +74,11 @@ pub enum MentionObject {
User {
user: User,
},
// TODO: need to add tests
Page {
page: Page,
page: MentionId<PageId>,
},
// TODO: need to add tests
Database {
database: Database,
database: MentionId<DatabaseId>,
},
Date {
date: DateValue,
Expand Down Expand Up @@ -107,6 +110,7 @@ pub enum RichText {
#[serde(flatten)]
rich_text: RichTextCommon,
mention: MentionObject,
href: Option<String>,
},
/// See <https://developers.notion.com/reference/rich-text#equation-objects>
Equation {
Expand Down