Skip to content

Commit

Permalink
Added test case for advanced rendering mode
Browse files Browse the repository at this point in the history
  • Loading branch information
developerkunal committed Dec 20, 2024
1 parent 59a1a17 commit 1307e1a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 45 deletions.
31 changes: 15 additions & 16 deletions management/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,30 +454,30 @@ type PromptRendering struct {

// MarshalJSON implements a custom [json.Marshaler].
func (c *PromptRendering) MarshalJSON() ([]byte, error) {

Check failure on line 456 in management/prompt.go

View workflow job for this annotation

GitHub Actions / Checks

unnecessary leading newline (whitespace)
type RenderingSubSet struct {
RenderingMode *RenderingMode `json:"rendering_mode,omitempty"`
ContextConfiguration *[]string `json:"context_configuration,omitempty"`
DefaultHeadTagsDisabled *bool `json:"default_head_tags_disabled,omitempty"`
HeadTags []interface{} `json:"head_tags,omitempty"`

if c.RenderingMode != nil && *c.RenderingMode == RenderingModeStandard {
return json.Marshal(&PromptRendering{
RenderingMode: c.RenderingMode,
ContextConfiguration: nil,
DefaultHeadTagsDisabled: nil,
HeadTags: nil,
Tenant: nil,
Prompt: nil,
Screen: nil,
})
}

return json.Marshal(&RenderingSubSet{
return json.Marshal(&PromptRendering{
RenderingMode: c.RenderingMode,
ContextConfiguration: c.ContextConfiguration,
DefaultHeadTagsDisabled: c.DefaultHeadTagsDisabled,
HeadTags: c.HeadTags,
Tenant: nil,
Prompt: nil,
Screen: nil,
})
}

func (c *PromptRendering) cleanForPatch() *PromptRendering {
if c.RenderingMode != nil && *c.RenderingMode == RenderingModeStandard {
return &PromptRendering{
RenderingMode: c.RenderingMode,
}
}
return c
}

// MarshalJSON implements a custom [json.Marshaler].
func (c *PromptPartials) MarshalJSON() ([]byte, error) {
body := map[string]PromptPartials{
Expand Down Expand Up @@ -647,6 +647,5 @@ func (m *PromptManager) ReadRendering(ctx context.Context, prompt PromptType, sc
//
// See: https://auth0.com/docs/api/management/v2/prompts/patch-rendering
func (m *PromptManager) UpdateRendering(ctx context.Context, prompt PromptType, screen ScreenName, c *PromptRendering, opts ...RequestOption) error {
c = c.cleanForPatch()
return m.management.Request(ctx, "PATCH", m.management.URI("prompts", string(prompt), "screen", string(screen), "rendering"), c, opts...)
}
52 changes: 23 additions & 29 deletions management/prompt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func TestPromptManager_UpdateRenderingWithStandardMode(t *testing.T) {

_ = givenACustomDomain(t)
_ = givenAUniversalLoginTemplate(t)
expected := givenAPromptStandardRendering(t)
expected := givenAPromptRendering(t)
expected.RenderingMode = &RenderingModeStandard
expected.ContextConfiguration = &[]string{"branding.settings", "branding.themes.default", "client.logo_uri"}
expected.DefaultHeadTagsDisabled = auth0.Bool(true)
Expand All @@ -187,6 +187,28 @@ func TestPromptManager_UpdateRenderingWithStandardMode(t *testing.T) {
assert.Equal(t, ScreenSignup, *actual.GetScreen())
}

func TestPromptManager_UpdateRenderingWithAdvancedMode(t *testing.T) {
configureHTTPTestRecordings(t)

_ = givenACustomDomain(t)
_ = givenAUniversalLoginTemplate(t)
_ = givenAPromptRendering(t)
updateData := &PromptRendering{}
updateData.RenderingMode = &RenderingModeAdvanced
updateData.ContextConfiguration = &[]string{"branding.settings", "branding.themes.default", "client.logo_uri"}
updateData.DefaultHeadTagsDisabled = auth0.Bool(true)

err := api.Prompt.UpdateRendering(context.Background(), PromptSignup, ScreenSignup, updateData)
assert.NoError(t, err)

actual, err := api.Prompt.ReadRendering(context.Background(), PromptSignup, ScreenSignup)
assert.NoError(t, err)
assert.Equal(t, updateData.GetContextConfiguration(), actual.GetContextConfiguration())
assert.Equal(t, updateData.GetDefaultHeadTagsDisabled(), actual.GetDefaultHeadTagsDisabled())
assert.Equal(t, PromptSignup, *actual.GetPrompt())
assert.Equal(t, ScreenSignup, *actual.GetScreen())
}

func TestPromptManager_GetPartialsGuardGuardError(t *testing.T) {
configureHTTPTestRecordings(t)

Expand Down Expand Up @@ -356,34 +378,6 @@ func givenAPartialPrompt(t *testing.T, prompt PromptType) *PromptScreenPartials
func givenAPromptRendering(t *testing.T) *PromptRendering {
t.Helper()

settings := &PromptRendering{
RenderingMode: &RenderingModeAdvanced,
ContextConfiguration: &[]string{"branding.settings", "branding.themes.default"},
DefaultHeadTagsDisabled: auth0.Bool(false),
HeadTags: []interface{}{
map[string]interface{}{
"tag": "script",
"content": "",
"attributes": map[string]interface{}{
"defer": true,
"src": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js",
"async": true,
"integrity": []interface{}{
"sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==",
},
},
},
},
}

err := api.Prompt.UpdateRendering(context.Background(), PromptSignup, ScreenSignup, settings)
assert.NoError(t, err)

return settings
}
func givenAPromptStandardRendering(t *testing.T) *PromptRendering {
t.Helper()

settings := &PromptRendering{
RenderingMode: &RenderingModeStandard,
ContextConfiguration: &[]string{"branding.settings", "branding.themes.default"},
Expand Down

0 comments on commit 1307e1a

Please sign in to comment.