test(e2e): cover insufficient-funds bank-transfer withdrawal journey - #131
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
Co-Authored-By: sheldon.chin <sheldon.chin@cognition.ai>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
| const updatedAccountBalance = Dinero({ | ||
| amount: ctx.receiver!.balance + amount * 100, | ||
| }).toFormat(); |
There was a problem hiding this comment.
📝 Info: Receiver balance assertion relies on stale seed-time snapshot
The expected receiver balance on line 57-58 is computed as ctx.receiver!.balance + amount * 100, where ctx.receiver!.balance is captured from the seed data in beforeEach. This works correctly because no other operation in the test modifies the receiver's balance before the assertion. However, this is a fragile pattern: if the seed data or test setup ever changes such that the receiver participates in other transactions before this point, the assertion would silently produce incorrect expected values. The same pattern is used in cypress/tests/ui/new-transaction.spec.ts:188-190, so this is consistent with the codebase convention.
Was this helpful? React with 👍 or 👎 to provide feedback.
| beforeEach(function () { | ||
| cy.task("db:seed"); | ||
|
|
||
| cy.intercept("POST", "/transactions").as("createTransaction"); | ||
|
|
||
| cy.database("filter", "users").then((users: User[]) => { | ||
| ctx.sender = users[0]; | ||
| ctx.receiver = users[1]; | ||
|
|
||
| return cy.loginByXstate(ctx.sender.username); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
📝 Info: Test omits several route intercepts present in the sibling test file
The existing new-transaction.spec.ts sets up intercepts for GET /users*, GET /users/search*, GET /notifications, GET /transactions/public, GET /transactions, and PATCH /transactions/* in its beforeEach. This new test only intercepts POST /transactions. Since this test uses cy.createTransaction() (which drives the state machine directly) rather than UI-based user search, the missing intercepts don't cause failures. However, the absence of GET /checkAuth aliased as @getUserProfile means the test can't cy.wait on it after transaction creation the way new-transaction.spec.ts:57 does — which is fine since this test doesn't attempt that wait. This is a deliberate simplification, not a bug.
Was this helpful? React with 👍 or 👎 to provide feedback.
Summary
Adds a Cypress E2E spec exercising the previously-untested "insufficient funds → automatic bank-transfer withdrawal" branch in
debitPayAppBalance(backend/database.ts), which is currently marked/* istanbul ignore next */.New file
cypress/tests/ui/new-transaction-insufficient-funds.spec.tsmirrors the conventions innew-transaction.spec.ts(db:seed,createTransactionintercept,db:filter users→sender = users[0]/receiver = users[1],loginByXstate). It submits a payment larger than the sender's balance via thecy.createTransactioncustom command (driving the XState service directly to bypass form validation), using:Assertions:
new-transaction-create-another-transaction0withdrawalbank transfer created for the senderamount * 100cents (Dinero+switchUserByXstate)Note on the withdrawal assertion: seeded users already have a pre-existing
depositbank transfer, socy.database("find", "banktransfers", { userId: sender.id })returns that deposit (lodash_.find= first match) rather than the new withdrawal. The spec instead scopes the lookup to the created transaction via the@createTransactionresponse id:No backend logic or
istanbul ignoreannotations were modified — the branch is exercised as-is.Verification
yarn cypress:run --spec cypress/tests/ui/new-transaction-insufficient-funds.spec.ts→ 1/1 passingyarn cypress:run --spec cypress/tests/ui/new-transaction.spec.ts→ 10/10 passing (no regressions)yarn lintandyarn typescleanLink to Devin session: https://app.devin.ai/sessions/22155aaac3a1493399a682f15e8f7217
Requested by: @sheldonchincognition
Devin Review