-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: move decline-expired-usd test to new integration format
- Loading branch information
Showing
2 changed files
with
62 additions
and
60 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
test/integration/app/wallets/update-pending-invoices.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,62 @@ | ||
import { randomUUID } from "crypto" | ||
|
||
import { handleHeldInvoices } from "@app/wallets" | ||
import * as UpdatePendingInvoicesImpl from "@app/wallets/update-pending-invoices" | ||
|
||
import { DEFAULT_EXPIRATIONS } from "@domain/bitcoin/lightning/invoice-expiration" | ||
import { WalletCurrency } from "@domain/shared" | ||
import { baseLogger } from "@services/logger" | ||
import { WalletInvoicesRepository } from "@services/mongoose" | ||
import { WalletInvoice } from "@services/mongoose/schema" | ||
import { getSecretAndPaymentHash } from "@domain/bitcoin/lightning" | ||
|
||
afterEach(async () => { | ||
await WalletInvoice.deleteMany({}) | ||
}) | ||
|
||
describe("update pending invoices", () => { | ||
describe("handleHeldInvoices", () => { | ||
it("declines USD invoice with expired 'createdAt'", async () => { | ||
// Setup mocks | ||
const declineHeldInvoiceMock = jest.fn() | ||
const declineHeldInvoiceSpy = jest | ||
.spyOn(UpdatePendingInvoicesImpl, "declineHeldInvoice") | ||
.mockImplementation(declineHeldInvoiceMock) | ||
|
||
// Setup expired USD wallet invoice | ||
const { paymentHash } = getSecretAndPaymentHash() | ||
const expiredUsdWalletInvoice = { | ||
paymentHash, | ||
secret: "secretPreImage" as SecretPreImage, | ||
selfGenerated: true, | ||
pubkey: "pubkey" as Pubkey, | ||
recipientWalletDescriptor: { | ||
id: randomUUID() as WalletId, | ||
currency: WalletCurrency.Usd, | ||
}, | ||
paid: false, | ||
} | ||
const persisted = await WalletInvoicesRepository().persistNew( | ||
expiredUsdWalletInvoice, | ||
) | ||
if (persisted instanceof Error) throw persisted | ||
|
||
const usdDelayMs = DEFAULT_EXPIRATIONS.USD.delay * 1000 | ||
const pastCreatedAt = new Date(Date.now() - usdDelayMs) | ||
await WalletInvoice.findOneAndUpdate( | ||
{ _id: paymentHash }, | ||
{ timestamp: pastCreatedAt }, | ||
) | ||
|
||
// Handle invoices | ||
await handleHeldInvoices(baseLogger) | ||
|
||
// Expect declined invoice | ||
expect(declineHeldInvoiceMock.mock.calls.length).toBe(1) | ||
expect(declineHeldInvoiceMock.mock.calls[0][0].paymentHash).toBe(paymentHash) | ||
|
||
// Restore system state | ||
declineHeldInvoiceSpy.mockRestore() | ||
}) | ||
}) | ||
}) |
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