Conversation
📝 WalkthroughWalkthroughThis PR introduces a suite of end-to-end tests for NWC (Nostr Wallet Connect) operations including invoice creation, payments, keysend transfers, and transaction listing. It adds websocket polyfill support to the test runtime and configures Jest to execute e2e tests serially with a single worker. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@rolznz hi! I continued working on the library's test coverage. I added tests covering the payments area. |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
jest.e2e.config.ts (1)
3-7: Centralize WebSocket polyfill in Jest setup instead of per-test imports.Running with
maxWorkers: 1is a good stability change. To reduce duplication and keep test files cleaner, loadwebsocket-polyfillonce viasetupFiles. This will remove the import statement from all 6 e2e test files.♻️ Proposed config refactor
export default { preset: 'ts-jest', testEnvironment: 'node', testMatch: ['<rootDir>/e2e/**/*.test.ts'], testPathIgnorePatterns: ['/node_modules/', '/e2e/browser'], + setupFiles: ['<rootDir>/e2e/setup-websocket.ts'], maxWorkers: 1, // Run e2e tests serially to avoid faucet rate limiting };// e2e/setup-websocket.ts import "websocket-polyfill";🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@jest.e2e.config.ts` around lines 3 - 7, Add a single global setup file to load the websocket polyfill instead of importing it in each test: create an e2e/setup-websocket.ts that does import "websocket-polyfill"; then update the Jest config (the object with keys preset, testEnvironment, testMatch, testPathIgnorePatterns, maxWorkers) to include that file in setupFiles (e.g. setupFiles: ['<rootDir>/e2e/setup-websocket.ts']), and remove the per-test websocket-polyfill imports from the e2e test files so the polyfill is centralized.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@e2e/nwc-pay-invoice-insufficient-funds.test.ts`:
- Around line 37-39: The test currently only asserts the thrown type; tighten it
by also asserting the specific insufficient-funds error code: when calling
senderClient.payInvoice({ invoice: invoiceResult.invoice }) update the assertion
to check both the error class (Nip47WalletError) and that the thrown error
contains the INSUFFICIENT_BALANCE code (e.g. await
expect(...).rejects.toMatchObject({ code: 'INSUFFICIENT_BALANCE' }) or combine
with .toBeInstanceOf(Nip47WalletError)); reference senderClient.payInvoice,
Nip47WalletError and the INSUFFICIENT_BALANCE error code in your assertion.
---
Nitpick comments:
In `@jest.e2e.config.ts`:
- Around line 3-7: Add a single global setup file to load the websocket polyfill
instead of importing it in each test: create an e2e/setup-websocket.ts that does
import "websocket-polyfill"; then update the Jest config (the object with keys
preset, testEnvironment, testMatch, testPathIgnorePatterns, maxWorkers) to
include that file in setupFiles (e.g. setupFiles:
['<rootDir>/e2e/setup-websocket.ts']), and remove the per-test
websocket-polyfill imports from the e2e test files so the polyfill is
centralized.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: cd797b9a-8d37-4702-84a0-ffd9e6cfdba2
📒 Files selected for processing (7)
e2e/nwc-faucet.test.tse2e/nwc-list-transactions-after-payment.test.tse2e/nwc-lookup-invoice.test.tse2e/nwc-pay-invoice-insufficient-funds.test.tse2e/nwc-pay-invoice.test.tse2e/nwc-pay-keysend.test.tsjest.e2e.config.ts
| await expect( | ||
| senderClient.payInvoice({ invoice: invoiceResult.invoice }), | ||
| ).rejects.toBeInstanceOf(Nip47WalletError); |
There was a problem hiding this comment.
Assert the specific insufficient-funds error code, not only the error class.
Line 37-39 currently passes for any Nip47WalletError, so it does not fully validate the intended INSUFFICIENT_BALANCE path.
🎯 Suggested assertion tightening
- await expect(
- senderClient.payInvoice({ invoice: invoiceResult.invoice }),
- ).rejects.toBeInstanceOf(Nip47WalletError);
+ await expect(
+ senderClient.payInvoice({ invoice: invoiceResult.invoice }),
+ ).rejects.toMatchObject(
+ expect.objectContaining({
+ // Use the exact field your Nip47WalletError exposes (e.g. `code` or `error.code`)
+ code: "INSUFFICIENT_BALANCE",
+ }),
+ );🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@e2e/nwc-pay-invoice-insufficient-funds.test.ts` around lines 37 - 39, The
test currently only asserts the thrown type; tighten it by also asserting the
specific insufficient-funds error code: when calling senderClient.payInvoice({
invoice: invoiceResult.invoice }) update the assertion to check both the error
class (Nip47WalletError) and that the thrown error contains the
INSUFFICIENT_BALANCE code (e.g. await expect(...).rejects.toMatchObject({ code:
'INSUFFICIENT_BALANCE' }) or combine with .toBeInstanceOf(Nip47WalletError));
reference senderClient.payInvoice, Nip47WalletError and the INSUFFICIENT_BALANCE
error code in your assertion.
Summary
pay_invoice(success path)lookup_invoiceafter paymentpay_keysend(success path)pay_invoicewith insufficient funds (negative case)list_transactionsafter successful paymente2esuite.maxWorkers: 1injest.e2e.config.tsto reduce flakiness caused by faucet rate limits.Why
INSUFFICIENT_BALANCE).Test plan
yarn jest --config=jest.e2e.config.ts e2e/nwc-pay-invoice.test.tsyarn jest --config=jest.e2e.config.ts e2e/nwc-lookup-invoice.test.tsyarn jest --config=jest.e2e.config.ts e2e/nwc-pay-keysend.test.tsyarn jest --config=jest.e2e.config.ts e2e/nwc-faucet.test.tsyarn jest --config=jest.e2e.config.ts e2e/nwc-pay-invoice-insufficient-funds.test.tsyarn jest --config=jest.e2e.config.ts e2e/nwc-list-transactions-after-payment.test.tsSummary by CodeRabbit