Skip to content

Commit

Permalink
APP-6821: Adding the cli command to disable the billing service (viam…
Browse files Browse the repository at this point in the history
  • Loading branch information
RoxyFarhad authored Dec 10, 2024
1 parent ba259a2 commit ebe95fe
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
13 changes: 10 additions & 3 deletions cli/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,14 +385,21 @@ var app = &cli.App{
Action: GetBillingConfigAction,
},
{
Name: "update",
Usage: "update the billing service update for an organization",
Name: "disable",
Usage: "disable the billing service for an organization",
Flags: []cli.Flag{
&cli.StringFlag{
Name: generalFlagOrgID,
Required: true,
Usage: "the org to update the billing service for",
Usage: "the org to disable the billing service for",
},
},
Action: OrganizationDisableBillingServiceAction,
},
{
Name: "update",
Usage: "update the billing service update for an organization",
Flags: []cli.Flag{
&cli.StringFlag{
Name: organizationBillingAddress,
Required: true,
Expand Down
28 changes: 28 additions & 0 deletions cli/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,34 @@ func (c *viamClient) getBillingConfig(cCtx *cli.Context, orgID string) error {
return nil
}

// OrganizationDisableBillingServiceAction corresponds to `organizations billing disable`.
func OrganizationDisableBillingServiceAction(cCtx *cli.Context) error {
client, err := newViamClient(cCtx)
if err != nil {
return err
}
orgID := cCtx.String(generalFlagOrgID)
if orgID == "" {
return errors.New("cannot disable billing service without an organization ID")
}
return client.organizationDisableBillingServiceAction(cCtx, orgID)
}

func (c *viamClient) organizationDisableBillingServiceAction(cCtx *cli.Context, orgID string) error {
if err := c.ensureLoggedIn(); err != nil {
return err
}

if _, err := c.client.DisableBillingService(cCtx.Context, &apppb.DisableBillingServiceRequest{
OrgId: orgID,
}); err != nil {
return errors.WithMessage(err, "could not disable billing service")
}

printf(cCtx.App.Writer, "Successfully disabled billing service for organization: %s", orgID)
return nil
}

// ListLocationsAction is the corresponding Action for 'locations list'.
func ListLocationsAction(c *cli.Context) error {
client, err := newViamClient(c)
Expand Down
19 changes: 19 additions & 0 deletions cli/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,25 @@ func TestGetSupportEmailAction(t *testing.T) {
test.That(t, out.messages[0], test.ShouldContainSubstring, "test-email")
}

func TestBillingServiceDisableAction(t *testing.T) {
disableBillingFunc := func(ctx context.Context, in *apppb.DisableBillingServiceRequest, opts ...grpc.CallOption) (
*apppb.DisableBillingServiceResponse, error,
) {
return &apppb.DisableBillingServiceResponse{}, nil
}

asc := &inject.AppServiceClient{
DisableBillingServiceFunc: disableBillingFunc,
}

cCtx, ac, out, errOut := setup(asc, nil, nil, nil, nil, "token")
test.That(t, ac.organizationDisableBillingServiceAction(cCtx, "test-org"), test.ShouldBeNil)
test.That(t, len(errOut.messages), test.ShouldEqual, 0)
test.That(t, len(out.messages), test.ShouldEqual, 1)

test.That(t, out.messages[0], test.ShouldContainSubstring, "Successfully disabled billing service for organization: ")
}

func TestGetBillingConfigAction(t *testing.T) {
getConfigEmailFunc := func(ctx context.Context, in *apppb.GetBillingServiceConfigRequest, opts ...grpc.CallOption) (
*apppb.GetBillingServiceConfigResponse, error,
Expand Down

0 comments on commit ebe95fe

Please sign in to comment.