fix: sync-wallet failing scenario test#415
Conversation
- Modify `sync-wallet.handler.js` to resolve wallet address conflicts using `EXCLUDED.user_id` and `EXCLUDED.is_primary`. - Update `sync-wallet.feature` to support different database boolean formats in assertions (`'t'`, `'true'`, or `true`). - Fix `get_one_rest.feature` to align with the standardized auth middleware 401 response structure.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughUpdated Karate expectations for an apartment 401 response and a sync-wallet upsert path. The wallet handler now writes conflict rows from incoming values, and the feature test accepts multiple truthy ChangesApartment unauthorized response
Wallet upsert behavior
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
tests/karate/features/auth/sync-wallet.feature (1)
26-37: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winMake the upsert test actually prove
is_primarychanges.Lines 28 and 32 both use
false, so this scenario still passes if the conflict branch ignoresEXCLUDED.is_primary. Seed the existing row with the opposite value and assert the stored flag after the POST.Suggested test change
- * db.execute("INSERT INTO public.user_wallets (user_id, wallet_address, chain_type, is_primary) VALUES ('tenant-456', '" + stellarAddress + "', 'STELLAR', false)") + * db.execute("INSERT INTO public.user_wallets (user_id, wallet_address, chain_type, is_primary) VALUES ('tenant-456', '" + stellarAddress + "', 'STELLAR', true)") ... * def rows = db.query("SELECT * FROM public.user_wallets WHERE wallet_address = '" + stellarAddress + "'") And match rows[0].user_id == testUid + And match rows[0].is_primary == '#? _ == "false" || _ == "f" || _ == false'🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/karate/features/auth/sync-wallet.feature` around lines 26 - 37, The sync-wallet upsert scenario is not currently verifying that the conflict path updates is_primary. In the sync-wallet feature’s “Upsert same address updates user_id and is_primary” scenario, seed the existing user_wallets row with the opposite is_primary value from the request, then assert after the POST that the stored row for stellarAddress reflects the new flag along with the updated user_id. This should be done in the same scenario using the existing db.execute, /api/auth/sync-wallet request, and db.query assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@webhook/src/routes/auth/sync-wallet.handler.js`:
- Line 14: The conflict handling in the wallet sync upsert is not updating
chain_type, so an existing wallet row can keep a stale chain classification
after being reassigned. Update the ON CONFLICT DO UPDATE branch in
sync-wallet.handler.js so the upsert in the wallet sync query also sets
chain_type alongside user_id, is_primary, and updated_at, using the same
conflict path keyed by wallet_address.
---
Outside diff comments:
In `@tests/karate/features/auth/sync-wallet.feature`:
- Around line 26-37: The sync-wallet upsert scenario is not currently verifying
that the conflict path updates is_primary. In the sync-wallet feature’s “Upsert
same address updates user_id and is_primary” scenario, seed the existing
user_wallets row with the opposite is_primary value from the request, then
assert after the POST that the stored row for stellarAddress reflects the new
flag along with the updated user_id. This should be done in the same scenario
using the existing db.execute, /api/auth/sync-wallet request, and db.query
assertions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 9b04ab33-fd5c-4fa5-8034-746400a2e4f5
📒 Files selected for processing (3)
tests/karate/features/apartments/get_one_rest.featuretests/karate/features/auth/sync-wallet.featurewebhook/src/routes/auth/sync-wallet.handler.js
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
sync-wallet.feature#402Changes
Webhook Handler: Updated the
UPSERT_WALLETquery insync-wallet.handler.jsto resolve conflicts on the unique wallet address constraint using PostgreSQL'sEXCLUDEDprefix (EXCLUDED.user_idandEXCLUDED.is_primary).Karate Test Suite:
is_primaryassertions insync-wallet.featureto robustly match database-specific boolean variations ('t','true', ortrue).get_one_rest.featureto match the standardized auth middleware 401 response layout.Summary by CodeRabbit