|
| 1 | +package handlers_test |
| 2 | + |
| 3 | +// cancel_for_team_final3_test.go — FINAL serial pass #3. Covers the |
| 4 | +// PortalSubscriptionCanceler.CancelForTeam arms (team_deletion.go): |
| 5 | +// - "no subscription" (free team, no stripe_customer_id) → nil (line 84-86) |
| 6 | +// - other DB error (fault DB) → returns the error (line 88) |
| 7 | + |
| 8 | +import ( |
| 9 | + "context" |
| 10 | + "testing" |
| 11 | + |
| 12 | + "github.com/google/uuid" |
| 13 | + "github.com/stretchr/testify/assert" |
| 14 | + "github.com/stretchr/testify/require" |
| 15 | + |
| 16 | + "instant.dev/internal/config" |
| 17 | + "instant.dev/internal/handlers" |
| 18 | + "instant.dev/internal/testhelpers" |
| 19 | +) |
| 20 | + |
| 21 | +// TestCancelForTeamFinal3_NoSubscription — a real team with no subscription → |
| 22 | +// SubscriptionID returns "no subscription" → CancelForTeam swallows it (nil). |
| 23 | +func TestCancelForTeamFinal3_NoSubscription(t *testing.T) { |
| 24 | + db, clean := testhelpers.SetupTestDB(t) |
| 25 | + defer clean() |
| 26 | + teamID := uuid.MustParse(testhelpers.MustCreateTeamDB(t, db, "free")) |
| 27 | + |
| 28 | + c := &handlers.PortalSubscriptionCanceler{DB: db, Cfg: &config.Config{}} |
| 29 | + err := c.CancelForTeam(context.Background(), teamID) |
| 30 | + require.NoError(t, err, "no-subscription must be treated as success (nil)") |
| 31 | +} |
| 32 | + |
| 33 | +// TestCancelForTeamFinal3_DBError — a fault DB makes the SubscriptionID query |
| 34 | +// error with a non-"no subscription" message → CancelForTeam bubbles the error |
| 35 | +// (team_deletion.go:88). |
| 36 | +func TestCancelForTeamFinal3_DBError(t *testing.T) { |
| 37 | + faultDB := openFaultDB(t, 0) |
| 38 | + c := &handlers.PortalSubscriptionCanceler{DB: faultDB, Cfg: &config.Config{}} |
| 39 | + err := c.CancelForTeam(context.Background(), uuid.New()) |
| 40 | + assert.Error(t, err, "a non-no-subscription DB error must bubble up") |
| 41 | +} |
0 commit comments