Skip to content

Commit

Permalink
Add page icon
Browse files Browse the repository at this point in the history
  • Loading branch information
b3ngg committed Oct 26, 2024
1 parent a625899 commit 8b03ad9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod users;
use crate::models::properties::{PropertyConfiguration, PropertyValue};
use crate::models::text::RichText;
use crate::Error;
use block::FileOrEmojiObject;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

Expand Down Expand Up @@ -39,6 +40,7 @@ pub struct Database {
pub last_edited_time: DateTime<Utc>,
/// Name of the database as it appears in Notion.
pub title: Vec<RichText>,
pub icon: Option<FileOrEmojiObject>,
/// Schema of properties for the database as they appear in Notion.
//
// key string
Expand Down Expand Up @@ -180,6 +182,7 @@ pub struct Page {
pub last_edited_time: DateTime<Utc>,
/// The archived status of the page.
pub archived: bool,
pub icon: Option<FileOrEmojiObject>,
pub properties: Properties,
pub parent: Parent,
}
Expand Down
22 changes: 21 additions & 1 deletion tests/databases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use test_log::test;
mod common;
use common::test_client;
use rusticnotion::models::{
block::FileOrEmojiObject,
search::{
DatabaseQuery, FilterCondition, FilterProperty, FilterValue, NotionSearch,
PropertyCondition, TextCondition,
Expand Down Expand Up @@ -61,9 +62,16 @@ async fn query_database() -> Result<(), Box<dyn std::error::Error>> {
.expect("Test expected to find at least one database in notion")
.clone();

assert_eq!(
db.icon,
Some(FileOrEmojiObject::Emoji {
emoji: "🪑".to_string(),
})
);

let pages = api
.query_database(
db,
db.clone(),
DatabaseQuery {
filter: Some(FilterCondition::Property {
property: "Name".to_string(),
Expand All @@ -77,6 +85,18 @@ async fn query_database() -> Result<(), Box<dyn std::error::Error>> {
.await?;

assert_eq!(pages.results().len(), 1);
assert_eq!(
pages.results()[0].icon,
Some(FileOrEmojiObject::Emoji {
emoji: "🌋".to_string(),
})
);

let pages = api.query_database(db, DatabaseQuery::default()).await?;

for page in pages.results() {
assert!(page.icon.is_some());
}

Ok(())
}

0 comments on commit 8b03ad9

Please # to comment.