//go:build test && dev package payments import ( "os" "testing" "crussell/db" "crussell/internal/square" "crussell/testutils/jwt" "crussell/testutils/testdb" ) func TestMain(m *testing.M) { pool := testdb.CreateTestDatabase("crussell_test_handlers_payments") db.Conn = db.NewPoolProxy(pool) jwt.Init() square.Client = square.NewDevClient() SquareClient = square.Client // Default the package to an explicit dev/mock Square env so generic payment // tests run with the 2FA gate OFF. twoFactorEnforced() is fail-closed: an // empty SQUARE_ENVIRONMENT now means ENFORCED, so a dev default must be set // explicitly. Tests that assert enforcement flip these via t.Setenv. os.Setenv("REQUIRE_2FA", "") os.Setenv("SQUARE_ENVIRONMENT", "mock") // The dev mock's CreateCheckout mirrors real Square's requirement that a // terminal checkout carries device_options.device_id (it 400s when both the // request DeviceID and this env fallback are empty). Default the terminal // device id so terminal/till/sweep tests can create checkouts; tests that // assert the rejection flip it via t.Setenv. os.Setenv("SQUARE_TERMINAL_DEVICE_ID", "dev-terminal") testdb.SeedBaseline(pool) code := m.Run() testdb.DestroyTestDatabase(pool, "crussell_test_handlers_payments") os.Exit(code) }