diff --git a/cmd/cloud/workspace.go b/cmd/cloud/workspace.go index c90f9c4f6..6903470e7 100644 --- a/cmd/cloud/workspace.go +++ b/cmd/cloud/workspace.go @@ -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 @@ -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 { diff --git a/cmd/cloud/workspace_test.go b/cmd/cloud/workspace_test.go index 899e08aba..be5119701 100644 --- a/cmd/cloud/workspace_test.go +++ b/cmd/cloud/workspace_test.go @@ -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()