Skip to content

Commit 05e7e57

Browse files
authored
update country_harmonized_system_codes type in InventoryItem (#319)
1 parent f644757 commit 05e7e57

File tree

3 files changed

+47
-19
lines changed

3 files changed

+47
-19
lines changed

fixtures/inventory_item.json

+11-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,17 @@
88
"tracked": true,
99
"admin_graphql_api_id": "gid://shopify/InventoryItem/808950810",
1010
"country_code_of_origin": "US",
11-
"country_harmonized_system_codes": ["8471.70.40.35", "8471.70.50.35"],
11+
"country_harmonized_system_codes": [
12+
{
13+
"harmonized_system_code": "8471.70.40.35",
14+
"country_code": "US"
15+
},
16+
{
17+
"harmonized_system_code": "8471.70.50.35",
18+
"country_code": "CA"
19+
}
20+
],
1221
"harmonized_system_code": "8471.70.40.35",
1322
"province_code_of_origin": "ON"
1423
}
15-
}
24+
}

inventory_item.go

+17-11
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,25 @@ type InventoryItemServiceOp struct {
2424
client *Client
2525
}
2626

27+
// CountryHarmonizedSystemCode represents a harmonized system code for a specific country
28+
type CountryHarmonizedSystemCode struct {
29+
HarmonizedSystemCode string `json:"harmonized_system_code"`
30+
CountryCode string `json:"country_code"`
31+
}
32+
2733
// InventoryItem represents a Shopify inventory item
2834
type InventoryItem struct {
29-
Id uint64 `json:"id,omitempty"`
30-
SKU string `json:"sku,omitempty"`
31-
CreatedAt *time.Time `json:"created_at,omitempty"`
32-
UpdatedAt *time.Time `json:"updated_at,omitempty"`
33-
Cost *decimal.Decimal `json:"cost,omitempty"`
34-
Tracked *bool `json:"tracked,omitempty"`
35-
AdminGraphqlApiId string `json:"admin_graphql_api_id,omitempty"`
36-
CountryCodeOfOrigin *string `json:"country_code_of_origin"`
37-
CountryHarmonizedSystemCodes []string `json:"country_harmonized_system_codes"`
38-
HarmonizedSystemCode *string `json:"harmonized_system_code"`
39-
ProvinceCodeOfOrigin *string `json:"province_code_of_origin"`
35+
Id uint64 `json:"id,omitempty"`
36+
SKU string `json:"sku,omitempty"`
37+
CreatedAt *time.Time `json:"created_at,omitempty"`
38+
UpdatedAt *time.Time `json:"updated_at,omitempty"`
39+
Cost *decimal.Decimal `json:"cost,omitempty"`
40+
Tracked *bool `json:"tracked,omitempty"`
41+
AdminGraphqlApiId string `json:"admin_graphql_api_id,omitempty"`
42+
CountryCodeOfOrigin *string `json:"country_code_of_origin"`
43+
CountryHarmonizedSystemCodes []CountryHarmonizedSystemCode `json:"country_harmonized_system_codes"`
44+
HarmonizedSystemCode *string `json:"harmonized_system_code"`
45+
ProvinceCodeOfOrigin *string `json:"province_code_of_origin"`
4046
}
4147

4248
// InventoryItemResource is used for handling single item requests and responses

inventory_item_test.go

+19-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package goshopify
33
import (
44
"context"
55
"fmt"
6-
"strings"
76
"testing"
87

98
"github.com/jarcoal/httpmock"
@@ -41,11 +40,25 @@ func inventoryItemTests(t *testing.T, item *InventoryItem) {
4140
t.Errorf("InventoryItem.CountryCodeOfOrigin returned %+v, expected %+v", item.CountryCodeOfOrigin, expectedOrigin)
4241
}
4342

44-
// strings.Join is used to compare slices since package's go.mod is set to 1.13
45-
// which predates the experimental slices package that has a Compare() func.
46-
expectedCountryHSCodes := strings.Join([]string{"8471.70.40.35", "8471.70.50.35"}, ",")
47-
if strings.Join(item.CountryHarmonizedSystemCodes, ",") != expectedCountryHSCodes {
48-
t.Errorf("InventoryItem.CountryHarmonizedSystemCodes returned %+v, expected %+v", item.CountryHarmonizedSystemCodes, expectedCountryHSCodes)
43+
expectedCodes := []CountryHarmonizedSystemCode{
44+
{HarmonizedSystemCode: "8471.70.40.35", CountryCode: "US"},
45+
{HarmonizedSystemCode: "8471.70.50.35", CountryCode: "CA"},
46+
}
47+
48+
if len(item.CountryHarmonizedSystemCodes) != len(expectedCodes) {
49+
t.Errorf("InventoryItem.CountryHarmonizedSystemCodes length is %d, expected %d",
50+
len(item.CountryHarmonizedSystemCodes), len(expectedCodes))
51+
}
52+
53+
for i, code := range item.CountryHarmonizedSystemCodes {
54+
if code.HarmonizedSystemCode != expectedCodes[i].HarmonizedSystemCode {
55+
t.Errorf("InventoryItem.CountryHarmonizedSystemCodes[%d].HarmonizedSystemCode is %s, expected %s",
56+
i, code.HarmonizedSystemCode, expectedCodes[i].HarmonizedSystemCode)
57+
}
58+
if code.CountryCode != expectedCodes[i].CountryCode {
59+
t.Errorf("InventoryItem.CountryHarmonizedSystemCodes[%d].CountryCode is %s, expected %s",
60+
i, code.CountryCode, expectedCodes[i].CountryCode)
61+
}
4962
}
5063

5164
expectedHSCode := "8471.70.40.35"

0 commit comments

Comments
 (0)