Skip to content

Commit

Permalink
test: add unit tests for WalletInvoiceStatusChecker
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleSamtoshi committed Oct 18, 2023
1 parent 7b4c0df commit 33f9638
Showing 1 changed file with 78 additions and 0 deletions.
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,
)
})
})
})

0 comments on commit 33f9638

Please sign in to comment.