Skip to content

Commit

Permalink
DXCDT-416: Add tests for updating universal login branding (#692)
Browse files Browse the repository at this point in the history
* Add tests for updating universal login branding

* Handle current data not existing

* Don't set URLs if they are already set as this a PATCH request

* Wrap in quotes

Co-authored-by: Will Vedder <[email protected]>

---------

Co-authored-by: Will Vedder <[email protected]>
  • Loading branch information
ewanharris and willvedd authored Mar 30, 2023
1 parent e801635 commit bb7f5a9
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 15 deletions.
18 changes: 3 additions & 15 deletions internal/cli/universal_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func updateUniversalLoginCmd(cli *cli) *cobra.Command {
b := &management.Branding{}
isAccentColorSet := len(inputs.AccentColor) > 0
isBackgroundColorSet := len(inputs.BackgroundColor) > 0
currentHasColors := current.Colors != nil
currentHasColors := current.GetColors() != nil

if isAccentColorSet || isBackgroundColorSet || currentHasColors {
b.Colors = &management.BrandingColors{}
Expand All @@ -196,15 +196,11 @@ func updateUniversalLoginCmd(cli *cli) *cobra.Command {
}
}

if len(inputs.LogoURL) == 0 {
b.LogoURL = current.LogoURL
} else {
if len(inputs.LogoURL) != 0 {
b.LogoURL = &inputs.LogoURL
}

if len(inputs.FaviconURL) == 0 {
b.FaviconURL = current.FaviconURL
} else {
if len(inputs.FaviconURL) != 0 {
b.FaviconURL = &inputs.FaviconURL
}

Expand All @@ -213,14 +209,6 @@ func updateUniversalLoginCmd(cli *cli) *cobra.Command {
b.Font = &management.BrandingFont{URL: &inputs.CustomFontURL}
}

if b.Font != nil {
if len(inputs.CustomFontURL) == 0 {
b.Font.URL = current.Font.URL
} else {
b.Font.URL = &inputs.CustomFontURL
}
}

// Update branding
if err := ansi.Waiting(func() error {
return cli.api.Branding.Update(b)
Expand Down
3 changes: 3 additions & 0 deletions test/integration/scripts/test-cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,7 @@ for action in $( echo "${actions}" | jq -r '.[] | @base64' ); do
fi
done

# Reset universal login branding
auth0 ul update --accent "#2A2E35" --background "#FF4F40" --logo "https://example.com/logo.png" --favicon "https://example.com/favicon.png" --font https://example.com/font.woff --no-input

rm -rf test/integration/identifiers
73 changes: 73 additions & 0 deletions test/integration/universal-login-test-cases.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
config:
inherit-env: true

tests:
001 - sets default expected values:
command: auth0 ul update --accent "#2A2E35" --background "#FF4F40" --logo "https://example.com/logo.png" --favicon "https://example.com/favicon.png" --font https://example.com/font.woff --no-input
exit-code: 0

002 - it successfully shows universal login branding:
command: auth0 ul show
exit-code: 0
stdout:
contains:
- "ACCENT COLOR #2A2E35"
- "BACKGROUND COLOR #FF4F40"
- LOGO URL https://example.com/logo.png
- FAVICON URL https://example.com/favicon.png
- CUSTOM FONT URL https://example.com/font.woff

003 - it successfully shows universal login branding in json:
command: auth0 ul show --json
exit-code: 0
stdout:
json:
colors.primary: "#2A2E35"
colors.page_background: "#FF4F40"
favicon_url: "https://example.com/favicon.png"
logo_url: "https://example.com/logo.png"
font.url: "https://example.com/font.woff"

004 - it successfully updates universal login branding:
command: auth0 ul update --accent "#2A2E35" --background "#FF4F40" --logo "https://example.com/logo-updated.png" --favicon "https://example.com/favicon-updated.png" --font https://example.com/font-updated.woff
exit-code: 0
stdout:
contains:
- "ACCENT COLOR #2A2E35"
- "BACKGROUND COLOR #FF4F40"
- LOGO URL https://example.com/logo-updated.png
- FAVICON URL https://example.com/favicon-updated.png
- CUSTOM FONT URL https://example.com/font-updated.woff

005 - it successfully updates universal login branding and outputs as json:
command: auth0 ul update --accent "#FF4F40" --background "#2A2E35" --logo "https://example.com/logo-updated-json.png" --favicon "https://example.com/favicon-updated-json.png" --font https://example.com/font-updated-json.woff --json
exit-code: 0
stdout:
json:
colors.primary: "#FF4F40"
colors.page_background: "#2A2E35"
favicon_url: "https://example.com/favicon-updated-json.png"
logo_url: "https://example.com/logo-updated-json.png"
font.url: "https://example.com/font-updated-json.woff"

006 - it successfully updates universal login branding and persists previous colors:
command: auth0 ul update --logo "https://example.com/logo-updated-2.png" --favicon "https://example.com/favicon-updated-2.png" --font https://example.com/font-updated-2.woff --json
exit-code: 0
stdout:
json:
colors.primary: "#FF4F40"
colors.page_background: "#2A2E35"
favicon_url: "https://example.com/favicon-updated-2.png"
logo_url: "https://example.com/logo-updated-2.png"
font.url: "https://example.com/font-updated-2.woff"

007 - it successfully updates universal login branding and persists previous URLs:
command: auth0 ul update --accent "#2A2E35" --background "#FF4F40" --json
exit-code: 0
stdout:
json:
colors.primary: "#2A2E35"
colors.page_background: "#FF4F40"
favicon_url: "https://example.com/favicon-updated-2.png"
logo_url: "https://example.com/logo-updated-2.png"
font.url: "https://example.com/font-updated-2.woff"

0 comments on commit bb7f5a9

Please sign in to comment.