2023-06-01 01:24:02 +09:00
|
|
|
mod int_test {
|
2023-06-02 21:48:12 +09:00
|
|
|
use native_utils::{database, model};
|
|
|
|
|
2023-05-27 19:52:15 +09:00
|
|
|
use model::{
|
|
|
|
entity::{antenna, user},
|
|
|
|
repository::Repository,
|
|
|
|
schema,
|
|
|
|
};
|
2023-06-02 20:08:58 +09:00
|
|
|
use pretty_assertions::assert_eq;
|
2023-05-27 19:52:15 +09:00
|
|
|
use sea_orm::{ColumnTrait, EntityTrait, QueryFilter};
|
2023-05-27 18:50:07 +09:00
|
|
|
|
2023-05-27 19:52:15 +09:00
|
|
|
use crate::{cleanup, prepare};
|
2023-05-27 18:50:07 +09:00
|
|
|
|
2023-05-27 19:52:15 +09:00
|
|
|
#[tokio::test]
|
|
|
|
async fn can_pack() {
|
|
|
|
prepare().await;
|
|
|
|
let db = database::get_database().unwrap();
|
2023-05-27 18:50:07 +09:00
|
|
|
|
2023-05-27 19:52:15 +09:00
|
|
|
let alice_antenna = user::Entity::find()
|
|
|
|
.filter(user::Column::Username.eq("alice"))
|
|
|
|
.find_also_related(antenna::Entity)
|
|
|
|
.one(db)
|
|
|
|
.await
|
|
|
|
.unwrap()
|
|
|
|
.expect("alice not found")
|
|
|
|
.1
|
|
|
|
.expect("alice's antenna not found");
|
2023-05-27 18:50:07 +09:00
|
|
|
|
2023-05-27 19:52:15 +09:00
|
|
|
let packed = alice_antenna
|
|
|
|
.to_owned()
|
|
|
|
.pack()
|
|
|
|
.await
|
|
|
|
.expect("Unable to pack");
|
2023-05-27 18:50:07 +09:00
|
|
|
|
2023-06-02 17:34:49 +09:00
|
|
|
let packed_by_id = antenna::Model::pack_by_id(alice_antenna.id.to_owned())
|
|
|
|
.await
|
|
|
|
.expect("Unable to pack");
|
|
|
|
|
2023-06-02 19:22:09 +09:00
|
|
|
let result = schema::Antenna {
|
2023-06-02 17:34:49 +09:00
|
|
|
id: alice_antenna.id,
|
|
|
|
created_at: alice_antenna.created_at.into(),
|
|
|
|
name: "Test Antenna".to_string(),
|
|
|
|
keywords: vec![
|
|
|
|
vec!["foo".to_string(), "bar".to_string()],
|
|
|
|
vec!["foobar".to_string()],
|
|
|
|
]
|
|
|
|
.into(),
|
|
|
|
exclude_keywords: vec![
|
|
|
|
vec!["abc".to_string()],
|
|
|
|
vec!["def".to_string(), "ghi".to_string()],
|
|
|
|
]
|
|
|
|
.into(),
|
2023-06-02 19:22:09 +09:00
|
|
|
src: schema::AntennaSrc::All,
|
2023-06-02 17:34:49 +09:00
|
|
|
user_list_id: None,
|
|
|
|
user_group_id: None,
|
|
|
|
users: vec![].into(),
|
|
|
|
instances: vec![].into(),
|
|
|
|
case_sensitive: true,
|
|
|
|
notify: true,
|
|
|
|
with_replies: false,
|
|
|
|
with_file: false,
|
|
|
|
has_unread_note: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
assert_eq!(packed, result);
|
|
|
|
assert_eq!(packed_by_id, result);
|
2023-05-27 18:50:07 +09:00
|
|
|
|
2023-05-27 19:52:15 +09:00
|
|
|
cleanup().await;
|
|
|
|
}
|
2023-05-27 20:02:10 +09:00
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn unread_note() {
|
|
|
|
todo!();
|
|
|
|
}
|
2023-05-27 18:50:07 +09:00
|
|
|
}
|