From fc27d2f19fc7cb7431099af58ccc1890d4cba169 Mon Sep 17 00:00:00 2001 From: nicolasburtey Date: Thu, 14 Sep 2023 12:59:59 +0200 Subject: [PATCH] test: fix random date error (#3212) Co-authored-by: Nicolas Burtey --- .../services/mongoose/wallet-invoices.spec.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/legacy-integration/services/mongoose/wallet-invoices.spec.ts b/test/legacy-integration/services/mongoose/wallet-invoices.spec.ts index dd8fb8f06d..874dd46d48 100644 --- a/test/legacy-integration/services/mongoose/wallet-invoices.spec.ts +++ b/test/legacy-integration/services/mongoose/wallet-invoices.spec.ts @@ -26,7 +26,7 @@ const createTestWalletInvoice = (): WalletInvoice => { currency: WalletCurrency.Usd, amount: 10n, }, - createdAt: new Date(Date.now()), + createdAt: new Date(), } } @@ -39,7 +39,14 @@ describe("WalletInvoices", () => { const { paymentHash } = persistResult as WalletInvoice const lookedUpInvoice = await repo.findByPaymentHash(paymentHash) - expect(lookedUpInvoice).not.toBeInstanceOf(Error) + if (lookedUpInvoice instanceof Error) throw lookedUpInvoice + + const dateDifference = Math.abs( + lookedUpInvoice.createdAt.getTime() - invoiceToPersist.createdAt.getTime(), + ) + expect(dateDifference).toBeLessThanOrEqual(10) // 10ms + + lookedUpInvoice.createdAt = invoiceToPersist.createdAt = new Date() expect(lookedUpInvoice).toEqual(invoiceToPersist) })