Skip to content

Commit

Permalink
Added new CDN url + updated tests (#1109)
Browse files Browse the repository at this point in the history
* Added new CDN url + updated tests

* temp

* Update unit tests

* Update doc info of default prompt-screen-settings.json

* Updated comments

* Add unit tests for promptScreenRendererResourceFetcher

* Fix lint

* Fix ACUL error check message

---------

Co-authored-by: ramya18101 <[email protected]>
Co-authored-by: Ramya Anusri <[email protected]>
  • Loading branch information
3 people authored Dec 18, 2024
1 parent 8468c81 commit 15ff967
Show file tree
Hide file tree
Showing 7 changed files with 262 additions and 153 deletions.
6 changes: 3 additions & 3 deletions internal/cli/data/universal-login/prompt-screen-settings.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"__doc1__": "The rendering_mode could be either advanced or standard... default_head_tags_disabled is a toggle to override Universal Login default head tags... context_configuration are the set of Context values to make available(Refer docs for the possible values)... head_tags are the array of head tags)..",
"__doc2__": "Note1: To update the rendering_mode to standard, only parse the rendering_mode field; no other fields are needed.",
"__doc2__": "Note1: while updating the rendering_mode to standard, only the rendering_mode field gets updated, the other fields shall not be updated.",
"__doc3__": "Note2: head_tags must contain at least one script tag",
"__doc4__": "Only the declared fields will be updated, Rest stays same.",
"__doc5__": "See the docs for possible values",
"__doc4__": "Only the declared fields get updated, rest stays same",
"__doc5__": "See https://auth0.com/docs/customize/login-pages/advanced-customizations/getting-started/configure-acul-screens for all possible values for each field",

"rendering_mode": "advanced",
"default_head_tags": false,
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/prompts_custom_text.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
const (
textDocsKey = "__doc__"
textDocsURL = "https://auth0.com/docs/customize/universal-login-pages/customize-login-text-prompts"
textLocalesURL = "https://cdn.auth0.com/ulp/react-components/1.66.3/languages/%s/prompts.json"
textLocalesURL = "https://cdn.auth0.com/ulp/react-components/1.102.1/languages/%s/prompts.json"
textLanguageDefault = "en"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/cli/terraform_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ func (f *promptScreenRendererResourceFetcher) FetchData(ctx context.Context) (im
_, err := f.api.Prompt.ReadRendering(ctx, "login-id", "login-id")
// Checking for the ACUL enabled feature.
if err != nil {
if strings.Contains(err.Error(), "This tenant does not have ACUL enabled") {
if strings.Contains(err.Error(), "403 Forbidden: This tenant does not have Advanced Customizations enabled") {
return nil, nil
}

Expand Down
66 changes: 66 additions & 0 deletions internal/cli/terraform_fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,72 @@ func TestPromptProviderResourceFetcher_FetchData(t *testing.T) {
})
}

func TestPromptScreenRendererResourceFetcher_FetchData(t *testing.T) {
t.Run("it successfully renders the prompts & screen settings import data", func(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

promptAPI := mock.NewMockPromptAPI(ctrl)
promptAPI.EXPECT().ReadRendering(gomock.Any(), management.PromptType("login-id"), management.ScreenName("login-id")).
Return(&management.PromptRendering{}, nil)

fetcher := promptScreenRendererResourceFetcher{
api: &auth0.API{
Prompt: promptAPI,
},
}

expectedData := importDataList{}
for promptType, screenNames := range ScreenPromptMap {
for _, screenName := range screenNames {
expectedData = append(expectedData, importDataItem{
ResourceName: "auth0_prompt_screen_renderer." + sanitizeResourceName(promptType+"_"+screenName),
ImportID: promptType + ":" + screenName,
})
}
}

data, err := fetcher.FetchData(context.Background())
assert.NoError(t, err)
assert.ElementsMatch(t, expectedData, data)
})
t.Run("it handles error, even if tenant does not have ACUL enabled", func(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

promptAPI := mock.NewMockPromptAPI(ctrl)
promptAPI.EXPECT().ReadRendering(gomock.Any(), management.PromptType("login-id"), management.ScreenName("login-id")).
Return(&management.PromptRendering{}, fmt.Errorf("403 Forbidden: This tenant does not have Advanced Customizations enabled"))

fetcher := promptScreenRendererResourceFetcher{
api: &auth0.API{
Prompt: promptAPI,
},
}

data, err := fetcher.FetchData(context.Background())
assert.NoError(t, err)
assert.Len(t, data, 0)
})
t.Run("it returns error, if the API call fails", func(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

promptAPI := mock.NewMockPromptAPI(ctrl)
promptAPI.EXPECT().ReadRendering(gomock.Any(), management.PromptType("login-id"), management.ScreenName("login-id")).
Return(&management.PromptRendering{}, fmt.Errorf("failed to read rendering settings"))

fetcher := promptScreenRendererResourceFetcher{
api: &auth0.API{
Prompt: promptAPI,
},
}

_, err := fetcher.FetchData(context.Background())
assert.EqualError(t, err, "failed to read rendering settings")
})
}

func TestPromptCustomTextResourceFetcher_FetchData(t *testing.T) {
t.Run("it successfully retrieves custom text prompts data", func(t *testing.T) {
ctrl := gomock.NewController(t)
Expand Down
Loading

0 comments on commit 15ff967

Please sign in to comment.