Skip to content

Commit

Permalink
add workspace id as flag to workspace team add cmd (#1381)
Browse files Browse the repository at this point in the history
* add workspace id as flag to workspace team add cmd
  • Loading branch information
aliotta authored and kushalmalani committed Sep 12, 2023
1 parent f796457 commit fb3d586
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cmd/cloud/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ func newWorkspaceTeamAddCmd(out io.Writer) *cobra.Command {
return addWorkspaceTeam(cmd, args, out)
},
}
cmd.Flags().StringVarP(&workspaceID, "workspace-id", "w", "", "The Workspace's unique identifier")
cmd.Flags().StringVarP(&addWorkspaceRole, "role", "r", "WORKSPACE_MEMBER", "The role for the "+
"new team. Possible values are WORKSPACE_MEMBER, WORKSPACE_AUTHOR, WORKSPACE_OPERATOR and WORKSPACE_OWNER ")
return cmd
Expand All @@ -421,7 +422,7 @@ func addWorkspaceTeam(cmd *cobra.Command, args []string, out io.Writer) error {
id = args[0]
}
cmd.SilenceUsage = true
return team.AddWorkspaceTeam(id, addWorkspaceRole, "", out, astroCoreClient)
return team.AddWorkspaceTeam(id, addWorkspaceRole, workspaceID, out, astroCoreClient)
}

func newWorkspaceTeamUpdateCmd(out io.Writer) *cobra.Command {
Expand Down
14 changes: 14 additions & 0 deletions cmd/cloud/workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,20 @@ func TestWorkspaceTeamAdd(t *testing.T) {
assert.NoError(t, err)
assert.Contains(t, resp, expectedOut)
})

t.Run("can add team with workspace-id flag", func(t *testing.T) {
workspaceIDFromFlag := "mock-workspace-id"
expectedOut := fmt.Sprintf("The team %s was successfully added to the workspace with the role WORKSPACE_MEMBER\n", team1.Id)
mockClient := new(astrocore_mocks.ClientWithResponsesInterface)
mockClient.On("GetTeamWithResponse", mock.Anything, mock.Anything, mock.Anything).Return(&GetTeamWithResponseOK, nil).Twice()
mockClient.On("MutateWorkspaceTeamRoleWithResponse", mock.Anything, mock.Anything, workspaceIDFromFlag, mock.Anything, mock.Anything).Return(&MutateWorkspaceTeamRoleResponseOK, nil).Once()
astroCoreClient = mockClient
cmdArgs := []string{"team", "add", team1.Id, "--role", "WORKSPACE_MEMBER", "--workspace-id", workspaceIDFromFlag}
resp, err := execWorkspaceCmd(cmdArgs...)
assert.NoError(t, err)
assert.Contains(t, resp, expectedOut)
})

t.Run("valid email with invalid role returns an error and team is not added", func(t *testing.T) {
mockClient := new(astrocore_mocks.ClientWithResponsesInterface)
mockClient.On("GetTeamWithResponse", mock.Anything, mock.Anything, mock.Anything).Return(&GetTeamWithResponseOK, nil).Twice()
Expand Down

0 comments on commit fb3d586

Please sign in to comment.