Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HS (HTS) Code fields, as per fields supported by Shopify's API. #213

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion fixtures/inventory_item.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
"updated_at": "2018-10-29T06:05:58-04:00",
"cost": "25.00",
"tracked": true,
"admin_graphql_api_id": "gid://shopify/InventoryItem/808950810"
"admin_graphql_api_id": "gid://shopify/InventoryItem/808950810",
"country_code_of_origin": "US",
"country_harmonized_system_codes": ["8471.70.40.35", "8471.70.50.35"],
"harmonized_system_code": "8471.70.40.35",
"province_code_of_origin": "ON"
}
}
18 changes: 11 additions & 7 deletions inventory_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ type InventoryItemServiceOp struct {

// InventoryItem represents a Shopify inventory item
type InventoryItem struct {
ID int64 `json:"id,omitempty"`
SKU string `json:"sku,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
Cost *decimal.Decimal `json:"cost,omitempty"`
Tracked *bool `json:"tracked,omitempty"`
AdminGraphqlAPIID string `json:"admin_graphql_api_id,omitempty"`
ID int64 `json:"id,omitempty"`
SKU string `json:"sku,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
Cost *decimal.Decimal `json:"cost,omitempty"`
Tracked *bool `json:"tracked,omitempty"`
AdminGraphqlAPIID string `json:"admin_graphql_api_id,omitempty"`
CountryCodeOfOrigin *string `json:"country_code_of_origin"`
CountryHarmonizedSystemCodes []string `json:"country_harmonized_system_codes"`
HarmonizedSystemCode *string `json:"harmonized_system_code"`
ProvinceCodeOfOrigin *string `json:"province_code_of_origin"`
}

// InventoryItemResource is used for handling single item requests and responses
Expand Down
23 changes: 23 additions & 0 deletions inventory_item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package goshopify

import (
"fmt"
"strings"
"testing"

"github.com/jarcoal/httpmock"
Expand Down Expand Up @@ -33,6 +34,28 @@ func inventoryItemTests(t *testing.T, item *InventoryItem) {
if costFloat != expectedCost {
t.Errorf("InventoryItem.Cost (float) is %+v, expected %+v", costFloat, expectedCost)
}

expectedOrigin := "US"
if *item.CountryCodeOfOrigin != expectedOrigin {
t.Errorf("InventoryItem.CountryCodeOfOrigin returned %+v, expected %+v", item.CountryCodeOfOrigin, expectedOrigin)
}

//strings.Join is used to compare slices since package's go.mod is set to 1.13
//which predates the experimental slices package that has a Compare() func.
expectedCountryHSCodes := strings.Join([]string{"8471.70.40.35", "8471.70.50.35"}, ",")
if strings.Join(item.CountryHarmonizedSystemCodes, ",") != expectedCountryHSCodes {
t.Errorf("InventoryItem.CountryHarmonizedSystemCodes returned %+v, expected %+v", item.CountryHarmonizedSystemCodes, expectedCountryHSCodes)
}

expectedHSCode := "8471.70.40.35"
if *item.HarmonizedSystemCode != expectedHSCode {
t.Errorf("InventoryItem.HarmonizedSystemCode returned %+v, expected %+v", item.CountryHarmonizedSystemCodes, expectedHSCode)
}

expectedProvince := "ON"
if *item.ProvinceCodeOfOrigin != expectedProvince {
t.Errorf("InventoryItem.ProvinceCodeOfOrigin returned %+v, expected %+v", item.ProvinceCodeOfOrigin, expectedHSCode)
}
}

func inventoryItemsTests(t *testing.T, items []InventoryItem) {
Expand Down