-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add unit tests for WalletInvoiceStatusChecker
- Loading branch information
1 parent
7b4c0df
commit 33f9638
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
core/api/test/unit/domain/wallet-invoices/wallet-invoice-status-checker.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { WalletCurrency } from "@/domain/shared" | ||
import { WalletInvoiceStatus } from "@/domain/wallet-invoices" | ||
import { WalletInvoiceStatusChecker } from "@/domain/wallet-invoices/wallet-invoice-status-checker" | ||
|
||
const earlierDate = new Date("2023-10-18T20:07:44.949Z") | ||
const laterDate = new Date("2023-10-18T20:08:44.950Z") | ||
const baseInvoice: WalletInvoice = { | ||
paymentHash: "paymentHash" as PaymentHash, | ||
secret: "secretPreImage" as SecretPreImage, | ||
selfGenerated: true, | ||
pubkey: "pubkey" as Pubkey, | ||
recipientWalletDescriptor: { id: "walletId" as WalletId, currency: WalletCurrency.Usd }, | ||
paid: false, | ||
createdAt: new Date(Date.now()), | ||
lnInvoice: { | ||
destination: "destination" as Pubkey, | ||
paymentHash: "paymentHash" as PaymentHash, | ||
paymentRequest: "paymentRequest" as EncodedPaymentRequest, | ||
paymentSecret: "paymentSecret" as PaymentIdentifyingSecret, | ||
milliSatsAmount: 0 as MilliSatoshis, | ||
description: "description", | ||
routeHints: [] as Hop[][], | ||
features: [] as LnInvoiceFeature[], | ||
expiresAt: new Date(), | ||
isExpired: false, | ||
cltvDelta: null, | ||
amount: null, | ||
paymentAmount: null, | ||
}, | ||
} | ||
|
||
describe("WalletInvoiceStatusChecker", () => { | ||
describe("status", () => { | ||
it("returns paid for paid unexpired invoice", () => { | ||
const paidInvoice = { | ||
...baseInvoice, | ||
paid: true, | ||
lnInvoice: { ...baseInvoice.lnInvoice, expiresAt: laterDate }, | ||
} | ||
expect(WalletInvoiceStatusChecker(paidInvoice).status(earlierDate)).toBe( | ||
WalletInvoiceStatus.Paid, | ||
) | ||
}) | ||
|
||
it("returns paid for paid expired invoice", () => { | ||
const paidInvoice = { | ||
...baseInvoice, | ||
paid: true, | ||
lnInvoice: { ...baseInvoice.lnInvoice, expiresAt: earlierDate }, | ||
} | ||
expect(WalletInvoiceStatusChecker(paidInvoice).status(laterDate)).toBe( | ||
WalletInvoiceStatus.Paid, | ||
) | ||
}) | ||
|
||
it("returns pending for unpaid unexpired invoice", () => { | ||
const unpaidInvoice = { | ||
...baseInvoice, | ||
paid: false, | ||
lnInvoice: { ...baseInvoice.lnInvoice, expiresAt: laterDate }, | ||
} | ||
expect(WalletInvoiceStatusChecker(unpaidInvoice).status(earlierDate)).toBe( | ||
WalletInvoiceStatus.Pending, | ||
) | ||
}) | ||
|
||
it("returns expired for unpaid expired invoice", () => { | ||
const unpaidInvoice = { | ||
...baseInvoice, | ||
paid: false, | ||
lnInvoice: { ...baseInvoice.lnInvoice, expiresAt: earlierDate }, | ||
} | ||
expect(WalletInvoiceStatusChecker(unpaidInvoice).status(laterDate)).toBe( | ||
WalletInvoiceStatus.Expired, | ||
) | ||
}) | ||
}) | ||
}) |