fix: corrige la dérive temporelle du pool mock
ci/woodpecker/push/woodpecker Pipeline was successful
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:
@@ -85,11 +85,15 @@ function generateTransactions(count: number, maxAgeMs: number): Transaction[] {
|
|||||||
return transactions.sort((a, b) => b.timestamp - a.timestamp);
|
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);
|
const TRANSACTION_POOL = generateTransactions(2400, 30 * 24 * 60 * 60 * 1000);
|
||||||
|
|
||||||
export function getTransactionsForPeriod(periodDays: number): Transaction[] {
|
export function getTransactionsForPeriod(periodDays: number): Transaction[] {
|
||||||
|
const drift = Date.now() - POOL_GENERATED_AT;
|
||||||
const cutoff = Date.now() - periodDays * 24 * 60 * 60 * 1000;
|
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[]) {
|
export function computeStats(transactions: Transaction[]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user