Skip to content

Commit

Permalink
fix(category): minimal category fields giving read error (#170)
Browse files Browse the repository at this point in the history
* fix(category): minimal category fields giving read error

Passing LocalizedString({}) gives back that empty LocalizedString in our mock server but CT gives back nil

* Update commercetools/resource_category.go

Fix wrong var name

Co-authored-by: qdegraaf <34540841+qdegraaf@users.noreply.github.com>

Co-authored-by: qdegraaf <34540841+qdegraaf@users.noreply.github.com>
  • Loading branch information
davidweterings and qdegraaf authored May 19, 2021
1 parent 023aca8 commit 35b50f0
Showing 2 changed files with 51 additions and 15 deletions.
40 changes: 27 additions & 13 deletions commercetools/resource_category.go
Original file line number Diff line number Diff line change
@@ -145,21 +145,33 @@ func resourceCategoryCreate(d *schema.ResourceData, m interface{}) error {
var category *commercetools.Category

name := commercetools.LocalizedString(expandStringMap(d.Get("name").(map[string]interface{})))
desc := commercetools.LocalizedString(expandStringMap(d.Get("description").(map[string]interface{})))
slug := commercetools.LocalizedString(expandStringMap(d.Get("slug").(map[string]interface{})))
metaTitle := commercetools.LocalizedString(expandStringMap(d.Get("meta_title").(map[string]interface{})))
metaDescription := commercetools.LocalizedString(expandStringMap(d.Get("meta_description").(map[string]interface{})))
metaKeywords := commercetools.LocalizedString(expandStringMap(d.Get("meta_keywords").(map[string]interface{})))

draft := &commercetools.CategoryDraft{
Key: d.Get("key").(string),
Name: &name,
Description: &desc,
Slug: &slug,
OrderHint: d.Get("order_hint").(string),
MetaTitle: &metaTitle,
MetaDescription: &metaDescription,
MetaKeywords: &metaKeywords,
Key: d.Get("key").(string),
Name: &name,
Slug: &slug,
OrderHint: d.Get("order_hint").(string),
}

if d.Get("description") != nil {
desc := commercetools.LocalizedString(expandStringMap(d.Get("description").(map[string]interface{})))
draft.Description = &desc
}

if d.Get("meta_title") != nil {
metaTitle := commercetools.LocalizedString(expandStringMap(d.Get("meta_title").(map[string]interface{})))
draft.MetaTitle = &metaTitle
}

if d.Get("meta_description") != nil {
metaDescription := commercetools.LocalizedString(expandStringMap(d.Get("meta_description").(map[string]interface{})))
draft.MetaDescription = &metaDescription
}

if d.Get("meta_keywords") != nil {
metaKeywords := commercetools.LocalizedString(expandStringMap(d.Get("meta_keywords").(map[string]interface{})))
draft.MetaKeywords = &metaKeywords
}

if d.Get("parent").(string) != "" {
@@ -224,9 +236,11 @@ func resourceCategoryRead(d *schema.ResourceData, m interface{}) error {
d.Set("version", category.Version)
d.Set("key", category.Key)
d.Set("name", *category.Name)
d.Set("description", *category.Description)
d.Set("parent", category.Parent)
d.Set("order_hint", category.OrderHint)
if category.Description != nil {
d.Set("description", *category.Description)
}
if category.MetaTitle != nil {
d.Set("meta_title", *category.MetaTitle)
}
26 changes: 24 additions & 2 deletions commercetools/resource_category_test.go
Original file line number Diff line number Diff line change
@@ -3,11 +3,12 @@ package commercetools
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/labd/commercetools-go-sdk/commercetools"
"strings"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/labd/commercetools-go-sdk/commercetools"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

@@ -21,6 +22,9 @@ func TestAccCategoryCreate_basic(t *testing.T) {
{
Config: testAccCategoryConfig(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"commercetools_category.accessories_minimal", "name.en", "accessories_m",
),
resource.TestCheckResourceAttr(
"commercetools_category.accessories", "name.en", "accessories",
),
@@ -155,6 +159,15 @@ func testAccCategoryConfig() string {
order_hint = "0.00001614336548703960465522"
}
resource "commercetools_category" "accessories_minimal" {
name = {
en = "accessories_m"
}
slug = {
en = "accessories_m"
}
}
resource "commercetools_category" "accessories" {
name = {
en = "accessories"
@@ -210,6 +223,15 @@ func testAccCategoryUpdate() string {
order_hint = "0.00001614336548703960465522"
}
resource "commercetools_category" "accessories_minimal" {
name = {
en = "accessories_m"
}
slug = {
en = "accessories_m"
}
}
resource "commercetools_category" "accessories" {
name = {
en = "accessories"

0 comments on commit 35b50f0

Please sign in to comment.