fix: corrige la dérive temporelle du pool mock
ci/woodpecker/push/woodpecker Pipeline was successful

Les timestamps du pool étaient figés au moment du chargement du module.
On calcule le drift entre l'heure de génération et l'heure courante,
et on le réapplique à chaque appel à getTransactionsForPeriod.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
syoul
2026-03-23 20:41:52 +01:00
parent 2ed51243d2
commit 3aa3933b4c
+5 -1
View File
@@ -85,11 +85,15 @@ function generateTransactions(count: number, maxAgeMs: number): Transaction[] {
return transactions.sort((a, b) => b.timestamp - a.timestamp);
}
const POOL_GENERATED_AT = Date.now();
const TRANSACTION_POOL = generateTransactions(2400, 30 * 24 * 60 * 60 * 1000);
export function getTransactionsForPeriod(periodDays: number): Transaction[] {
const drift = Date.now() - POOL_GENERATED_AT;
const cutoff = Date.now() - periodDays * 24 * 60 * 60 * 1000;
return TRANSACTION_POOL.filter((tx) => tx.timestamp >= cutoff);
return TRANSACTION_POOL
.map((tx) => ({ ...tx, timestamp: tx.timestamp + drift }))
.filter((tx) => tx.timestamp >= cutoff);
}
export function computeStats(transactions: Transaction[]) {