Skip to content

Commit

Permalink
PATCH: Ensure Removal of Insertion Points in `auth0_prompt_screen_par…
Browse files Browse the repository at this point in the history
…tial` Resource (auth0#1043)

Fix: Ensure Removal of Insertion Points in  Resource API
Signed-off-by: BryanLewis-AtOkta <[email protected]>
  • Loading branch information
developerkunal authored and bryanlewis-okta committed Oct 24, 2024
1 parent 420e434 commit 77be727
Show file tree
Hide file tree
Showing 3 changed files with 1,033 additions and 324 deletions.
5 changes: 5 additions & 0 deletions internal/auth0/prompt/resource_screen_partial.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ func updatePromptScreenPartial(ctx context.Context, data *schema.ResourceData, m
promptPartial := expandPromptScreenPartial(data)
for screenName, insertionPoints := range *promptPartial {
if existingInsertionPoints, exists := (*existingPromptScreenPartial)[screenName]; exists {
for insertionPoint := range existingInsertionPoints {
if _, found := insertionPoints[insertionPoint]; !found {
delete(existingInsertionPoints, insertionPoint)
}
}
for insertionPoint, content := range insertionPoints {
existingInsertionPoints[insertionPoint] = content
}
Expand Down
40 changes: 39 additions & 1 deletion internal/auth0/prompt/resource_screen_partial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,21 @@ resource "auth0_prompt_screen_partial" "login" {
}
}
`
const testAccPromptScreenPartialUpdate = testAccPromptScreenPartialCreate + testAccPromptScreenPartialCreate2

const testAccPromptScreenPartialRemoveInsertionPoint = testAccPromptScreenPartialWithoutScreenPartial + `
resource "auth0_prompt_screen_partial" "login_passwordless_email_code" {
depends_on = [ auth0_branding.my_brand ]
prompt_type = "login-passwordless"
screen_name = "login-passwordless-email-code"
insertion_points {
form_content_start = "<div>Form Content Start</div>"
form_content_end = "<div>Form Content End</div>"
}
}
`

const testAccPromptScreenPartialUpdate = testAccPromptScreenPartialCreate + testAccPromptScreenPartialCreate2
const testAccPromptScreenPartialRemoveInsertionPoints = testAccPromptScreenPartialRemoveInsertionPoint + testAccPromptScreenPartialCreate2
const testAccPromptScreenPartialDelete = testAccGivenACustomDomain + testGivenABrandingTemplate + testAccPromptScreenPartialCreate2

const testAccPromptScreenPartialData = `
Expand Down Expand Up @@ -93,6 +106,31 @@ func TestAccPromptScreenPartial(t *testing.T) {
resource.TestCheckResourceAttr("auth0_prompt_screen_partial.login_passwordless_email_code", "screen_name", "login-passwordless-email-code"),
resource.TestCheckResourceAttr("auth0_prompt_screen_partial.login_passwordless_email_code", "insertion_points.0.form_content_start", "<div>Form Content Start</div>"),
resource.TestCheckResourceAttr("auth0_prompt_screen_partial.login_passwordless_email_code", "insertion_points.0.form_content_end", "<div>Form Content End</div>"),
resource.TestCheckResourceAttr("auth0_prompt_screen_partial.login_passwordless_email_code", "insertion_points.0.form_footer_start", "<div>Form Footer Start</div>"),
resource.TestCheckResourceAttr("auth0_prompt_screen_partial.login_passwordless_email_code", "insertion_points.0.form_footer_end", "<div>Form Footer End</div>"),
resource.TestCheckResourceAttr("auth0_prompt_screen_partial.login_passwordless_sms_otp", "prompt_type", "login-passwordless"),
resource.TestCheckResourceAttr("auth0_prompt_screen_partial.login_passwordless_sms_otp", "screen_name", "login-passwordless-sms-otp"),
resource.TestCheckResourceAttr("auth0_prompt_screen_partial.login_passwordless_sms_otp", "insertion_points.0.form_content_start", "<div>Form Content Start</div>"),
resource.TestCheckResourceAttr("auth0_prompt_screen_partial.login_passwordless_sms_otp", "insertion_points.0.form_content_end", "<div>Form Content End</div>"),
resource.TestCheckResourceAttr("auth0_prompt_screen_partial.login", "prompt_type", "login"),
resource.TestCheckResourceAttr("auth0_prompt_screen_partial.login", "screen_name", "login"),
resource.TestCheckResourceAttr("auth0_prompt_screen_partial.login", "insertion_points.0.form_content_start", "<div>Form Content Start</div>"),
resource.TestCheckResourceAttr("auth0_prompt_screen_partial.login", "insertion_points.0.form_content_end", "<div>Form Content End</div>"),
resource.TestCheckResourceAttr("auth0_prompt_screen_partial.login", "insertion_points.0.form_footer_start", "<div>Form Footer Start</div>"),
resource.TestCheckResourceAttr("auth0_prompt_screen_partial.login", "insertion_points.0.form_footer_end", "<div>Form Footer End</div>"),
resource.TestCheckResourceAttr("auth0_prompt_screen_partial.login", "insertion_points.0.secondary_actions_start", "<div>Secondary Actions Start</div>"),
resource.TestCheckResourceAttr("auth0_prompt_screen_partial.login", "insertion_points.0.secondary_actions_end", "<div>Secondary Actions End</div>"),
),
},
{
Config: testAccPromptScreenPartialRemoveInsertionPoints,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("auth0_prompt_screen_partial.login_passwordless_email_code", "prompt_type", "login-passwordless"),
resource.TestCheckResourceAttr("auth0_prompt_screen_partial.login_passwordless_email_code", "screen_name", "login-passwordless-email-code"),
resource.TestCheckResourceAttr("auth0_prompt_screen_partial.login_passwordless_email_code", "insertion_points.0.form_content_start", "<div>Form Content Start</div>"),
resource.TestCheckResourceAttr("auth0_prompt_screen_partial.login_passwordless_email_code", "insertion_points.0.form_content_end", "<div>Form Content End</div>"),
resource.TestCheckResourceAttr("auth0_prompt_screen_partial.login_passwordless_email_code", "insertion_points.0.form_footer_start", ""),
resource.TestCheckResourceAttr("auth0_prompt_screen_partial.login_passwordless_email_code", "insertion_points.0.form_footer_end", ""),
resource.TestCheckResourceAttr("auth0_prompt_screen_partial.login_passwordless_sms_otp", "prompt_type", "login-passwordless"),
resource.TestCheckResourceAttr("auth0_prompt_screen_partial.login_passwordless_sms_otp", "screen_name", "login-passwordless-sms-otp"),
resource.TestCheckResourceAttr("auth0_prompt_screen_partial.login_passwordless_sms_otp", "insertion_points.0.form_content_start", "<div>Form Content Start</div>"),
Expand Down
Loading

0 comments on commit 77be727

Please sign in to comment.