add integration test of antenna

This commit is contained in:
Namekuji 2023-06-02 23:29:48 -04:00
parent 874b0a2c69
commit d3d30bbbc2
No known key found for this signature in database
GPG Key ID: B541BD6E646CABC7
2 changed files with 61 additions and 6 deletions

View File

@ -164,7 +164,7 @@ async fn setup_model(db: &DbConn) {
id: create_id().unwrap(), id: create_id().unwrap(),
created_at: Utc::now().into(), created_at: Utc::now().into(),
user_id: user_id.to_owned(), user_id: user_id.to_owned(),
name: "Test Antenna".to_string(), name: "Alice Antenna".to_string(),
src: AntennaSrcEnum::All, src: AntennaSrcEnum::All,
keywords: vec![ keywords: vec![
vec!["foo".to_string(), "bar".to_string()], vec!["foo".to_string(), "bar".to_string()],
@ -185,6 +185,18 @@ async fn setup_model(db: &DbConn) {
.reset_all() .reset_all()
.insert(txn) .insert(txn)
.await?; .await?;
let note_model = entity::note::Model {
id: create_id().unwrap(),
created_at: Utc::now().into(),
text: Some("Testing 123".to_string()),
user_id: user_id.to_owned(),
..Default::default()
};
note_model
.into_active_model()
.reset_all()
.insert(txn)
.await?;
Ok(()) Ok(())
}) })

View File

@ -1,13 +1,13 @@
mod int_test { mod int_test {
use native_utils::{database, model}; use native_utils::{database, model, util};
use model::{ use model::{
entity::{antenna, user}, entity::{antenna, antenna_note, note, user},
repository::Repository, repository::Repository,
schema, schema,
}; };
use pretty_assertions::assert_eq; use pretty_assertions::assert_eq;
use sea_orm::{ColumnTrait, EntityTrait, QueryFilter}; use sea_orm::{ActiveModelTrait, ColumnTrait, EntityTrait, IntoActiveModel, QueryFilter};
use crate::{cleanup, prepare}; use crate::{cleanup, prepare};
@ -39,7 +39,7 @@ mod int_test {
let result = schema::Antenna { let result = schema::Antenna {
id: alice_antenna.id, id: alice_antenna.id,
created_at: alice_antenna.created_at.into(), created_at: alice_antenna.created_at.into(),
name: "Test Antenna".to_string(), name: "Alice Antenna".to_string(),
keywords: vec![ keywords: vec![
vec!["foo".to_string(), "bar".to_string()], vec!["foo".to_string(), "bar".to_string()],
vec!["foobar".to_string()], vec!["foobar".to_string()],
@ -70,6 +70,49 @@ mod int_test {
#[tokio::test] #[tokio::test]
async fn unread_note() { async fn unread_note() {
todo!(); 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().unwrap(),
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;
} }
} }