Skip to content

Commit

Permalink
Prompt User For Team Name (#1329)
Browse files Browse the repository at this point in the history
  • Loading branch information
aliotta authored Jul 31, 2023
1 parent c2bcc04 commit 8e385a1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
8 changes: 7 additions & 1 deletion cloud/team/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
astrocore "github.com/astronomer/astro-cli/astro-client-core"
"github.com/astronomer/astro-cli/cloud/user"
"github.com/astronomer/astro-cli/context"
"github.com/astronomer/astro-cli/pkg/ansi"
"github.com/astronomer/astro-cli/pkg/input"
"github.com/astronomer/astro-cli/pkg/printutil"
)
Expand All @@ -28,6 +29,7 @@ var (
ErrNoTeamsFoundInWorkspace = errors.New("no teams found in your workspace")
ErrNoTeamMembersFoundInTeam = errors.New("no team members found in team")
ErrNoUsersFoundInOrg = errors.New("no users found in your organization")
ErrNoTeamNameProvided = errors.New("you must give your Team a name")
teamPagnationLimit = 100
)

Expand All @@ -42,7 +44,11 @@ func CreateTeam(name, description, role string, out io.Writer, client astrocore.
return err
}
if name == "" {
return ErrInvalidName
fmt.Println("Please specify a name for your Team")
name = input.Text(ansi.Bold("\nTeam name: "))
if name == "" {
return ErrNoTeamNameProvided
}
}
ctx, err := context.GetCurrentContext()
if err != nil {
Expand Down
16 changes: 14 additions & 2 deletions cloud/team/team_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,18 @@ func TestCreate(t *testing.T) {
assert.Equal(t, expectedOutMessage, out.String())
})

t.Run("happy path no name passed so user types one in when prompted", func(t *testing.T) {
teamName := "Test Team Name"
expectedOutMessage := fmt.Sprintf("Astro Team %s was successfully created\n", teamName)
out := new(bytes.Buffer)
mockClient := new(astrocore_mocks.ClientWithResponsesInterface)
mockClient.On("CreateTeamWithResponse", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(&CreateTeamResponseOK, nil).Once()
defer testUtil.MockUserInput(t, teamName)()
err := CreateTeam("", *team1.Description, "ORGANIZATION_MEMBER", out, mockClient)
assert.NoError(t, err)
assert.Equal(t, expectedOutMessage, out.String())
})

t.Run("error path when CreateTeamWithResponse return network error", func(t *testing.T) {
out := new(bytes.Buffer)
mockClient := new(astrocore_mocks.ClientWithResponsesInterface)
Expand Down Expand Up @@ -1056,12 +1068,12 @@ func TestCreate(t *testing.T) {
assert.Error(t, err)
assert.Equal(t, expectedOutMessage, out.String())
})
t.Run("error path no name passed in", func(t *testing.T) {
t.Run("error path no name passed in and user doesn't type one in when prompted", func(t *testing.T) {
testUtil.InitTestConfig(testUtil.CloudPlatform)
out := new(bytes.Buffer)
mockClient := new(astrocore_mocks.ClientWithResponsesInterface)
err := CreateTeam("", *team1.Description, "ORGANIZATION_MEMBER", out, mockClient)
assert.EqualError(t, err, "no name provided for the team. Retry with a valid name")
assert.EqualError(t, err, "you must give your Team a name")
})

t.Run("error path invalid org role", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion cloud/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func SelectUser(users []astrocore.User, workspace bool) (astrocore.User, error)
Header: []string{"#", "FULLNAME", "EMAIL", "ID", roleColumn, "CREATE DATE"},
}

fmt.Println("\nPlease select the user who's role you would like to update:")
fmt.Println("\nPlease select the user:")

userMap := map[string]astrocore.User{}
for i := range users {
Expand Down

0 comments on commit 8e385a1

Please sign in to comment.