console: a success screen only after a refresh that found the subscription (billing-success review P2)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+43
−5
internal/console/billingchange.go+9 −5internal/console/billingchange_test.go+34 −0
Intent
diff --git a/internal/console/billingchange.go b/internal/console/billingchange.go| index 52b4ead34..0ec40836f 100644 |
| --- a/internal/console/billingchange.go |
| +++ b/internal/console/billingchange.go |
| @@ -538,8 +538,9 @@ func (s *Server) settleChangeLocked(h billingHold, ctx context.Context, acct *Ac |
| // settleSuccessLocked is settleChangeLocked for a raise or an upgrade: |
| // applied, with the refresh read, it answers done, the success screen's |
| // marker and fallback flash. Anything else (pending, declined, uncertain) |
| -// keeps its flash. So does an applied change whose refresh failed: the |
| -// page would show the plan as it was before, and the screen would name it. |
| +// keeps its flash. So does an applied change whose refresh failed or found |
| +// no subscription: the page would show the plan as it was before, and the |
| +// screen would name it. |
| func (s *Server) settleSuccessLocked(h billingHold, ctx context.Context, acct *Account, out opOutcome, now time.Time, done changeReply) changeReply { |
| reply, refreshed := s.settleRefreshLocked(h, ctx, acct, out, now) |
| if out.State == opApplied && refreshed { |
| @@ -549,14 +550,17 @@ func (s *Server) settleSuccessLocked(h billingHold, ctx context.Context, acct *A |
| } |
| // settleRefreshLocked is the refresh and outcome flash both settle |
| -// helpers share, and whether the refresh read the subscription. |
| +// helpers share, and whether the refresh read the subscription: no error |
| +// and a subscription read. A provider with no subscription is no error |
| +// (refreshLocked records it as a problem and returns no read), and it |
| +// confirms nothing. |
| func (s *Server) settleRefreshLocked(h billingHold, ctx context.Context, acct *Account, out opOutcome, now time.Time) (changeReply, bool) { |
| - _, _, err := s.refreshLocked(h, ctx, acct, now) |
| + _, sub, err := s.refreshLocked(h, ctx, acct, now) |
| if err != nil { |
| log.Printf("console: billing change %s: refresh after the change: %v", acct.Sqid, err) |
| } |
| kind, key := outcomeCopy(out) |
| - return changeFlash(kind, key), err == nil |
| + return changeFlash(kind, key), err == nil && sub != nil |
| } |
| // packsDone is the answer to a pack raise the provider applied: the packs |
diff --git a/internal/console/billingchange_test.go b/internal/console/billingchange_test.go| index 315b39981..7c45270a8 100644 |
| --- a/internal/console/billingchange_test.go |
| +++ b/internal/console/billingchange_test.go |
| @@ -1069,3 +1069,37 @@ func TestChangeSuccessScreen(t *testing.T) { |
| o.wantFlash(t, o.renewal(t, "stop"), "ok", fmt.Sprintf(billingCopy["renewal.stopped"], billingDate(periodEnd))) |
| o.wantFlash(t, o.renewal(t, "resume"), "ok", billingCopy["renewal.resumed"]) |
| } |
| + |
| +// TestChangeSuccessNeedsTheSubscription: an upgrade or a pack raise the |
| +// provider applied, whose refresh then finds no subscription (a missing |
| +// subscription is recorded as a problem, not an error), gets the generic |
| +// flash and no success marker: nothing confirmed the purchase's limits. |
| +func TestChangeSuccessNeedsTheSubscription(t *testing.T) { |
| + for _, c := range []struct { |
| + name string |
| + kv []string |
| + }{ |
| + {"packs", []string{"pack", "apps", "quantity", "3", "confirmed", "1"}}, |
| + {"upgrade", []string{"plan", "community", "confirmed", "1"}}, |
| + } { |
| + t.Run(c.name, func(t *testing.T) { |
| + o := newChangeFixture(t, map[string]int64{"apps": 1}) |
| + o.stepUp(t) |
| + reads := 0 |
| + o.fake.BeforeSubscription = func(string) error { |
| + // The change's own read succeeds; the refresh after the |
| + // send finds nothing. |
| + if reads++; reads > 1 { |
| + return billing.ErrNotFound |
| + } |
| + return nil |
| + } |
| + r := o.change(t, c.kv...) |
| + o.fake.BeforeSubscription = nil |
| + if op := o.lastOp(t); op.State != opApplied { |
| + t.Fatalf("op = %+v, want applied", op) |
| + } |
| + o.wantFlash(t, r, "ok", billingCopy["change.done"]) |
| + }) |
| + } |
| +} |