Skip to content

Commit f13fc38

Browse files
committed
fix(test): update SQL parameter positions after laddering_enabled shift
Rebasing onto main added laddering_enabled as $21 in global_config INSERT, shifting offering_class from $21 to $22. Update the pgxmock and coverage tests to reflect the new column count and binding positions.
1 parent 890656e commit f13fc38

2 files changed

Lines changed: 17 additions & 12 deletions

File tree

‎internal/config/store_postgres_coverage_test.go‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -538,15 +538,16 @@ func TestPostgresStore_GetAllPurchaseHistory_NilDB(t *testing.T) {
538538
assert.True(t, panicked, "expected panic with nil db connection")
539539
}
540540

541-
// TestSaveGlobalConfig_OfferingClassBindsAt21 is the HOLE 2 regression guard
541+
// TestSaveGlobalConfig_OfferingClassBindsAt22 is the HOLE 2 regression guard
542542
// (issue #694): the real PostgresStore.SaveGlobalConfig must bind offering_class
543-
// as the 21st positional argument ($21). The testablePostgresStore in
544-
// store_postgres_mock_test.go is a hand-maintained copy that omits the field
545-
// entirely, so no fast test guarded the placeholder count until now.
543+
// as the 22nd positional argument ($22), with laddering_enabled at $21.
544+
// The testablePostgresStore in store_postgres_mock_test.go is a hand-maintained
545+
// copy that omits the field entirely, so no fast test guarded the placeholder
546+
// count until now.
546547
//
547548
// Using pgxmock directly against the real PostgresStore (not the hand-maintained
548549
// testablePostgresStore wrapper) ensures the live query is tested, not a stale copy.
549-
func TestSaveGlobalConfig_OfferingClassBindsAt21(t *testing.T) {
550+
func TestSaveGlobalConfig_OfferingClassBindsAt22(t *testing.T) {
550551
ctx := context.Background()
551552
mock, err := pgxmock.NewPool()
552553
require.NoError(t, err)
@@ -568,8 +569,8 @@ func TestSaveGlobalConfig_OfferingClassBindsAt21(t *testing.T) {
568569
OfferingClass: "standard",
569570
}
570571

571-
// Expect exactly 21 args; pgxmock validates arg count and types.
572-
// The 21st arg must be the string "standard" (offering_class).
572+
// Expect exactly 22 args; pgxmock validates arg count and types.
573+
// The 21st arg is laddering_enabled; the 22nd arg must be "standard" (offering_class).
573574
// If the real query regresses to a different arg count, pgxmock
574575
// will return an unexpected-call error and the test will fail.
575576
mock.ExpectExec(`INSERT INTO global_config`).
@@ -594,13 +595,14 @@ func TestSaveGlobalConfig_OfferingClassBindsAt21(t *testing.T) {
594595
pgxmock.AnyArg(), // $18 recommendations_cache_stale_hours
595596
pgxmock.AnyArg(), // $19 recommendations_lookback_days
596597
pgxmock.AnyArg(), // $20 purchase_delay_hours
597-
"standard", // $21 offering_class -- the field this test guards
598+
pgxmock.AnyArg(), // $21 laddering_enabled
599+
"standard", // $22 offering_class -- the field this test guards
598600
).
599601
WillReturnResult(pgxmock.NewResult("INSERT", 1))
600602

601603
err = store.SaveGlobalConfig(ctx, cfg)
602-
require.NoError(t, err, "SaveGlobalConfig must succeed when the DB accepts all 21 args")
604+
require.NoError(t, err, "SaveGlobalConfig must succeed when the DB accepts all 22 args")
603605

604606
require.NoError(t, mock.ExpectationsWereMet(),
605-
"offering_class must be bound as the 21st argument to SaveGlobalConfig")
607+
"offering_class must be bound as the 22nd argument to SaveGlobalConfig")
606608
}

‎internal/config/store_postgres_pgxmock_test.go‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ var globalConfigCols = []string{
176176
"recommendations_cache_stale_hours", "recommendations_lookback_days",
177177
"purchase_delay_hours",
178178
"laddering_enabled",
179+
"offering_class",
179180
}
180181

181182
// TestPGXMock_UpdateGlobalConfigAtomic_LockedReadModifyWrite proves the F2
@@ -203,7 +204,8 @@ func TestPGXMock_UpdateGlobalConfigAtomic_LockedReadModifyWrite(t *testing.T) {
203204
"{}",
204205
24, 7,
205206
48,
206-
false, // laddering_enabled = false
207+
false, // laddering_enabled = false
208+
"convertible", // offering_class
207209
)
208210

209211
// Strict order: the SELECT and the UPSERT must sit between the same
@@ -212,7 +214,7 @@ func TestPGXMock_UpdateGlobalConfigAtomic_LockedReadModifyWrite(t *testing.T) {
212214
mock.ExpectExec("pg_advisory_xact_lock").WithArgs(pgxmock.AnyArg()).
213215
WillReturnResult(pgxmock.NewResult("SELECT", 1))
214216
mock.ExpectQuery("FROM global_config").WillReturnRows(seeded)
215-
mock.ExpectExec("INSERT INTO global_config").WithArgs(anyArgsCfg(21)...).
217+
mock.ExpectExec("INSERT INTO global_config").WithArgs(anyArgsCfg(22)...).
216218
WillReturnResult(pgxmock.NewResult("INSERT", 1))
217219
mock.ExpectCommit()
218220

@@ -258,6 +260,7 @@ func TestPGXMock_UpdateGlobalConfigAtomic_ApplyErrorRollsBack(t *testing.T) {
258260
24, 7,
259261
0,
260262
false,
263+
"convertible",
261264
)
262265

263266
mock.ExpectBegin()

0 commit comments

Comments
 (0)