forked from bold-commerce/go-shopify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fulfillment_order_test.go
219 lines (167 loc) · 7.31 KB
/
fulfillment_order_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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
package goshopify
import (
"context"
"encoding/json"
"fmt"
"reflect"
"testing"
"time"
"github.com/jarcoal/httpmock"
)
func FulfillmentOrderTests(t *testing.T, fulfillmentOrder FulfillmentOrder) {
// Check that Id is assigned to the returned fulfillment
expectedInt := uint64(255858046) // in fulfillment_order.json fixture
if fulfillmentOrder.Id != expectedInt {
t.Errorf("FulfillmentOrder.Id returned %+v, expected %+v", fulfillmentOrder.Id, expectedInt)
}
}
func TestFulfillmentOrderList(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/123/fulfillment_orders.json", client.pathPrefix),
httpmock.NewStringResponder(200, `{"fulfillment_orders": [{"id":1},{"id":2}]}`))
fulfillmentService := &FulfillmentOrderServiceOp{client: client}
fulfillmentOrders, err := fulfillmentService.List(context.Background(), 123, nil)
if err != nil {
t.Errorf("FulfillmentOrder.List returned error: %v", err)
}
expected := []FulfillmentOrder{{Id: 1}, {Id: 2}}
if !reflect.DeepEqual(fulfillmentOrders, expected) {
t.Errorf("FulfillmentOrder.List returned %+v, expected %+v", fulfillmentOrders, expected)
}
}
func TestFulfillmentOrderGet(t *testing.T) {
setup()
defer teardown()
fixture := loadFixture("fulfillment_order.json")
httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/fulfillment_orders/255858046.json", client.pathPrefix),
httpmock.NewBytesResponder(200, fixture))
fulfillmentOrderService := &FulfillmentOrderServiceOp{client: client}
fulfillment, err := fulfillmentOrderService.Get(context.Background(), 255858046, nil)
if err != nil {
t.Errorf("FulfillmentOrder.Get returned error: %v", err)
}
expected := FulfillmentOrderResource{}
err = json.Unmarshal(fixture, &expected)
if err != nil {
t.Errorf("json.Unmarshall returned error : %v", err)
}
if !reflect.DeepEqual(fulfillment, expected.FulfillmentOrder) {
t.Errorf("FulfillmentOrder.Get returned %+v, expected %+v", fulfillment, expected)
}
}
func TestFulfillmentOrderCancel(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/fulfillment_orders/1/cancel.json", client.pathPrefix),
httpmock.NewBytesResponder(200, loadFixture("fulfillment_order.json")))
fulfillmentOrderService := &FulfillmentOrderServiceOp{client: client}
returnedFulfillment, err := fulfillmentOrderService.Cancel(context.Background(), 1)
if err != nil {
t.Errorf("FulfillmentOrder.Cancel returned error: %v", err)
}
FulfillmentOrderTests(t, *returnedFulfillment)
}
func TestFulfillmentOrderClose(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/fulfillment_orders/1/close.json", client.pathPrefix),
httpmock.NewBytesResponder(200, loadFixture("fulfillment_order.json")))
fulfillmentOrderService := &FulfillmentOrderServiceOp{client: client}
returnedFulfillment, err := fulfillmentOrderService.Close(context.Background(), 1, "test")
if err != nil {
t.Errorf("FulfillmentOrder.Close returned error: %v", err)
}
FulfillmentOrderTests(t, *returnedFulfillment)
}
func TestFulfillmentOrderHold(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/fulfillment_orders/1/hold.json", client.pathPrefix),
httpmock.NewBytesResponder(200, loadFixture("fulfillment_order.json")))
fulfillmentOrderService := &FulfillmentOrderServiceOp{client: client}
returnedFulfillment, err := fulfillmentOrderService.Hold(context.Background(), 1, false, HoldReasonOutOfStock, "test")
if err != nil {
t.Errorf("FulfillmentOrder.Hold returned error: %v", err)
}
FulfillmentOrderTests(t, *returnedFulfillment)
}
func TestFulfillmentOrderMove(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/fulfillment_orders/1046000818/move.json", client.pathPrefix),
httpmock.NewBytesResponder(200, loadFixture("fulfillment_order_move.json")))
fulfillmentOrderService := &FulfillmentOrderServiceOp{client: client}
req := FulfillmentOrderMoveRequest{
NewLocationId: 655441491,
LineItems: []FulfillmentOrderLineItemQuantity{
{Id: 1058737594, Quantity: 1},
},
}
result, err := fulfillmentOrderService.Move(context.Background(), 1046000818, req)
if err != nil {
t.Errorf("FulfillmentOrder.Move returned error: %v", err)
}
if result.MovedFulfillmentOrder.AssignedLocationId != 655441491 {
t.Errorf("FulfillmentOrder.Move result AssignedLocation is is %d, expected %d",
result.MovedFulfillmentOrder.AssignedLocationId, 655441491)
}
}
func TestFulfillmentOrderOpen(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/fulfillment_orders/255858046/open.json", client.pathPrefix),
httpmock.NewBytesResponder(200, loadFixture("fulfillment_order.json")))
fulfillmentOrderService := &FulfillmentOrderServiceOp{client: client}
fulfillmentId := uint64(255858046)
result, err := fulfillmentOrderService.Open(context.Background(), fulfillmentId)
if err != nil {
t.Errorf("FulfillmentOrder.Open returned error: %v", err)
}
if result == nil || result.Id != fulfillmentId {
t.Errorf("Expected Id: %d got: %d", result.Id, fulfillmentId)
}
}
func TestFulfillmentOrderReleaseHold(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/fulfillment_orders/255858046/release_hold.json", client.pathPrefix),
httpmock.NewBytesResponder(200, loadFixture("fulfillment_order.json")))
fulfillmentOrderService := &FulfillmentOrderServiceOp{client: client}
fulfillmentId := uint64(255858046)
result, err := fulfillmentOrderService.ReleaseHold(context.Background(), fulfillmentId)
if err != nil {
t.Errorf("FulfillmentOrder.ReleaseHold returned error: %v", err)
}
if result == nil || result.Id != fulfillmentId {
t.Errorf("Expected Id: %d got: %d", result.Id, fulfillmentId)
}
}
func TestFulfillmentOrderReschedule(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/fulfillment_orders/255858046/reschedule.json", client.pathPrefix),
httpmock.NewBytesResponder(200, loadFixture("fulfillment_order.json")))
fulfillmentOrderService := &FulfillmentOrderServiceOp{client: client}
fulfillmentId := uint64(255858046)
result, err := fulfillmentOrderService.Reschedule(context.Background(), fulfillmentId)
if err != nil {
t.Errorf("FulfillmentOrder.Reschedule returned error: %v", err)
}
if result == nil || result.Id != fulfillmentId {
t.Errorf("Expected Id: %d got: %d", result.Id, fulfillmentId)
}
}
func TestFulfillmentOrderSetDeadline(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/fulfillment_orders/set_fulfillment_orders_deadline.json", client.pathPrefix),
httpmock.NewStringResponder(200, "{}"))
fulfillmentOrderService := &FulfillmentOrderServiceOp{client: client}
fulfillmentId := uint64(255858046)
newDeadline := time.Now().Add(time.Hour * 24 * 7)
err := fulfillmentOrderService.SetDeadline(context.Background(), []uint64{fulfillmentId}, newDeadline)
if err != nil {
t.Errorf("FulfillmentOrder.SetDeadline returned error: %v", err)
}
}