Skip to content

Commit

Permalink
test(api): add test cases for NotionFile
Browse files Browse the repository at this point in the history
  • Loading branch information
mindeng committed Oct 7, 2024
1 parent e9b15a3 commit 4e91dd2
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions notion-async-api/src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,42 @@ where
}
}
}

#[cfg(test)]
mod tests {
use chrono::{DateTime, FixedOffset};

use super::NotionFile;

#[test]
fn notion_file() {
let js = r#"{
"type": "file",
"file": {
"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",
"expiry_time": "2022-10-24T22:49:22.765Z"
}
}"#;
let file: NotionFile = serde_json::from_str(js).unwrap();
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";
let t: DateTime<FixedOffset> =
DateTime::parse_from_rfc3339("2022-10-24T22:49:22.765Z").unwrap();
let t = t.to_utc();
assert!(
matches!(file, NotionFile::File { file } if file.url == url && file.expiry_time == t)
);
}

#[test]
fn notion_external_file() {
let js = r#"{
"type": "external",
"external": {
"url": "https://images.unsplash.com/photo-1525310072745-f49212b5ac6d?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1065&q=80"
}
}"#;
let file: NotionFile = serde_json::from_str(js).unwrap();
let url = "https://images.unsplash.com/photo-1525310072745-f49212b5ac6d?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1065&q=80";
assert!(matches!(file, NotionFile::External { external } if external.url == url));
}
}

0 comments on commit 4e91dd2

Please sign in to comment.