reports: switch test fixtures from Amazon to Etsy to fix test isolation
domains/reports' fixtures used Amazon as their example platform - same as domains/amazon's own tests. Both packages' test binaries run concurrently under go test ./... by default, both wrote to the shared mock.raw_shop_events table with platform='amazon', and the DB trigger routed those into mock.shop_amazon_events - the exact table domains/amazon's background-processing tests poll and assert on. Confirmed directly: running the two packages together, domains/amazon's TestProcessUnprocessedEvents_RetriesUnackedNotification picked up 4 events instead of 1, three of them from domains/reports' fixture shop. Switched to Etsy instead (test-only change, no production code touched). Verified the casing first since it mattered here: accounts.Etsy's Go value is "Etsy" (capital), and separately Etsy's raw_shop_events trigger checks for lowercase 'etsy' - but the view these tests actually depend on (mock.shop_etsy_listing_event_sequence) filters on 'Etsy', matching the Go constant, confirmed via pg_get_viewdef. So the fixtures work correctly and, as a side effect, never fire the lowercase-gated trigger at all - keeping mock.shop_etsy_events untouched by these tests regardless. Combined with the previous commit's goroutine-leak fix, go test ./... and make test are both reliably green as single commands again. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XEDaCB7C2NEBgyvqEtZuxY
This commit is contained in:
@@ -13,11 +13,10 @@ import (
|
||||
"ruben/inventory2/internal/testdb"
|
||||
)
|
||||
|
||||
// createAmazonListing creates a listing with the given base count in
|
||||
// shopID and registers its cleanup. Must be called after
|
||||
// setupAmazonMockShop, so cleanup order (LIFO) deletes the listing before
|
||||
// the shop it belongs to.
|
||||
func createAmazonListing(t *testing.T, acctStore *accounts.Store, acctID int64, shopID string, baseCount int64) (listingID string) {
|
||||
// createEtsyListing creates a listing with the given base count in shopID
|
||||
// and registers its cleanup. Must be called after setupEtsyMockShop, so
|
||||
// cleanup order (LIFO) deletes the listing before the shop it belongs to.
|
||||
func createEtsyListing(t *testing.T, acctStore *accounts.Store, acctID int64, shopID string, baseCount int64) (listingID string) {
|
||||
t.Helper()
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -27,7 +26,7 @@ func createAmazonListing(t *testing.T, acctStore *accounts.Store, acctID int64,
|
||||
AccountShopListingIDs: accounts.AccountShopListingIDs{
|
||||
AccountShopIDs: accounts.AccountShopIDs{
|
||||
AccountIDs: accounts.AccountIDs{AccountID: acctID},
|
||||
Platform: accounts.Amazon,
|
||||
Platform: accounts.Etsy,
|
||||
ShopID: shopID,
|
||||
},
|
||||
},
|
||||
@@ -40,7 +39,7 @@ func createAmazonListing(t *testing.T, acctStore *accounts.Store, acctID int64,
|
||||
|
||||
t.Cleanup(func() {
|
||||
pool.Exec(context.Background(), `
|
||||
DELETE FROM mock.shop_amazon_listings WHERE shop_id = $1 AND listing_id = $2
|
||||
DELETE FROM mock.shop_etsy_listings WHERE shop_id = $1 AND listing_id = $2
|
||||
`, shopID, listing.ListingID)
|
||||
})
|
||||
|
||||
@@ -48,8 +47,8 @@ func createAmazonListing(t *testing.T, acctStore *accounts.Store, acctID int64,
|
||||
}
|
||||
|
||||
// TestGetListingCountsOverTime exercises the actual running-count logic,
|
||||
// which lives in a recursive SQL view (mock.shop_amazon_listing_counts,
|
||||
// built on mock.shop_amazon_listing_event_sequence) rather than in Go: it
|
||||
// which lives in a recursive SQL view (mock.shop_etsy_listing_counts,
|
||||
// built on mock.shop_etsy_listing_event_sequence) rather than in Go: it
|
||||
// starts from the listing's base count and walks mock.raw_shop_events in
|
||||
// order, applying each as a delta (sale/refund) or an absolute reset
|
||||
// (inventory-reset). Uses the real SaveNewMock* methods to write those
|
||||
@@ -61,17 +60,17 @@ func TestGetListingCountsOverTime(t *testing.T) {
|
||||
reportsStore := reports.NewStore(testdb.Logger(), pool, acctStore)
|
||||
ctx := context.Background()
|
||||
|
||||
acctID, shopID := setupAmazonMockShop(t, pool, acctStore)
|
||||
listingID := createAmazonListing(t, acctStore, acctID, shopID, 100)
|
||||
acctID, shopID := setupEtsyMockShop(t, pool, acctStore)
|
||||
listingID := createEtsyListing(t, acctStore, acctID, shopID, 100)
|
||||
|
||||
_, err := acctStore.SaveNewMockSale(ctx, acctID, accounts.Amazon, shopID, listingID, 10)
|
||||
_, err := acctStore.SaveNewMockSale(ctx, acctID, accounts.Etsy, shopID, listingID, 10)
|
||||
require.NoError(t, err, "SaveNewMockSale()")
|
||||
_, err = acctStore.SaveNewMockRefund(ctx, acctID, accounts.Amazon, shopID, listingID, 5)
|
||||
_, err = acctStore.SaveNewMockRefund(ctx, acctID, accounts.Etsy, shopID, listingID, 5)
|
||||
require.NoError(t, err, "SaveNewMockRefund()")
|
||||
_, err = acctStore.SaveNewMockInventoryReset(ctx, acctID, accounts.Amazon, shopID, listingID, 50)
|
||||
_, err = acctStore.SaveNewMockInventoryReset(ctx, acctID, accounts.Etsy, shopID, listingID, 50)
|
||||
require.NoError(t, err, "SaveNewMockInventoryReset()")
|
||||
|
||||
got, err := reportsStore.GetListingCountsOverTime(ctx, acctID, accounts.Amazon, shopID, listingID)
|
||||
got, err := reportsStore.GetListingCountsOverTime(ctx, acctID, accounts.Etsy, shopID, listingID)
|
||||
require.NoError(t, err, "GetListingCountsOverTime()")
|
||||
|
||||
wantCounts := []int64{100, 110, 105, 50}
|
||||
@@ -95,9 +94,9 @@ func TestGetListingCountsOverTime_UnknownListing(t *testing.T) {
|
||||
reportsStore := reports.NewStore(testdb.Logger(), pool, acctStore)
|
||||
ctx := context.Background()
|
||||
|
||||
acctID, shopID := setupAmazonMockShop(t, pool, acctStore)
|
||||
acctID, shopID := setupEtsyMockShop(t, pool, acctStore)
|
||||
|
||||
_, err := reportsStore.GetListingCountsOverTime(ctx, acctID, accounts.Amazon, shopID, "no-such-listing")
|
||||
_, err := reportsStore.GetListingCountsOverTime(ctx, acctID, accounts.Etsy, shopID, "no-such-listing")
|
||||
require.ErrorIs(t, err, consts.ErrNotFound, "GetListingCountsOverTime()")
|
||||
}
|
||||
|
||||
@@ -107,19 +106,19 @@ func TestGetListingCountsReport(t *testing.T) {
|
||||
reportsStore := reports.NewStore(testdb.Logger(), pool, acctStore)
|
||||
ctx := context.Background()
|
||||
|
||||
acctID, shopID := setupAmazonMockShop(t, pool, acctStore)
|
||||
listingID := createAmazonListing(t, acctStore, acctID, shopID, 100)
|
||||
acctID, shopID := setupEtsyMockShop(t, pool, acctStore)
|
||||
listingID := createEtsyListing(t, acctStore, acctID, shopID, 100)
|
||||
|
||||
_, err := acctStore.SaveNewMockSale(ctx, acctID, accounts.Amazon, shopID, listingID, 10)
|
||||
_, err := acctStore.SaveNewMockSale(ctx, acctID, accounts.Etsy, shopID, listingID, 10)
|
||||
require.NoError(t, err, "SaveNewMockSale()")
|
||||
_, err = acctStore.SaveNewMockInventoryReset(ctx, acctID, accounts.Amazon, shopID, listingID, 20)
|
||||
_, err = acctStore.SaveNewMockInventoryReset(ctx, acctID, accounts.Etsy, shopID, listingID, 20)
|
||||
require.NoError(t, err, "SaveNewMockInventoryReset()")
|
||||
|
||||
report, err := reportsStore.GetListingCountsReport(ctx, acctID, accounts.Amazon, shopID, listingID)
|
||||
report, err := reportsStore.GetListingCountsReport(ctx, acctID, accounts.Etsy, shopID, listingID)
|
||||
require.NoError(t, err, "GetListingCountsReport()")
|
||||
|
||||
assert.Equal(t, acctID, report.AccountID, "report.AccountID")
|
||||
assert.Equal(t, accounts.Amazon, report.Platform, "report.Platform")
|
||||
assert.Equal(t, accounts.Etsy, report.Platform, "report.Platform")
|
||||
assert.Equal(t, shopID, report.ShopID, "report.ShopID")
|
||||
assert.Equal(t, listingID, report.ListingID, "report.ListingID")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user