Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

Commit

Permalink
client/tier: add Cancel (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmizerany committed Feb 24, 2023
1 parent 1559fe1 commit e99e82d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
42 changes: 42 additions & 0 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,48 @@ func TestAPISubscribe(t *testing.T) {
})
}

func TestCancel(t *testing.T) {
t.Parallel()

ctx := context.Background()
tc, _ := newTestClient(t)
_, err := tc.PushJSON(ctx, []byte(`{
"plans": {
"plan:test@0": {
"features": {
"feature:t": {
"tiers": [{}]
}
}
}
}
}`))
if err != nil {
t.Fatal(err)
}

checkUsage := func(org string, want []apitypes.Usage) {
t.Helper()
u, err := tc.LookupLimits(ctx, org)
if err != nil {
t.Fatal(err)
}
diff.Test(t, t.Errorf, u.Usage, want)
}

if err := tc.Subscribe(ctx, "org:test", "plan:test@0"); err != nil {
t.Fatal(err)
}
checkUsage("org:test", []apitypes.Usage{
{Feature: mpn("feature:t"), Used: 0, Limit: control.Inf},
})

if err := tc.Cancel(ctx, "org:test"); err != nil {
t.Fatal(err)
}
checkUsage("org:test", nil)
}

func TestPhaseBadOrg(t *testing.T) {
t.Parallel()

Expand Down
5 changes: 5 additions & 0 deletions client/tier/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@ func (c *Client) Subscribe(ctx context.Context, org string, featuresAndPlans ...
return err
}

// Cancel cancels the subscription for the provided org.
func (c *Client) Cancel(ctx context.Context, org string) error {
return c.Subscribe(ctx, org)
}

// Checkout creates a new checkout link for the provided org and features, if
// any; otherwise, if no features are specified, and payment setup link is
// returned instead.
Expand Down

0 comments on commit e99e82d

Please sign in to comment.