Skip to content

Commit

Permalink
prevented issue with bool valueunknown check
Browse files Browse the repository at this point in the history
  • Loading branch information
demeyerthom committed Sep 25, 2023
1 parent 2608dbb commit 68ded34
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 81 deletions.
3 changes: 3 additions & 0 deletions .changes/unreleased/Fixed-20230925-095615.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Fixed
body: prevented issue with bool valueunknown check
time: 2023-09-25T09:56:15.850639829+02:00
4 changes: 2 additions & 2 deletions internal/resources/project/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func (p Project) updateActions(plan Project) platform.ProjectUpdate {
}

// changeOrderSearchStatus
if !p.EnableSearchIndexOrders.Equal(plan.EnableSearchIndexOrders) {
if !(p.EnableSearchIndexOrders.ValueBool() == plan.EnableSearchIndexOrders.ValueBool()) {
status := platform.OrderSearchStatusDeactivated
if plan.EnableSearchIndexOrders.ValueBool() {
status = platform.OrderSearchStatusActivated
Expand All @@ -251,7 +251,7 @@ func (p Project) updateActions(plan Project) platform.ProjectUpdate {
}

// changeProductSearchIndexingEnabled
if !p.EnableSearchIndexProducts.Equal(plan.EnableSearchIndexProducts) {
if !(p.EnableSearchIndexProducts.ValueBool() == plan.EnableSearchIndexProducts.ValueBool()) {
result.Actions = append(result.Actions,
platform.ProjectChangeProductSearchIndexingEnabledAction{
Enabled: plan.EnableSearchIndexProducts.ValueBool(),
Expand Down
175 changes: 96 additions & 79 deletions internal/resources/project/model_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package project

import (
"github.com/labd/terraform-provider-commercetools/internal/utils"
"testing"

"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/labd/commercetools-go-sdk/platform"
"github.com/stretchr/testify/assert"

"github.com/labd/terraform-provider-commercetools/internal/customtypes"
"github.com/labd/terraform-provider-commercetools/internal/models"
)

Expand Down Expand Up @@ -67,91 +64,111 @@ func TestUpdateActions(t *testing.T) {
plan Project
action platform.ProjectUpdate
}{
//{
// name: "Default",
// state: Project{
// Version: types.Int64Value(1),
// ID: types.StringValue("my-project"),
// Key: types.StringValue("my-project"),
// Name: types.StringValue("my project"),
// Countries: []types.String{types.StringValue("US")},
// ShippingRateInputType: types.StringValue("CartValue"),
// },
// plan: Project{
// Version: types.Int64Value(1),
// ID: types.StringValue("my-project"),
// Key: types.StringValue("my-project"),
// Name: types.StringValue("my new name"),
// Countries: []types.String{
// types.StringValue("NL"),
// types.StringValue("DE"),
// },
// ShippingRateInputType: types.StringValue("CartClassification"),
// ShippingRateCartClassificationValue: []models.CustomFieldLocalizedEnumValue{
// {
// Key: types.StringValue("Light"),
// Label: customtypes.NewLocalizedStringValue(map[string]attr.Value{
// "nl": types.StringValue("licht"),
// "en": types.StringValue("light"),
// }),
// },
// },
// },
// action: platform.ProjectUpdate{
// Version: 1,
// Actions: []platform.ProjectUpdateAction{
// platform.ProjectChangeCountriesAction{
// Countries: []string{"NL", "DE"},
// },
// platform.ProjectChangeNameAction{
// Name: "my new name",
// },
// platform.ProjectSetShippingRateInputTypeAction{
// ShippingRateInputType: platform.CartClassificationType{
// Values: []platform.CustomFieldLocalizedEnumValue{
// {
// Key: "Light",
// Label: platform.LocalizedString{
// "en": "light",
// "nl": "licht",
// },
// },
// },
// },
// },
// },
// },
//},
//{
// name: "Carts Configuration",
// state: Project{
// Version: types.Int64Value(1),
// Carts: []Carts{
// {
// CountryTaxRateFallbackEnabled: types.BoolValue(true),
// DeleteDaysAfterLastModification: types.Int64Value(10),
// },
// },
// },
// plan: Project{
// Version: types.Int64Value(1),
// Carts: []Carts{
// {
// CountryTaxRateFallbackEnabled: types.BoolValue(false),
// DeleteDaysAfterLastModification: types.Int64Value(90),
// },
// },
// },
// action: platform.ProjectUpdate{
// Version: 1,
// Actions: []platform.ProjectUpdateAction{
// platform.ProjectChangeCartsConfigurationAction{
// CartsConfiguration: platform.CartsConfiguration{
// CountryTaxRateFallbackEnabled: utils.BoolRef(false),
// DeleteDaysAfterLastModification: utils.IntRef(90),
// },
// },
// platform.ProjectChangeCountryTaxRateFallbackEnabledAction{CountryTaxRateFallbackEnabled: false},
// },
// },
//},
{
name: "Default",
name: "Create with bool unknown",
state: Project{
Version: types.Int64Value(1),
ID: types.StringValue("my-project"),
Key: types.StringValue("my-project"),
Name: types.StringValue("my project"),
Countries: []types.String{types.StringValue("US")},
ShippingRateInputType: types.StringValue("CartValue"),
},
plan: Project{
Version: types.Int64Value(1),
ID: types.StringValue("my-project"),
Key: types.StringValue("my-project"),
Name: types.StringValue("my new name"),
Countries: []types.String{
types.StringValue("NL"),
types.StringValue("DE"),
},
ShippingRateInputType: types.StringValue("CartClassification"),
ShippingRateCartClassificationValue: []models.CustomFieldLocalizedEnumValue{
{
Key: types.StringValue("Light"),
Label: customtypes.NewLocalizedStringValue(map[string]attr.Value{
"nl": types.StringValue("licht"),
"en": types.StringValue("light"),
}),
},
},
},
action: platform.ProjectUpdate{
Version: 1,
Actions: []platform.ProjectUpdateAction{
platform.ProjectChangeCountriesAction{
Countries: []string{"NL", "DE"},
},
platform.ProjectChangeNameAction{
Name: "my new name",
},
platform.ProjectSetShippingRateInputTypeAction{
ShippingRateInputType: platform.CartClassificationType{
Values: []platform.CustomFieldLocalizedEnumValue{
{
Key: "Light",
Label: platform.LocalizedString{
"en": "light",
"nl": "licht",
},
},
},
},
},
},
},
},
{
name: "Carts Configuration",
state: Project{
Version: types.Int64Value(1),
Carts: []Carts{
{
CountryTaxRateFallbackEnabled: types.BoolValue(true),
DeleteDaysAfterLastModification: types.Int64Value(10),
},
},
Version: types.Int64Value(1),
EnableSearchIndexOrders: types.BoolValue(false),
EnableSearchIndexProducts: types.BoolValue(false),
},
plan: Project{
Version: types.Int64Value(1),
Carts: []Carts{
{
CountryTaxRateFallbackEnabled: types.BoolValue(false),
DeleteDaysAfterLastModification: types.Int64Value(90),
},
},

EnableSearchIndexOrders: types.BoolValue(true),
EnableSearchIndexProducts: types.BoolUnknown(),
},
action: platform.ProjectUpdate{
Version: 1,
Actions: []platform.ProjectUpdateAction{
platform.ProjectChangeCartsConfigurationAction{
CartsConfiguration: platform.CartsConfiguration{
CountryTaxRateFallbackEnabled: utils.BoolRef(false),
DeleteDaysAfterLastModification: utils.IntRef(90),
},
},
platform.ProjectChangeCountryTaxRateFallbackEnabledAction{CountryTaxRateFallbackEnabled: false},
platform.ProjectChangeOrderSearchStatusAction{Status: platform.OrderSearchStatusActivated},
},
},
},
Expand Down

0 comments on commit 68ded34

Please sign in to comment.