fix(tests): use distinct usernames in notification tests

This commit is contained in:
2026-05-15 14:11:58 +02:00
parent 3f6b91c943
commit 988f5c75aa

View File

@@ -161,30 +161,17 @@ impl NotificationRepository for PgNotificationRepository {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::user::PgUserRepository; use crate::test_helpers;
use chrono::Utc; use chrono::Utc;
use domain::ports::UserWriter;
use domain::{ use domain::{
models::{notification::NotificationKind, user::User}, models::{notification::NotificationKind, user::User},
value_objects::*, value_objects::*,
}; };
async fn seed_user(pool: &sqlx::PgPool) -> User {
let repo = PgUserRepository::new(pool.clone());
let u = User::new_local(
UserId::new(),
Username::new("alice").unwrap(),
Email::new("alice@ex.com").unwrap(),
PasswordHash("h".into()),
);
repo.save(&u).await.unwrap();
u
}
#[sqlx::test(migrations = "./migrations")] #[sqlx::test(migrations = "./migrations")]
async fn save_and_list(pool: sqlx::PgPool) { async fn save_and_list(pool: sqlx::PgPool) {
let user = seed_user(&pool).await; let user = test_helpers::seed_user(&pool, "alice", "alice@ex.com").await;
let from_user = seed_user(&pool).await; let from_user = test_helpers::seed_user(&pool, "bob", "bob@ex.com").await;
let repo = PgNotificationRepository::new(pool); let repo = PgNotificationRepository::new(pool);
use domain::models::feed::PageParams; use domain::models::feed::PageParams;
let n = Notification { let n = Notification {
@@ -213,8 +200,8 @@ mod tests {
#[sqlx::test(migrations = "./migrations")] #[sqlx::test(migrations = "./migrations")]
async fn mark_all_read(pool: sqlx::PgPool) { async fn mark_all_read(pool: sqlx::PgPool) {
let user = seed_user(&pool).await; let user = test_helpers::seed_user(&pool, "alice", "alice@ex.com").await;
let from_user = seed_user(&pool).await; let from_user = test_helpers::seed_user(&pool, "bob", "bob@ex.com").await;
let repo = PgNotificationRepository::new(pool); let repo = PgNotificationRepository::new(pool);
use domain::models::feed::PageParams; use domain::models::feed::PageParams;
let n = Notification { let n = Notification {