From 134f218c7d3172ae3b1d1c3d74aad16c165e6192 Mon Sep 17 00:00:00 2001 From: ramya18101 Date: Fri, 20 Dec 2024 14:56:57 +0530 Subject: [PATCH] Fix unit tests & lint --- management/prompt.go | 4 +- management/prompt_test.go | 34 +++++- .../TestPromptManager_ReadRendering.yaml | 28 ++--- ...nager_UpdateRenderingWithStandardMode.yaml | 109 +++--------------- 4 files changed, 66 insertions(+), 109 deletions(-) diff --git a/management/prompt.go b/management/prompt.go index 4aa85e08..0249ab71 100644 --- a/management/prompt.go +++ b/management/prompt.go @@ -469,7 +469,7 @@ func (c *PromptRendering) MarshalJSON() ([]byte, error) { }) } -func (c *PromptRendering) CleanForPatch() *PromptRendering { +func (c *PromptRendering) cleanForPatch() *PromptRendering { if c.RenderingMode != nil && *c.RenderingMode == RenderingModeStandard { return &PromptRendering{ RenderingMode: c.RenderingMode, @@ -647,6 +647,6 @@ 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() + c = c.cleanForPatch() return m.management.Request(ctx, "PATCH", m.management.URI("prompts", string(prompt), "screen", string(screen), "rendering"), c, opts...) } diff --git a/management/prompt_test.go b/management/prompt_test.go index 97cd716c..3f7892e4 100644 --- a/management/prompt_test.go +++ b/management/prompt_test.go @@ -167,9 +167,9 @@ func TestPromptManager_UpdateRendering(t *testing.T) { func TestPromptManager_UpdateRenderingWithStandardMode(t *testing.T) { configureHTTPTestRecordings(t) - _ = givenACustomDomain(t) + // _ = givenACustomDomain(t) _ = givenAUniversalLoginTemplate(t) - expected := givenAPromptRendering(t) + expected := givenAPromptStandardRendering(t) expected.RenderingMode = &RenderingModeStandard expected.ContextConfiguration = &[]string{"branding.settings", "branding.themes.default", "client.logo_uri"} expected.DefaultHeadTagsDisabled = auth0.Bool(true) @@ -356,6 +356,34 @@ 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"}, @@ -368,7 +396,7 @@ func givenAPromptRendering(t *testing.T) *PromptRendering { "defer": true, "src": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js", "async": true, - "integrity": []string{ + "integrity": []interface{}{ "sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==", }, }, diff --git a/test/data/recordings/TestPromptManager_ReadRendering.yaml b/test/data/recordings/TestPromptManager_ReadRendering.yaml index 48881eab..7cb4ea77 100644 --- a/test/data/recordings/TestPromptManager_ReadRendering.yaml +++ b/test/data/recordings/TestPromptManager_ReadRendering.yaml @@ -6,20 +6,20 @@ interactions: proto: HTTP/1.1 proto_major: 1 proto_minor: 1 - content_length: 93 + content_length: 99 transfer_encoding: [] trailer: {} host: go-auth0-dev.eu.auth0.com remote_addr: "" request_uri: "" body: | - {"domain":"1730881029.auth.uat.auth0.com","type":"auth0_managed_certs","tls_policy":"recommended"} + {"domain":"1734684889.auth.uat.auth0.com","type":"auth0_managed_certs","tls_policy":"recommended"} form: {} headers: Content-Type: - application/json User-Agent: - - Go-Auth0/1.11.2 + - Go-Auth0/1.13.0 url: https://go-auth0-dev.eu.auth0.com/api/v2/custom-domains method: POST response: @@ -28,7 +28,7 @@ interactions: proto_minor: 0 transfer_encoding: [] trailer: {} - content_length: 328 + content_length: 169 uncompressed: false body: '{"custom_domain_id":"cd_7SgKHnrmHQNuTXEs","domain":"1730881029.auth.uat.auth0.com","primary":true,"status":"pending_verification","type":"auth0_managed_certs","verification":{"methods":[{"name":"CNAME","record":"go-auth0-dev.eu.auth0.com-cd-7sgkhnrmhqnutxes.edge.tenants.us.auth0.com","domain":"1730881029.auth.uat.auth0.com"}]},"tls_policy":"recommended"}' headers: @@ -55,7 +55,7 @@ interactions: Content-Type: - application/json User-Agent: - - Go-Auth0/1.11.2 + - Go-Auth0/1.13.0 url: https://go-auth0-dev.eu.auth0.com/api/v2/branding/templates/universal-login method: PUT response: @@ -72,7 +72,7 @@ interactions: - application/json; charset=utf-8 status: 201 Created code: 201 - duration: 2.783568542s + duration: 2.953769208s - id: 2 request: proto: HTTP/1.1 @@ -91,7 +91,7 @@ interactions: Content-Type: - application/json User-Agent: - - Go-Auth0/1.11.2 + - Go-Auth0/1.13.0 url: https://go-auth0-dev.eu.auth0.com/api/v2/prompts/signup/screen/signup/rendering method: PATCH response: @@ -108,7 +108,7 @@ interactions: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 345.701625ms + duration: 538.750459ms - id: 3 request: proto: HTTP/1.1 @@ -126,7 +126,7 @@ interactions: Content-Type: - application/json User-Agent: - - Go-Auth0/1.11.2 + - Go-Auth0/1.13.0 url: https://go-auth0-dev.eu.auth0.com/api/v2/prompts/signup/screen/signup/rendering method: GET response: @@ -143,7 +143,7 @@ interactions: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 348.5575ms + duration: 568.930541ms - id: 4 request: proto: HTTP/1.1 @@ -161,7 +161,7 @@ interactions: Content-Type: - application/json User-Agent: - - Go-Auth0/1.11.2 + - Go-Auth0/1.13.0 url: https://go-auth0-dev.eu.auth0.com/api/v2/branding/templates/universal-login method: DELETE response: @@ -178,7 +178,7 @@ interactions: - application/json; charset=utf-8 status: 204 No Content code: 204 - duration: 433.247666ms + duration: 593.201584ms - id: 5 request: proto: HTTP/1.1 @@ -196,8 +196,8 @@ interactions: Content-Type: - application/json User-Agent: - - Go-Auth0/1.11.2 - url: https://go-auth0-dev.eu.auth0.com/api/v2/custom-domains/cd_7SgKHnrmHQNuTXEs + - Go-Auth0/1.13.0 + url: https://go-auth0-dev.eu.auth0.com/api/v2/custom-domains/ method: DELETE response: proto: HTTP/2.0 diff --git a/test/data/recordings/TestPromptManager_UpdateRenderingWithStandardMode.yaml b/test/data/recordings/TestPromptManager_UpdateRenderingWithStandardMode.yaml index 8d66438a..ce115d32 100644 --- a/test/data/recordings/TestPromptManager_UpdateRenderingWithStandardMode.yaml +++ b/test/data/recordings/TestPromptManager_UpdateRenderingWithStandardMode.yaml @@ -2,42 +2,6 @@ version: 2 interactions: - id: 0 - request: - proto: HTTP/1.1 - proto_major: 1 - proto_minor: 1 - content_length: 100 - transfer_encoding: [] - trailer: {} - host: go-auth0-dev.eu.auth0.com - remote_addr: "" - request_uri: "" - body: | - {"domain":"1733383430.auth.uat.auth0.com","type":"auth0_managed_certs","tls_policy":"recommended"} - form: {} - headers: - Content-Type: - - application/json - User-Agent: - - Go-Auth0/1.12.0 - url: https://go-auth0-dev.eu.auth0.com/api/v2/custom-domains - method: POST - response: - proto: HTTP/2.0 - proto_major: 2 - proto_minor: 0 - transfer_encoding: [] - trailer: {} - content_length: 342 - uncompressed: false - body: '{"custom_domain_id":"cd_HuDxFi74SU24Wy5g","domain":"1733383430.auth.uat.auth0.com","primary":true,"status":"pending_verification","type":"auth0_managed_certs","verification":{"methods":[{"name":"CNAME","record":"go-auth0-dev.eu.auth0.com-cd-hudxfi74su24wy5g.edge.tenants.us.auth0.com","domain":"1733383430.auth.uat.auth0.com"}]},"tls_policy":"recommended"}' - headers: - Content-Type: - - application/json; charset=utf-8 - status: 201 Created - code: 201 - duration: 460.5115ms - - id: 1 request: proto: HTTP/1.1 proto_major: 1 @@ -55,7 +19,7 @@ interactions: Content-Type: - application/json User-Agent: - - Go-Auth0/1.12.0 + - Go-Auth0/1.13.0 url: https://go-auth0-dev.eu.auth0.com/api/v2/branding/templates/universal-login method: PUT response: @@ -72,26 +36,26 @@ interactions: - application/json; charset=utf-8 status: 201 Created code: 201 - duration: 2.709378583s - - id: 2 + duration: 3.363495209s + - id: 1 request: proto: HTTP/1.1 proto_major: 1 proto_minor: 1 - content_length: 408 + content_length: 30 transfer_encoding: [] trailer: {} host: go-auth0-dev.eu.auth0.com remote_addr: "" request_uri: "" body: | - {"rendering_mode":"advanced","context_configuration":["branding.settings","branding.themes.default"],"default_head_tags_disabled":false,"head_tags":[{"attributes":{"async":true,"defer":true,"integrity":["sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g=="],"src":"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"},"content":"","tag":"script"}]} + {"rendering_mode":"standard"} form: {} headers: Content-Type: - application/json User-Agent: - - Go-Auth0/1.12.0 + - Go-Auth0/1.13.0 url: https://go-auth0-dev.eu.auth0.com/api/v2/prompts/signup/screen/signup/rendering method: PATCH response: @@ -100,16 +64,16 @@ interactions: proto_minor: 0 transfer_encoding: [] trailer: {} - content_length: -1 - uncompressed: true - body: '{"rendering_mode":"advanced","context_configuration":["branding.settings","branding.themes.default"],"default_head_tags_disabled":false,"head_tags":[{"attributes":{"async":true,"defer":true,"integrity":["sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g=="],"src":"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"},"content":"","tag":"script"}]}' + content_length: 29 + uncompressed: false + body: '{"rendering_mode":"standard"}' headers: Content-Type: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 385.032375ms - - id: 3 + duration: 407.188791ms + - id: 2 request: proto: HTTP/1.1 proto_major: 1 @@ -127,7 +91,7 @@ interactions: Content-Type: - application/json User-Agent: - - Go-Auth0/1.12.0 + - Go-Auth0/1.13.0 url: https://go-auth0-dev.eu.auth0.com/api/v2/prompts/signup/screen/signup/rendering method: PATCH response: @@ -144,8 +108,8 @@ interactions: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 386.19325ms - - id: 4 + duration: 490.321083ms + - id: 3 request: proto: HTTP/1.1 proto_major: 1 @@ -162,7 +126,7 @@ interactions: Content-Type: - application/json User-Agent: - - Go-Auth0/1.12.0 + - Go-Auth0/1.13.0 url: https://go-auth0-dev.eu.auth0.com/api/v2/prompts/signup/screen/signup/rendering method: GET response: @@ -179,8 +143,8 @@ interactions: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 429.387042ms - - id: 5 + duration: 420.75075ms + - id: 4 request: proto: HTTP/1.1 proto_major: 1 @@ -197,7 +161,7 @@ interactions: Content-Type: - application/json User-Agent: - - Go-Auth0/1.12.0 + - Go-Auth0/1.13.0 url: https://go-auth0-dev.eu.auth0.com/api/v2/branding/templates/universal-login method: DELETE response: @@ -214,39 +178,4 @@ interactions: - application/json; charset=utf-8 status: 204 No Content code: 204 - duration: 427.015708ms - - id: 6 - request: - proto: HTTP/1.1 - proto_major: 1 - proto_minor: 1 - content_length: 0 - transfer_encoding: [] - trailer: {} - host: go-auth0-dev.eu.auth0.com - remote_addr: "" - request_uri: "" - body: "" - form: {} - headers: - Content-Type: - - application/json - User-Agent: - - Go-Auth0/1.12.0 - url: https://go-auth0-dev.eu.auth0.com/api/v2/custom-domains/cd_HuDxFi74SU24Wy5g - method: DELETE - response: - proto: HTTP/2.0 - proto_major: 2 - proto_minor: 0 - transfer_encoding: [] - trailer: {} - content_length: 0 - uncompressed: false - body: "" - headers: - Content-Type: - - application/json; charset=utf-8 - status: 204 No Content - code: 204 - duration: 381.59875ms + duration: 998.947834ms