Skip to content

fix: Use correct GraphQL field names in UpdateTransaction mutation#14

Merged
eshaffer321 merged 1 commit intomainfrom
fix/transaction-update-field-names
Oct 17, 2025
Merged

fix: Use correct GraphQL field names in UpdateTransaction mutation#14
eshaffer321 merged 1 commit intomainfrom
fix/transaction-update-field-names

Conversation

@eshaffer321
Copy link
Copy Markdown
Owner

Problem

The Update() method was using incorrect GraphQL field names when updating transactions:

  • ❌ Used "categoryId" instead of "category"
  • ❌ Used "merchant" instead of "name"

This caused Monarch's API to reject requests with BAD_REQUEST errors, breaking single-category transaction updates since the October 2024 refactoring.

Solution

Fixed using TDD Red-Green-Refactor:

🔴 RED Phase

  • Added TestTransactionService_Update_CorrectFieldNames that verifies correct field names
  • Test failed as expected, confirming the bug

🟢 GREEN Phase

  • Fixed transactions.go lines 155, 158 to use correct field names:
    • "categoryId""category"
    • "merchant""name"
  • Test now passes

🔵 REFACTOR Phase

  • Verified all 39 tests pass with no regressions
  • Integration tested with real Walmart order - now succeeds

Reference

Field names verified against the Python monarchmoney library (lines 2574-2575), which is the reference implementation.

Verification

  • New test prevents regression
  • All tests pass (39/39)
  • Integration tested with real order
  • Production verified: Order 200013901907426 status changed from failed to success

Files Changed

  • pkg/monarch/transactions.go: Fixed field names (2 lines)
  • pkg/monarch/transactions_test.go: Added comprehensive test (113 lines)

Impact

Fixes critical bug in single-category transaction updates that has been broken in production.

PROBLEM:
The Update() method was sending incorrect field names to Monarch's API:
- Used "categoryId" instead of "category"
- Used "merchant" instead of "name"

This caused Monarch to reject requests with BAD_REQUEST errors, breaking
single-category transaction updates since the October 2024 refactoring.

SOLUTION (TDD Red-Green-Refactor):
1. RED: Added TestTransactionService_Update_CorrectFieldNames that verifies
   the correct field names are used, matching the Python reference implementation
2. GREEN: Fixed transactions.go lines 155, 158 to use correct field names
3. REFACTOR: Verified all 39 tests pass with no regressions

VERIFICATION:
- Test-driven: New test prevents regression
- Reference: Matches Python SDK field names (monarchmoney library)
- Integration: Tested with real Walmart order, now succeeds
- Database: Order 200013901907426 status changed from failed to success

Changes:
- pkg/monarch/transactions.go: Changed "categoryId" → "category", "merchant" → "name"
- pkg/monarch/transactions_test.go: Added comprehensive test case

Fixes single-category transaction update feature that has been broken in production.
@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 43.18%. Comparing base (05a7f9f) to head (b172145).
⚠️ Report is 1 commits behind head on main.

❌ Your project status has failed because the head coverage (43.18%) is below the target coverage (70.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #14      +/-   ##
==========================================
+ Coverage   41.80%   43.18%   +1.38%     
==========================================
  Files          15       15              
  Lines        2239     2239              
==========================================
+ Hits          936      967      +31     
+ Misses       1236     1198      -38     
- Partials       67       74       +7     
Flag Coverage Δ
unittests 43.18% <100.00%> (+1.38%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
pkg/monarch/transactions.go 68.08% <100.00%> (+5.71%) ⬆️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 05a7f9f...b172145. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@eshaffer321 eshaffer321 merged commit a449bb9 into main Oct 17, 2025
12 of 13 checks passed
@eshaffer321 eshaffer321 deleted the fix/transaction-update-field-names branch October 17, 2025 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant