Skip to content

fix: match Amazon multi-shipment charges by their own charge date - #120

Merged
eshaffer321 merged 1 commit into
mainfrom
fix/amazon-late-shipment-charge-date
Nov 19, 2026
Merged

eshaffer321 merged 1 commit into
mainfrom
fix/amazon-late-shipment-charge-date

Conversation

@eshaffer321

Copy link
Copy Markdown
Owner

Problem

Amazon order 112-8585165-6989818 (dated Nov 5, $492.65) was charged in two shipments: $294.46 on Nov 6 and $198.19 on Nov 11. Both posted to Monarch, but every sync logged Waiting for remaining Amazon charges to post expected=2 found=1 and left the transactions uncategorized.

The multi-charge matcher compared every charge only to the order date ±5 days. The Nov 11 charge was 6 days out. Amazon reports each charge's date, but GetFinalCharges returned only the amounts, so that date was lost.

Fix

  • amazon.Order.GetFinalChargeDates(): charge dates aligned index for index with GetFinalCharges
  • Matcher.FindMultipleMatchesWithDates: a transaction is eligible within tolerance of the order date or that charge's own date, and a known charge date is used for scoring. FindMultipleMatches delegates with no dates, so Walmart is unchanged.
  • The Amazon handler passes the charge dates through.

Testing

  • Regression tests written first and confirmed failing (the handler test failed with skip reason: payment pending):
    • TestMatcher_FindMultipleMatchesWithDates_UsesChargeDate
    • TestMatcher_FindMultipleMatchesWithDates_ZeroDateFallsBackToOrderDate
    • TestOrder_GetFinalChargeDates_AlignedWithCharges
    • TestAmazonHandler_ProcessOrder_LateShipmentChargeMatchesByChargeDate
  • go test -race ./..., golangci-lint v2.14.0, go vet, and go mod tidy are all clean
  • Dry run, then a real run for the order: it consolidated into one $492.65 transaction categorized as Home Spending

Also runs gofmt on internal/domain/matcher/multi{,_test}.go, which were already unformatted (import order and comment alignment only).

Order 112-8585165-6989818 (Nov 5) had a second shipment charged Nov 11,
6 days later. The multi-charge matcher only checked the order date ±5
days, so the order sat at "Waiting for remaining Amazon charges to post"
forever. Carry each charge's date from Amazon into the matcher and accept
transactions near either the order date or the charge date.
@codecov

codecov Bot commented Nov 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.90909% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.03%. Comparing base (248a031) to head (5a1bf46).

Files with missing lines Patch % Lines
internal/domain/matcher/multi.go 84.61% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #120      +/-   ##
==========================================
+ Coverage   66.91%   67.03%   +0.11%     
==========================================
  Files          53       53              
  Lines        7460     7480      +20     
==========================================
+ Hits         4992     5014      +22     
+ Misses       2111     2108       -3     
- Partials      357      358       +1     
Flag Coverage Δ
unittests 67.03% <90.90%> (+0.11%) ⬆️

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

Files with missing lines Coverage Δ
internal/adapters/providers/amazon/order.go 67.39% <100.00%> (+2.00%) ⬆️
internal/application/sync/handlers/amazon.go 78.72% <100.00%> (+1.41%) ⬆️
internal/domain/matcher/multi.go 93.25% <84.61%> (-1.55%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@eshaffer321
eshaffer321 merged commit fa72e4d into main Nov 19, 2026
14 checks passed
@eshaffer321
eshaffer321 deleted the fix/amazon-late-shipment-charge-date branch November 19, 2026 18:46
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