Skip to content

Commit

Permalink
feat: fixed len issues with business unit settings
Browse files Browse the repository at this point in the history
  • Loading branch information
demeyerthom committed Aug 23, 2024
1 parent 59f5ce8 commit e194162
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 23 deletions.
2 changes: 1 addition & 1 deletion internal/resources/project/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ func (p *Project) updateActions(plan Project) (platform.ProjectUpdate, error) {
},
)
//TODO: should set associate role to nil, but that is not currently supported in the SDK
} else {
} else if len(p.BusinessUnits) != 0 && len(plan.BusinessUnits) != 0 {
if !p.BusinessUnits[0].MyBusinessUnitStatusOnCreation.Equal(plan.BusinessUnits[0].MyBusinessUnitStatusOnCreation) {
result.Actions = append(result.Actions,
platform.ProjectChangeBusinessUnitStatusOnCreationAction{
Expand Down
1 change: 0 additions & 1 deletion internal/resources/project/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ func (r *projectResource) Schema(_ context.Context, _ resource.SchemaRequest, re
"for the shippingRateInput on the cart. The keys are checked for uniqueness and the request is " +
"rejected if keys are not unique",
Validators: []validator.List{
listvalidator.SizeAtMost(1),
customvalidator.RequireValueValidator(
"CartClassification",
path.MatchRoot("shipping_rate_input_type"),
Expand Down
123 changes: 102 additions & 21 deletions internal/resources/project/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestAccProjectCreate_basic(t *testing.T) {
assert.EqualValues(t, result.Languages, []string{"nl", "de", "en", "en-US"})
assert.EqualValues(t, result.Currencies, []string{"EUR", "USD"})
assert.Equal(t, *result.Carts.DeleteDaysAfterLastModification, 7)
assert.Equal(t, result.ShippingRateInputType, platform.CartValueType(platform.CartValueType{}))
assert.Equal(t, result.ShippingRateInputType, platform.CartValueType{})
return nil
},
),
Expand Down Expand Up @@ -142,27 +142,43 @@ func TestAccProjectCreate_basic(t *testing.T) {
resourceName, "carts.0.delete_days_after_last_modification"),
),
},
// Running this step again so project settings match what later shipping_zone_rate_test will need
/*
{
Config: testAccProjectConfig("acctest_project_settings"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "name", "Test this thing"),
resource.TestCheckResourceAttr(resourceName, "countries.#", "3"),
resource.TestCheckResourceAttr(resourceName, "currencies.#", "2"),
resource.TestCheckResourceAttr(resourceName, "languages.#", "4"),
resource.TestCheckResourceAttr(resourceName, "messages.0.enabled", "true"),
resource.TestCheckResourceAttr(
resourceName, "external_oauth.0.url", "https://example.com/oauth/token"),
resource.TestCheckResourceAttr(
resourceName, "external_oauth.0.authorization_header", "Bearer secret"),
resource.TestCheckResourceAttr(
resourceName, "shipping_rate_input_type", "CartValue"),
resource.TestCheckResourceAttr(
resourceName, "carts.0.country_tax_rate_fallback_enabled", "true"),
{
Config: testAccProjectConfigSetMyBusinessUnitStatusOnCreation("acctest_project_settings"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "business_units.#", "1"),
resource.TestCheckResourceAttr(
resourceName,
"business_units.0.my_business_unit_status_on_creation",
string(platform.BusinessUnitStatusActive),
),
),
},
{
Config: testAccProjectConfigSetMyBusinessUnitStatusOnCreation("acctest_project_settings"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "business_units.#", "1"),
resource.TestCheckResourceAttr(
resourceName,
"business_units.0.my_business_unit_status_on_creation",
string(platform.BusinessUnitStatusActive),
),
),
},
{
Config: testAccProjectConfigSetMyBusinessUnitAssociateRoleOnKeyCreation("acctest_project_settings"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "business_units.#", "1"),
resource.TestCheckResourceAttr(
resourceName,
"business_units.0.my_business_unit_status_on_creation",
string(platform.BusinessUnitStatusInactive),
),
resource.TestCheckResourceAttrSet(
resourceName,
"business_units.0.my_business_unit_associate_role_key_on_creation",
),
},
*/
),
},
},
})
}
Expand Down Expand Up @@ -268,3 +284,68 @@ func testAccProjectConfigDeleteOAuthAndCarts(identifier string) string {
"identifier": identifier,
})
}

func testAccProjectConfigSetMyBusinessUnitStatusOnCreation(identifier string) string {
return utils.HCLTemplate(`
resource "commercetools_project_settings" "{{ .identifier }}" {
name = "Test this thing new"
countries = ["NL", "DE", "US", "GB"]
currencies = ["EUR", "USD", "GBP"]
languages = ["nl", "de", "en", "en-US", "fr"]
messages {
enabled = false
}
shipping_rate_input_type = "CartClassification"
shipping_rate_cart_classification_value {
key = "Small"
label = {
"en" = "Small"
"nl" = "Klein"
}
}
business_units {
my_business_unit_status_on_creation = "Active"
}
}`, map[string]any{
"identifier": identifier,
})
}

func testAccProjectConfigSetMyBusinessUnitAssociateRoleOnKeyCreation(identifier string) string {
return utils.HCLTemplate(`
resource commercetools_associate_role "my-role" {
key = "my-role"
name = "My role"
permissions = [
"UpdateAssociates"
]
}
resource "commercetools_project_settings" "{{ .identifier }}" {
name = "Test this thing new"
countries = ["NL", "DE", "US", "GB"]
currencies = ["EUR", "USD", "GBP"]
languages = ["nl", "de", "en", "en-US", "fr"]
messages {
enabled = false
}
shipping_rate_input_type = "CartClassification"
shipping_rate_cart_classification_value {
key = "Small"
label = {
"en" = "Small"
"nl" = "Klein"
}
}
business_units {
my_business_unit_status_on_creation = "Inactive"
my_business_unit_associate_role_key_on_creation = commercetools_associate_role.my-role.key
}
}`, map[string]any{
"identifier": identifier,
})
}

0 comments on commit e194162

Please sign in to comment.