Skip to content

Commit 5524479

Browse files
committed
fix(utils): self-review fixes for plan_gate
- Rename package-level test var to avoid collision risk - Add dashboard URL to project-lookup-failed fallback message - Add test for hasAccess:true edge case
1 parent 4249a97 commit 5524479

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

internal/utils/plan_gate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func SuggestUpgradeOnError(ctx context.Context, projectRef, featureKey string, s
3131

3232
orgSlug, err := GetOrgSlugFromProjectRef(ctx, projectRef)
3333
if err != nil {
34-
CmdSuggestion = "This feature may require a plan upgrade. Check your organization's billing settings in the Supabase dashboard."
34+
CmdSuggestion = fmt.Sprintf("This feature may require a plan upgrade. Manage billing: %s", Bold(GetSupabaseDashboardURL()))
3535
return
3636
}
3737

internal/utils/plan_gate_test.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/supabase/cli/internal/testing/apitest"
1111
)
1212

13-
var projectJSON = map[string]interface{}{
13+
var planGateProjectJSON = map[string]interface{}{
1414
"ref": "test-ref",
1515
"organization_slug": "my-org",
1616
"name": "test",
@@ -28,7 +28,7 @@ func TestGetOrgSlugFromProjectRef(t *testing.T) {
2828
gock.New(DefaultApiHost).
2929
Get("/v1/projects/" + ref).
3030
Reply(http.StatusOK).
31-
JSON(projectJSON)
31+
JSON(planGateProjectJSON)
3232
slug, err := GetOrgSlugFromProjectRef(context.Background(), ref)
3333
assert.NoError(t, err)
3434
assert.Equal(t, "my-org", slug)
@@ -80,7 +80,7 @@ func TestSuggestUpgradeOnError(t *testing.T) {
8080
gock.New(DefaultApiHost).
8181
Get("/v1/projects/" + ref).
8282
Reply(http.StatusOK).
83-
JSON(projectJSON)
83+
JSON(planGateProjectJSON)
8484
gock.New(DefaultApiHost).
8585
Get("/v1/organizations/my-org/entitlements").
8686
Reply(http.StatusOK).
@@ -96,7 +96,7 @@ func TestSuggestUpgradeOnError(t *testing.T) {
9696
gock.New(DefaultApiHost).
9797
Get("/v1/projects/" + ref).
9898
Reply(http.StatusOK).
99-
JSON(projectJSON)
99+
JSON(planGateProjectJSON)
100100
gock.New(DefaultApiHost).
101101
Get("/v1/organizations/my-org/entitlements").
102102
Reply(http.StatusInternalServerError)
@@ -113,9 +113,26 @@ func TestSuggestUpgradeOnError(t *testing.T) {
113113
Reply(http.StatusNotFound)
114114
SuggestUpgradeOnError(context.Background(), ref, "branching_limit", http.StatusPaymentRequired)
115115
assert.Contains(t, CmdSuggestion, "plan upgrade")
116+
assert.Contains(t, CmdSuggestion, GetSupabaseDashboardURL())
116117
assert.NotContains(t, CmdSuggestion, "/org/")
117118
})
118119

120+
t.Run("sets generic suggestion when feature has access", func(t *testing.T) {
121+
t.Cleanup(apitest.MockPlatformAPI(t))
122+
t.Cleanup(func() { CmdSuggestion = "" })
123+
gock.New(DefaultApiHost).
124+
Get("/v1/projects/" + ref).
125+
Reply(http.StatusOK).
126+
JSON(planGateProjectJSON)
127+
gock.New(DefaultApiHost).
128+
Get("/v1/organizations/my-org/entitlements").
129+
Reply(http.StatusOK).
130+
JSON(entitlementsJSON("branching_limit", true))
131+
SuggestUpgradeOnError(context.Background(), ref, "branching_limit", http.StatusPaymentRequired)
132+
assert.Contains(t, CmdSuggestion, "/org/my-org/billing")
133+
assert.Contains(t, CmdSuggestion, "may require a plan upgrade")
134+
})
135+
119136
t.Run("skips suggestion on 403 forbidden", func(t *testing.T) {
120137
CmdSuggestion = ""
121138
SuggestUpgradeOnError(context.Background(), ref, "branching_limit", http.StatusForbidden)

0 commit comments

Comments
 (0)