Skip to content

Commit

Permalink
Consolidating check lower-down
Browse files Browse the repository at this point in the history
  • Loading branch information
willvedd committed Sep 8, 2023
1 parent 73e8eea commit 061dc5c
Show file tree
Hide file tree
Showing 3 changed files with 342 additions and 30 deletions.
8 changes: 4 additions & 4 deletions internal/auth0/prompt/flatten.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ func flattenPromptCustomText(data *schema.ResourceData, customText map[string]in
return err
}

if body == "null" {
return data.Set("body", nil)
}

return data.Set("body", body)
}

func marshalCustomTextBody(b map[string]interface{}) (string, error) {
if b == nil {
return "{}", nil
}

bodyBytes, err := json.Marshal(b)
if err != nil {
return "", fmt.Errorf("failed to serialize the custom texts to JSON: %w", err)
Expand Down
24 changes: 24 additions & 0 deletions internal/auth0/prompt/resource_custom_text_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ import (
func TestAccPromptCustomText(t *testing.T) {
acctest.Test(t, resource.TestCase{
Steps: []resource.TestStep{
{
Config: testAccPromptCustomTextEmptyBody,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("auth0_prompt_custom_text.prompt_custom_text", "prompt", "login"),
resource.TestCheckResourceAttr("auth0_prompt_custom_text.prompt_custom_text", "language", "en"),
resource.TestCheckResourceAttr("auth0_prompt_custom_text.prompt_custom_text", "body", "{}"),
),
},
{
Config: testAccPromptCustomTextCreate,
Check: resource.ComposeTestCheckFunc(
Expand All @@ -35,10 +43,26 @@ func TestAccPromptCustomText(t *testing.T) {
),
),
},
{
Config: testAccPromptCustomTextEmptyBody,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("auth0_prompt_custom_text.prompt_custom_text", "prompt", "login"),
resource.TestCheckResourceAttr("auth0_prompt_custom_text.prompt_custom_text", "language", "en"),
resource.TestCheckResourceAttr("auth0_prompt_custom_text.prompt_custom_text", "body", "{}"),
),
},
},
})
}

const testAccPromptCustomTextEmptyBody = `
resource "auth0_prompt_custom_text" "prompt_custom_text" {
prompt = "login"
language = "en"
body = "{}"
}
`

const testAccPromptCustomTextCreate = `
resource "auth0_prompt_custom_text" "prompt_custom_text" {
prompt = "login"
Expand Down
Loading

0 comments on commit 061dc5c

Please sign in to comment.