From cd15c23af570f50d94cc03af325b7bc6979ef8ab Mon Sep 17 00:00:00 2001 From: "A. Craig West" Date: Fri, 10 Jan 2025 10:50:49 -0500 Subject: [PATCH] DXCDT-741 Add tests for creating custom email provider --- internal/cli/email_provider.go | 10 ++++---- test/integration/email-test-cases.yaml | 24 ++++++++++++------- .../scripts/create-custom-email-action.sh | 12 ++++++++++ .../scripts/delete-custom-email-action.sh | 13 ++++++++++ 4 files changed, 47 insertions(+), 12 deletions(-) create mode 100755 test/integration/scripts/create-custom-email-action.sh create mode 100755 test/integration/scripts/delete-custom-email-action.sh diff --git a/internal/cli/email_provider.go b/internal/cli/email_provider.go index 2e204292..a9aa5e82 100644 --- a/internal/cli/email_provider.go +++ b/internal/cli/email_provider.go @@ -174,6 +174,7 @@ func createEmailProviderCmd(cli *cli) *cobra.Command { if len(inputs.credentials) > 0 { return fmt.Errorf("credentials not supported for provider: %s", inputs.name) } + credentials = make(map[string]interface{}) } else { if err := emailProviderCredentials.Ask(cmd, &inputs.credentials, nil); err != nil { return err @@ -216,11 +217,11 @@ func createEmailProviderCmd(cli *cli) *cobra.Command { emailProvider.DefaultFromAddress = &inputs.defaultFromAddress } - if len(credentials) > 0 { + if credentials != nil { emailProvider.Credentials = &credentials } - if len(settings) > 0 { + if settings != nil { emailProvider.Settings = &settings } @@ -315,6 +316,7 @@ func updateEmailProviderCmd(cli *cli) *cobra.Command { if len(inputs.credentials) > 0 { return fmt.Errorf("credentials not supported for provider: %s", inputs.name) } + credentials = make(map[string]interface{}) } else { if err := emailProviderCredentials.AskU(cmd, &inputs.credentials, nil); err != nil { return err @@ -357,11 +359,11 @@ func updateEmailProviderCmd(cli *cli) *cobra.Command { emailProvider.DefaultFromAddress = &inputs.defaultFromAddress } - if len(credentials) > 0 { + if credentials != nil { emailProvider.Credentials = &credentials } - if len(settings) > 0 { + if settings != nil { emailProvider.Settings = &settings } diff --git a/test/integration/email-test-cases.yaml b/test/integration/email-test-cases.yaml index b0248b48..c5b10046 100644 --- a/test/integration/email-test-cases.yaml +++ b/test/integration/email-test-cases.yaml @@ -7,23 +7,31 @@ tests: command: auth0 email provider delete --force exit-code: 0 - 002 - create email provider: - command: auth0 email provider create --provider=mandrill --enabled=false --default-from-address='not-admin@auth0.invalid' --credentials='{"api_key":"some-api-key"}' --settings='{}' + 002 - create custom email provider action: + command: ./test/integration/scripts/create-custom-email-action.sh + exit-code: 0 + + 003 - create custom email provider: + command: auth0 email provider create --provider=custom --enabled=true --default-from-address='not-admin@auth0.invalid' exit-code: 0 - 003 - delete up email provider: + 004 - delete up email provider: command: auth0 email provider delete --force exit-code: 0 - 004 - it doesn't show the email provider: + 005 - it doesn't show the email provider: command: auth0 email provider show exit-code: 1 - 005 - create email provider: + 006 - delete custom email provider action: + command: ./test/integration/scripts/delete-custom-email-action.sh + exit-code: 0 + + 007 - create email provider: command: auth0 email provider create --provider=mandrill --enabled=false --default-from-address='not-admin@auth0.invalid' --credentials='{"api_key":"some-api-key"}' --settings='{}' exit-code: 0 - 006 - it successfully shows the email provider: + 008 - it successfully shows the email provider: command: auth0 email provider show exit-code: 0 stdout: @@ -33,11 +41,11 @@ tests: - DEFAULT FROM ADDRESS not-admin@auth0.invalid - SETTINGS {} - 007 - update and enable email provider: + 009 - update and enable email provider: command: auth0 email provider update --enabled --default-from-address='admin@auth0.invalid' exit-code: 0 - 008 - it successfully shows the email provider: + 010 - it successfully shows the email provider: command: auth0 email provider show exit-code: 0 stdout: diff --git a/test/integration/scripts/create-custom-email-action.sh b/test/integration/scripts/create-custom-email-action.sh new file mode 100755 index 00000000..01397ecc --- /dev/null +++ b/test/integration/scripts/create-custom-email-action.sh @@ -0,0 +1,12 @@ +#! /bin/bash + +FILE=./test/integration/identifiers/custom-email-action-id + +# Create the action. +action_id=$( auth0 actions create -n "integration-test-custom-email-action" -t "custom-email-provider" -c "exports.onExecuteCustomEmailProvider = async (event, api) => { return; };" --json | jq -r '.["id"]' ) + +# Deploy the action. +auth0 actions deploy "$action_id" + +mkdir -p ./test/integration/identifiers +echo "$action_id" > $FILE diff --git a/test/integration/scripts/delete-custom-email-action.sh b/test/integration/scripts/delete-custom-email-action.sh new file mode 100755 index 00000000..531a0b70 --- /dev/null +++ b/test/integration/scripts/delete-custom-email-action.sh @@ -0,0 +1,13 @@ +#! /bin/bash + +FILE=./test/integration/identifiers/custom-email-action-id +if [ -e "$FILE" ] +then + action_id=$(cat $FILE) + + # Delete the action. + auth0 actions delete "$action_id" --force + + rm "$FILE" +fi +