forked from bold-commerce/go-shopify
-
Notifications
You must be signed in to change notification settings - Fork 1
/
inventory_item_test.go
117 lines (92 loc) · 2.79 KB
/
inventory_item_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package goshopify
import (
"fmt"
"testing"
"github.com/jarcoal/httpmock"
)
func inventoryItemTests(t *testing.T, item *InventoryItem) {
if item == nil {
t.Errorf("InventoryItem is nil")
return
}
expectedInt := int64(808950810)
if item.ID != expectedInt {
t.Errorf("InventoryItem.ID returned %+v, expected %+v", item.ID, expectedInt)
}
expectedSKU := "new sku"
if item.SKU != expectedSKU {
t.Errorf("InventoryItem.SKU sku is %+v, expected %+v", item.SKU, expectedSKU)
}
if item.Cost == nil {
t.Errorf("InventoryItem.Cost is nil")
return
}
expectedCost := 25.00
costFloat, _ := item.Cost.Float64()
if costFloat != expectedCost {
t.Errorf("InventoryItem.Cost (float) is %+v, expected %+v", costFloat, expectedCost)
}
}
func inventoryItemsTests(t *testing.T, items []InventoryItem) {
expectedLen := 3
if len(items) != expectedLen {
t.Errorf("InventoryItems list lenth is %+v, expected %+v", len(items), expectedLen)
}
}
func TestInventoryItemsList(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/inventory_items.json", client.pathPrefix),
httpmock.NewBytesResponder(200, loadFixture("inventory_items.json")))
items, err := client.InventoryItem.List(nil)
if err != nil {
t.Errorf("InventoryItems.List returned error: %v", err)
}
inventoryItemsTests(t, items)
}
func TestInventoryItemsListWithIDs(t *testing.T) {
setup()
defer teardown()
params := map[string]string{
"ids": "1,2",
}
httpmock.RegisterResponderWithQuery(
"GET",
fmt.Sprintf("https://fooshop.myshopify.com/%s/inventory_items.json", client.pathPrefix),
params,
httpmock.NewBytesResponder(200, loadFixture("inventory_items.json")),
)
options := ListOptions{
IDs: []int64{1, 2},
}
items, err := client.InventoryItem.List(options)
if err != nil {
t.Errorf("InventoryItems.List returned error: %v", err)
}
inventoryItemsTests(t, items)
}
func TestInventoryItemGet(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/inventory_items/1.json", client.pathPrefix),
httpmock.NewBytesResponder(200, loadFixture("inventory_item.json")))
item, err := client.InventoryItem.Get(1, nil)
if err != nil {
t.Errorf("InventoryItem.Get returned error: %v", err)
}
inventoryItemTests(t, item)
}
func TestInventoryItemUpdate(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("PUT", fmt.Sprintf("https://fooshop.myshopify.com/%s/inventory_items/1.json", client.pathPrefix),
httpmock.NewBytesResponder(200, loadFixture("inventory_item.json")))
item := InventoryItem{
ID: 1,
}
updatedItem, err := client.InventoryItem.Update(item)
if err != nil {
t.Errorf("InentoryItem.Update returned error: %v", err)
}
inventoryItemTests(t, updatedItem)
}