code refactor
Some checks failed
CI / Check / Test (push) Has been cancelled

Reviewed-on: #26
This commit was merged in pull request #26.
This commit is contained in:
2026-10-26 09:36:23 +00:00
parent 2ce7db12c2
commit 017b58d6fa
804 changed files with 33423 additions and 28955 deletions

View File

@@ -0,0 +1,40 @@
use application::jobs::{PROCESSED_EVENTS_RETENTION_DAYS, ProcessedEventsCleanupJob};
use domain::{events::EventId, ports::PeriodicJob, testing::InMemoryStore};
#[tokio::test]
async fn removes_only_rows_older_than_the_retention_window() {
let store = InMemoryStore::new();
let now = chrono::Utc::now().naive_utc();
let stale = EventId::new();
let fresh = EventId::new();
store.seed_processed_event(
&stale,
"h",
true,
now - chrono::Duration::days(PROCESSED_EVENTS_RETENTION_DAYS + 1),
);
store.seed_processed_event(
&fresh,
"h",
true,
now - chrono::Duration::days(PROCESSED_EVENTS_RETENTION_DAYS - 1),
);
ProcessedEventsCleanupJob::new(store.clone())
.run()
.await
.unwrap();
use domain::ports::{Begin, ProcessedEventLedger};
assert!(matches!(
store.begin(&stale, "h").await.unwrap(),
Begin::Run(_)
));
assert_eq!(store.begin(&fresh, "h").await.unwrap(), Begin::AlreadyDone);
}
#[test]
fn runs_daily() {
let job = ProcessedEventsCleanupJob::new(InMemoryStore::new());
assert_eq!(job.interval(), std::time::Duration::from_secs(86_400));
}

View File

@@ -0,0 +1,59 @@
use std::sync::{Arc, Mutex};
use application::jobs::{TOMBSTONE_RETENTION_DAYS, TombstoneCleanupJob};
use async_trait::async_trait;
use domain::{
errors::DomainError,
ports::{AccountPurger, PeriodicJob},
value_objects::UserId,
};
#[derive(Default)]
struct Purger {
cutoffs: Mutex<Vec<chrono::NaiveDateTime>>,
}
#[async_trait]
impl AccountPurger for Purger {
async fn is_purged(&self, _: &UserId) -> Result<bool, DomainError> {
unimplemented!()
}
async fn owned_image_keys(&self, _: &UserId) -> Result<Vec<String>, DomainError> {
unimplemented!()
}
async fn purge(&self, _: &UserId) -> Result<(), DomainError> {
unimplemented!()
}
async fn forget_images(&self, _: &UserId) -> Result<(), DomainError> {
unimplemented!()
}
async fn purge_expired_tombstones(
&self,
cutoff: chrono::NaiveDateTime,
) -> Result<u64, DomainError> {
self.cutoffs.lock().unwrap().push(cutoff);
Ok(0)
}
}
#[tokio::test]
async fn removes_tombstones_purged_before_the_retention_window() {
assert_eq!(TOMBSTONE_RETENTION_DAYS, 7);
let purger = Arc::new(Purger::default());
TombstoneCleanupJob::new(purger.clone())
.run()
.await
.unwrap();
let cutoffs = purger.cutoffs.lock().unwrap();
let expected = chrono::Utc::now().naive_utc() - chrono::Duration::days(7);
assert_eq!(cutoffs.len(), 1);
assert!((cutoffs[0] - expected).num_seconds().abs() < 5);
}
#[test]
fn runs_daily() {
let job = TombstoneCleanupJob::new(Arc::new(Purger::default()));
assert_eq!(job.interval(), std::time::Duration::from_secs(86_400));
}