Skip to content

Commit

Permalink
DXCDT-741 Add tests for creating custom email provider
Browse files Browse the repository at this point in the history
  • Loading branch information
acwest committed Jan 10, 2025
1 parent 604c915 commit cd15c23
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 12 deletions.
10 changes: 6 additions & 4 deletions internal/cli/email_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
24 changes: 16 additions & 8 deletions test/integration/email-test-cases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions test/integration/scripts/create-custom-email-action.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions test/integration/scripts/delete-custom-email-action.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit cd15c23

Please sign in to comment.