feat: user tombstone and retired usernames

This commit is contained in:
2026-10-26 02:03:36 +01:00
parent bde8040cc3
commit 31f5d5f337
15 changed files with 550 additions and 56 deletions

View File

@@ -575,3 +575,56 @@ async fn deleting_a_review_while_another_remains_keeps_the_movie_and_records_one
assert_eq!(store.movie_count(), 1);
assert_eq!(store.recorded_events().len(), 1);
}
#[tokio::test]
async fn fake_mark_deleted_mirrors_the_sqlite_tombstone() {
let store = InMemoryStore::new();
let user = test_user("ghost");
let other = test_user("other");
UserRepository::save(&*store, &user).await.unwrap();
UserRepository::save(&*store, &other).await.unwrap();
RefreshSessionRepository::create(
&*store,
&RefreshSession {
id: Uuid::new_v4(),
user_id: user.id().clone(),
token: "t".into(),
expires_at: Utc::now(),
created_at: Utc::now(),
},
)
.await
.unwrap();
let event = domain::events::DomainEvent::UserDeleted {
user_id: user.id().clone(),
};
store
.mark_deleted(user.id(), std::slice::from_ref(&event))
.await
.unwrap();
assert!(store.find_by_id(user.id()).await.unwrap().is_none());
assert!(store.find_by_email(user.email()).await.unwrap().is_none());
assert!(
store
.find_by_username(user.username())
.await
.unwrap()
.is_none()
);
assert_eq!(store.list_with_stats().await.unwrap().len(), 1);
assert!(
store
.find_tombstoned_by_id(user.id())
.await
.unwrap()
.is_some()
);
assert!(store.is_username_retired(user.username()).await.unwrap());
let upper =
domain::value_objects::Username::new(user.username().value().to_uppercase()).unwrap();
assert!(store.is_username_retired(&upper).await.unwrap());
assert_eq!(store.refresh_session_count(), 0);
assert_eq!(store.recorded_events().len(), 1);
}