Skip to content

Commit

Permalink
test: fix random date error (#3212)
Browse files Browse the repository at this point in the history
Co-authored-by: Nicolas Burtey <[email protected]>
  • Loading branch information
nicolasburtey and Nicolas Burtey authored Sep 14, 2023
1 parent 640bb28 commit fc27d2f
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const createTestWalletInvoice = (): WalletInvoice => {
currency: WalletCurrency.Usd,
amount: 10n,
},
createdAt: new Date(Date.now()),
createdAt: new Date(),
}
}

Expand All @@ -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)
})

Expand Down

0 comments on commit fc27d2f

Please sign in to comment.