Skip to content

Commit

Permalink
DXCDT-585: Only display undeployed actions with auth0 actions deploy (
Browse files Browse the repository at this point in the history
#916)

Adding separate undeployed actions picker

Co-authored-by: Will Vedder <[email protected]>
  • Loading branch information
willvedd and willvedd authored Nov 21, 2023
1 parent 32082b8 commit 63ccef0
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 1 deletion.
22 changes: 21 additions & 1 deletion internal/cli/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ func deployActionCmd(cli *cli) *cobra.Command {
auth0 actions deploy <action-id> --json`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
if err := actionID.Pick(cmd, &inputs.ID, cli.actionPickerOptions); err != nil {
if err := actionID.Pick(cmd, &inputs.ID, cli.undeployedActionPickerOptions); err != nil {
return err
}
} else {
Expand Down Expand Up @@ -498,6 +498,26 @@ func (c *cli) actionPickerOptions(ctx context.Context) (pickerOptions, error) {
return opts, nil
}

func (c *cli) undeployedActionPickerOptions(ctx context.Context) (pickerOptions, error) {
list, err := c.api.Action.List(ctx, management.Parameter("deployed", "false"))
if err != nil {
return nil, err
}

var opts pickerOptions
for _, r := range list.Actions {
label := fmt.Sprintf("%s %s", r.GetName(), ansi.Faint("("+r.GetID()+")"))

opts = append(opts, pickerOption{value: r.GetID(), label: label})
}

if len(opts) == 0 {
return nil, errors.New("There are currently no actions to deploy.")
}

return opts, nil
}

func (c *cli) actionEditorHint() {
c.renderer.Infof("%s Once you close the editor, the action will be saved. To cancel, press CTRL+C.", ansi.Faint("Hint:"))
}
Expand Down
79 changes: 79 additions & 0 deletions internal/cli/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,85 @@ func TestActionsPickerOptions(t *testing.T) {
}
}

func TestUndeployedActionsPickerOptions(t *testing.T) {
tests := []struct {
name string
actions []*management.Action
apiError error
assertOutput func(t testing.TB, options pickerOptions)
assertError func(t testing.TB, err error)
}{
{
name: "happy path",
actions: []*management.Action{
{
ID: auth0.String("some-id-1"),
Name: auth0.String("some-name-1"),
},
{
ID: auth0.String("some-id-2"),
Name: auth0.String("some-name-2"),
},
},
assertOutput: func(t testing.TB, options pickerOptions) {
assert.Len(t, options, 2)
assert.Equal(t, "some-name-1 (some-id-1)", options[0].label)
assert.Equal(t, "some-id-1", options[0].value)
assert.Equal(t, "some-name-2 (some-id-2)", options[1].label)
assert.Equal(t, "some-id-2", options[1].value)
},
assertError: func(t testing.TB, err error) {
t.Fail()
},
},
{
name: "no actions",
actions: []*management.Action{},
assertOutput: func(t testing.TB, options pickerOptions) {
t.Fail()
},
assertError: func(t testing.TB, err error) {
assert.ErrorContains(t, err, "There are currently no actions to deploy.")
},
},
{
name: "API error",
apiError: errors.New("error"),
assertOutput: func(t testing.TB, options pickerOptions) {
t.Fail()
},
assertError: func(t testing.TB, err error) {
assert.Error(t, err)
},
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

actionAPI := mock.NewMockActionAPI(ctrl)
actionAPI.EXPECT().
List(gomock.Any(), gomock.Any()).
Return(&management.ActionList{
Actions: test.actions}, test.apiError)

cli := &cli{
api: &auth0.API{Action: actionAPI},
}

options, err := cli.undeployedActionPickerOptions(context.Background())

if err != nil {
test.assertError(t, err)
} else {
test.assertOutput(t, options)
}
})
}
}

func TestActionsInputSecretsToActionSecrets(t *testing.T) {
t.Run("it should map input secrets to action payload", func(t *testing.T) {
input := map[string]string{
Expand Down

0 comments on commit 63ccef0

Please sign in to comment.