Covers the happy path (ordering by event_timestamp DESC/event_id ASC, Platform/ShopID fields, RawPayload round-tripping through jsonb), the empty-shop case, and the unknown-shop ErrNotFound case (via the accts.GetMockShop check GetRawShopEvents does before querying). setupAmazonMockShop creates a real account + Amazon mock shop via the same Store methods the app uses (CreateAccount, CreateMockShop) and registers cleanup in FK-safe order. GetListingCountsOverTime/GetListingCountsReport coverage is a separate, larger task (needs a listing plus count-changing history feeding a DB view) - not done here. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XEDaCB7C2NEBgyvqEtZuxY
3.0 KiB
3.0 KiB
Work Summary — 2026-08-05 22:18
Task
First half of domains/reports test coverage (agreed to split into two separate tasks): GetRawShopEvents. The other method, GetListingCountsOverTime/GetListingCountsReport, needs a deeper fixture (a listing plus count-changing history feeding a DB view) and was deliberately left for a separate pass.
Changes
New domains/reports/events_test.go:
setupAmazonMockShophelper: creates a fresh account (viatestdb.SeedOAuthUser+accounts.Store.CreateAccount, matching the pattern fromdomains/accounts/accounts_test.go) and an Amazon mock shop viaaccounts.Store.CreateMockShop, registering cleanup for every row it creates in FK-safe order (mock.shop_amazon_events/mock.raw_shop_events→mock.shop_amazon→mock.accounts→accounts;oauth_userscleanup comes fromSeedOAuthUseritself). Cleans upshop_amazon_eventstoo even though these tests don't touch the Amazon event processor, since anyraw_shop_eventsinsert forplatform='amazon'fires the same DB trigger that populates it.TestGetRawShopEvents: inserts two raw events at different timestamps, confirms both come back, in the right order (event_timestamp DESC, event_id ASC), with the rightPlatform/ShopID, and thatRawPayloadround-trips correctly through thejsonbcolumn.TestGetRawShopEvents_NoEvents: a valid shop with zero events returns an empty slice, not an error.TestGetRawShopEvents_UnknownShop: an unrecognized shop ID returnsconsts.ErrNotFound(via theaccts.GetMockShopcheckGetRawShopEventsdoes before querying events).
Verification
go build ./.../go vet ./...clean.go test ./domains/reports/... -v -race: all 3 pass.- 10x repeated runs (
-count=1 -race) with no flakes, ~1.1-1.2s each. make test: full suite green.- Confirmed zero leftover rows after the run across
accounts,mock.accounts, andmock.raw_shop_eventson the test DB. - Skipped
make test-against-dev-db: same livego run .process from the previous session was still running, and this suite inserts realmock.raw_shop_eventsrows forplatform='amazon', which fires the same trigger/NOTIFY that live process's Amazon background handler listens on. Almost certainly harmless (unique per-test IDs, no connection manipulation involved this time, unlike the insight #4 test), but no strong need to interact with a running session's live processing loop just to re-confirm what the test-DB run already showed cleanly.
Follow-ups / not done here
GetListingCountsOverTime/GetListingCountsReportcoverage remains a separate, open task - needs an account + mock shop +CreateMockListing+ something that actually generates count history (a simulated sale/refund/inventory change, or a direct insert) so thelistingCountsViewthese methods read from has real data to aggregate. That view is real per-platform logic, not just a passthrough, so this would be the first test exercising it directly rather than just the Go code around it.