iceshrimp-161sh/packages/backend/native-utils/tests/model/repository/antenna.rs

117 lines
3.4 KiB
Rust
Raw Normal View History

2023-05-31 18:24:02 +02:00
mod int_test {
2023-06-03 05:29:48 +02:00
use native_utils::{database, model, util};
2023-06-02 14:48:12 +02:00
2023-05-27 12:52:15 +02:00
use model::{
2023-06-03 05:29:48 +02:00
entity::{antenna, antenna_note, note, user},
2023-05-27 12:52:15 +02:00
repository::Repository,
schema,
};
2023-06-02 13:08:58 +02:00
use pretty_assertions::assert_eq;
2023-06-03 05:29:48 +02:00
use sea_orm::{ActiveModelTrait, ColumnTrait, EntityTrait, IntoActiveModel, QueryFilter};
2023-05-27 11:50:07 +02:00
2023-05-27 12:52:15 +02:00
use crate::{cleanup, prepare};
2023-05-27 11:50:07 +02:00
2023-05-27 12:52:15 +02:00
#[tokio::test]
async fn can_pack() {
prepare().await;
let db = database::get_database().unwrap();
2023-05-27 11:50:07 +02:00
2023-05-27 12:52:15 +02: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 11:50:07 +02:00
2023-05-27 12:52:15 +02:00
let packed = alice_antenna
.to_owned()
.pack()
.await
.expect("Unable to pack");
2023-05-27 11:50:07 +02:00
2023-06-02 10:34:49 +02:00
let packed_by_id = antenna::Model::pack_by_id(alice_antenna.id.to_owned())
.await
.expect("Unable to pack");
2023-06-02 12:22:09 +02:00
let result = schema::Antenna {
2023-06-02 10:34:49 +02:00
id: alice_antenna.id,
created_at: alice_antenna.created_at.into(),
2023-06-03 05:29:48 +02:00
name: "Alice Antenna".to_string(),
2023-06-02 10:34:49 +02:00
keywords: vec![
vec!["foo".to_string(), "bar".to_string()],
vec!["foobar".to_string()],
2023-07-17 00:32:32 +02:00
],
2023-06-02 10:34:49 +02:00
exclude_keywords: vec![
vec!["abc".to_string()],
vec!["def".to_string(), "ghi".to_string()],
2023-07-17 00:32:32 +02:00
],
2023-06-02 12:22:09 +02:00
src: schema::AntennaSrc::All,
2023-06-02 10:34:49 +02:00
user_list_id: None,
user_group_id: None,
2023-07-17 00:32:32 +02:00
users: vec![],
instances: vec![],
2023-06-02 10:34:49 +02:00
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 11:50:07 +02:00
2023-05-27 12:52:15 +02:00
cleanup().await;
}
2023-05-27 13:02:10 +02:00
#[tokio::test]
async fn unread_note() {
2023-06-03 05:29:48 +02:00
prepare().await;
let db = database::get_database().unwrap();
let (alice, alice_antenna) = user::Entity::find()
.filter(user::Column::Username.eq("alice"))
.find_also_related(antenna::Entity)
.one(db)
.await
.unwrap()
.expect("alice not found");
let alice_antenna = alice_antenna.expect("alice's antenna not found");
let packed = alice_antenna
.to_owned()
.pack()
.await
.expect("Unable to pack");
assert_eq!(packed.has_unread_note, false);
let note_model = note::Entity::find()
.filter(note::Column::UserId.eq(alice.id))
.one(db)
.await
.unwrap()
.expect("note not found");
let antenna_note = antenna_note::Model {
id: util::id::create_id(0).unwrap(),
2023-06-03 05:29:48 +02:00
antenna_id: alice_antenna.id.to_owned(),
note_id: note_model.id.to_owned(),
read: false,
};
antenna_note
.into_active_model()
.reset_all()
.insert(db)
.await
.unwrap();
let packed = alice_antenna
.to_owned()
.pack()
.await
.expect("Unable to pack");
assert_eq!(packed.has_unread_note, true);
cleanup().await;
2023-05-27 13:02:10 +02:00
}
2023-05-27 11:50:07 +02:00
}