Skip to content

Commit 4e91dd2

Browse files
committed
test(api): add test cases for NotionFile
1 parent e9b15a3 commit 4e91dd2

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

notion-async-api/src/misc.rs

+39
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,42 @@ where
132132
}
133133
}
134134
}
135+
136+
#[cfg(test)]
137+
mod tests {
138+
use chrono::{DateTime, FixedOffset};
139+
140+
use super::NotionFile;
141+
142+
#[test]
143+
fn notion_file() {
144+
let js = r#"{
145+
"type": "file",
146+
"file": {
147+
"url": "https://s3.us-west-2.amazonaws.com/secure.notion-static.com/7b8b0713-dbd4-4962-b38b-955b6c49a573/My_test_image.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45EIPT3X45%2F20221024%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20221024T205211Z&X-Amz-Expires=3600&X-Amz-Signature=208aa971577ff05e75e68354e8a9488697288ff3fb3879c2d599433a7625bf90&X-Amz-SignedHeaders=host&x-id=GetObject",
148+
"expiry_time": "2022-10-24T22:49:22.765Z"
149+
}
150+
}"#;
151+
let file: NotionFile = serde_json::from_str(js).unwrap();
152+
let url = "https://s3.us-west-2.amazonaws.com/secure.notion-static.com/7b8b0713-dbd4-4962-b38b-955b6c49a573/My_test_image.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45EIPT3X45%2F20221024%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20221024T205211Z&X-Amz-Expires=3600&X-Amz-Signature=208aa971577ff05e75e68354e8a9488697288ff3fb3879c2d599433a7625bf90&X-Amz-SignedHeaders=host&x-id=GetObject";
153+
let t: DateTime<FixedOffset> =
154+
DateTime::parse_from_rfc3339("2022-10-24T22:49:22.765Z").unwrap();
155+
let t = t.to_utc();
156+
assert!(
157+
matches!(file, NotionFile::File { file } if file.url == url && file.expiry_time == t)
158+
);
159+
}
160+
161+
#[test]
162+
fn notion_external_file() {
163+
let js = r#"{
164+
"type": "external",
165+
"external": {
166+
"url": "https://images.unsplash.com/photo-1525310072745-f49212b5ac6d?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1065&q=80"
167+
}
168+
}"#;
169+
let file: NotionFile = serde_json::from_str(js).unwrap();
170+
let url = "https://images.unsplash.com/photo-1525310072745-f49212b5ac6d?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1065&q=80";
171+
assert!(matches!(file, NotionFile::External { external } if external.url == url));
172+
}
173+
}

0 commit comments

Comments
 (0)