From d3d30bbbc246e559bc8ddd3dc2faaed53d768ff3 Mon Sep 17 00:00:00 2001 From: Namekuji Date: Fri, 2 Jun 2023 23:29:48 -0400 Subject: [PATCH] add integration test of antenna --- packages/backend/native-utils/tests/common.rs | 14 ++++- .../tests/model/repository/antenna.rs | 53 +++++++++++++++++-- 2 files changed, 61 insertions(+), 6 deletions(-) diff --git a/packages/backend/native-utils/tests/common.rs b/packages/backend/native-utils/tests/common.rs index 61dd20aac7..186e862bd5 100644 --- a/packages/backend/native-utils/tests/common.rs +++ b/packages/backend/native-utils/tests/common.rs @@ -164,7 +164,7 @@ async fn setup_model(db: &DbConn) { id: create_id().unwrap(), created_at: Utc::now().into(), user_id: user_id.to_owned(), - name: "Test Antenna".to_string(), + name: "Alice Antenna".to_string(), src: AntennaSrcEnum::All, keywords: vec![ vec!["foo".to_string(), "bar".to_string()], @@ -185,6 +185,18 @@ async fn setup_model(db: &DbConn) { .reset_all() .insert(txn) .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(()) }) diff --git a/packages/backend/native-utils/tests/model/repository/antenna.rs b/packages/backend/native-utils/tests/model/repository/antenna.rs index a370073987..3bda2ca183 100644 --- a/packages/backend/native-utils/tests/model/repository/antenna.rs +++ b/packages/backend/native-utils/tests/model/repository/antenna.rs @@ -1,13 +1,13 @@ mod int_test { - use native_utils::{database, model}; + use native_utils::{database, model, util}; use model::{ - entity::{antenna, user}, + entity::{antenna, antenna_note, note, user}, repository::Repository, schema, }; use pretty_assertions::assert_eq; - use sea_orm::{ColumnTrait, EntityTrait, QueryFilter}; + use sea_orm::{ActiveModelTrait, ColumnTrait, EntityTrait, IntoActiveModel, QueryFilter}; use crate::{cleanup, prepare}; @@ -39,7 +39,7 @@ mod int_test { let result = schema::Antenna { id: alice_antenna.id, created_at: alice_antenna.created_at.into(), - name: "Test Antenna".to_string(), + name: "Alice Antenna".to_string(), keywords: vec![ vec!["foo".to_string(), "bar".to_string()], vec!["foobar".to_string()], @@ -70,6 +70,49 @@ mod int_test { #[tokio::test] 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; } }