1
1
import assert from 'assert' ;
2
2
import Client from '../src/client' ;
3
3
import fetchMock from './isomorphic-fetch-mock' ; // eslint-disable-line import/no-unresolved
4
+ import fetchMockPostOnce from './fetch-mock-helper' ;
4
5
5
6
// fixtures
6
7
import checkoutFixture from '../fixtures/checkout-fixture' ;
@@ -57,7 +58,7 @@ suite('client-checkout-integration-test', () => {
57
58
} ) ;
58
59
59
60
test ( 'it resolves with a checkout on Client.checkout#fetch' , ( ) => {
60
- fetchMock . postOnce ( apiUrl , checkoutFixture ) ;
61
+ fetchMockPostOnce ( fetchMock , apiUrl , checkoutFixture ) ;
61
62
62
63
const checkoutId = checkoutFixture . data . node . id ;
63
64
@@ -68,7 +69,7 @@ suite('client-checkout-integration-test', () => {
68
69
} ) ;
69
70
70
71
test ( 'it resolves with null on Client.checkout#fetch for a bad checkoutId' , ( ) => {
71
- fetchMock . postOnce ( apiUrl , checkoutNullFixture ) ;
72
+ fetchMockPostOnce ( fetchMock , apiUrl , checkoutNullFixture ) ;
72
73
73
74
const checkoutId = checkoutFixture . data . node . id ;
74
75
@@ -89,7 +90,7 @@ suite('client-checkout-integration-test', () => {
89
90
shippingAddress : { }
90
91
} ;
91
92
92
- fetchMock . postOnce ( apiUrl , checkoutCreateFixture ) ;
93
+ fetchMockPostOnce ( fetchMock , apiUrl , checkoutCreateFixture ) ;
93
94
94
95
return client . checkout . create ( input ) . then ( ( checkout ) => {
95
96
assert . equal ( checkout . id , checkoutCreateFixture . data . checkoutCreate . checkout . id ) ;
@@ -108,7 +109,7 @@ suite('client-checkout-integration-test', () => {
108
109
]
109
110
} ;
110
111
111
- fetchMock . postOnce ( apiUrl , checkoutUpdateAttributesV2Fixture ) ;
112
+ fetchMockPostOnce ( fetchMock , apiUrl , checkoutUpdateAttributesV2Fixture ) ;
112
113
113
114
return client . checkout . updateAttributes ( checkoutId , input ) . then ( ( checkout ) => {
114
115
assert . equal ( checkout . id , checkoutUpdateAttributesV2Fixture . data . checkoutAttributesUpdateV2 . checkout . id ) ;
@@ -124,7 +125,7 @@ suite('client-checkout-integration-test', () => {
124
125
note : 'Very long note'
125
126
} ;
126
127
127
- fetchMock . postOnce ( apiUrl , checkoutUpdateAttributesV2WithUserErrorsFixture ) ;
128
+ fetchMockPostOnce ( fetchMock , apiUrl , checkoutUpdateAttributesV2WithUserErrorsFixture ) ;
128
129
129
130
return client . checkout . updateAttributes ( checkoutId , input ) . then ( ( ) => {
130
131
assert . ok ( false , 'Promise should not resolve' ) ;
@@ -139,7 +140,7 @@ suite('client-checkout-integration-test', () => {
139
140
email : 'user@example.com'
140
141
} ;
141
142
142
- fetchMock . postOnce ( apiUrl , checkoutUpdateEmailV2Fixture ) ;
143
+ fetchMockPostOnce ( fetchMock , apiUrl , checkoutUpdateEmailV2Fixture ) ;
143
144
144
145
return client . checkout . updateEmail ( checkoutId , input ) . then ( ( checkout ) => {
145
146
assert . equal ( checkout . id , checkoutUpdateEmailV2Fixture . data . checkoutEmailUpdateV2 . checkout . id ) ;
@@ -151,7 +152,7 @@ suite('client-checkout-integration-test', () => {
151
152
test ( 'it resolve with user errors on Client.checkout#updateEmail when email is invalid' , ( ) => {
152
153
const checkoutId = checkoutUpdateEmailV2Fixture . data . checkoutEmailUpdateV2 . checkout . id ;
153
154
154
- fetchMock . postOnce ( apiUrl , checkoutUpdateEmailV2WithUserErrorsFixture ) ;
155
+ fetchMockPostOnce ( fetchMock , apiUrl , checkoutUpdateEmailV2WithUserErrorsFixture ) ;
155
156
156
157
return client . checkout . updateEmail ( checkoutId , { email : 'invalid-email' } ) . then ( ( ) => {
157
158
assert . ok ( false , 'Promise should not resolve' ) ;
@@ -167,7 +168,7 @@ suite('client-checkout-integration-test', () => {
167
168
{ variantId : 'id2' , quantity : 2 }
168
169
] ;
169
170
170
- fetchMock . postOnce ( apiUrl , checkoutLineItemsAddFixture ) ;
171
+ fetchMockPostOnce ( fetchMock , apiUrl , checkoutLineItemsAddFixture ) ;
171
172
172
173
return client . checkout . addLineItems ( checkoutId , lineItems ) . then ( ( checkout ) => {
173
174
assert . equal ( checkout . id , checkoutId ) ;
@@ -181,7 +182,7 @@ suite('client-checkout-integration-test', () => {
181
182
{ variantId : '' , quantity : 1 }
182
183
] ;
183
184
184
- fetchMock . postOnce ( apiUrl , checkoutLineItemsAddWithUserErrorsFixture ) ;
185
+ fetchMockPostOnce ( fetchMock , apiUrl , checkoutLineItemsAddWithUserErrorsFixture ) ;
185
186
186
187
return client . checkout . addLineItems ( checkoutId , lineItems ) . then ( ( ) => {
187
188
assert . ok ( false , 'Promise should not resolve' ) ;
@@ -197,7 +198,7 @@ suite('client-checkout-integration-test', () => {
197
198
{ variantId : 'id2' , quantity : 2 }
198
199
] ;
199
200
200
- fetchMock . postOnce ( apiUrl , checkoutLineItemsReplaceFixture ) ;
201
+ fetchMockPostOnce ( fetchMock , apiUrl , checkoutLineItemsReplaceFixture ) ;
201
202
202
203
return client . checkout . replaceLineItems ( checkoutId , lineItems ) . then ( ( checkout ) => {
203
204
assert . equal ( checkout . id , checkoutId ) ;
@@ -211,7 +212,7 @@ suite('client-checkout-integration-test', () => {
211
212
{ variantId : '' , quantity : 1 }
212
213
] ;
213
214
214
- fetchMock . postOnce ( apiUrl , checkoutLineItemsReplaceWithUserErrorsFixture ) ;
215
+ fetchMockPostOnce ( fetchMock , apiUrl , checkoutLineItemsReplaceWithUserErrorsFixture ) ;
215
216
216
217
return client . checkout . replaceLineItems ( checkoutId , lineItems ) . then ( ( ) => {
217
218
assert . ok ( false , 'Promise should not resolve' ) ;
@@ -230,7 +231,7 @@ suite('client-checkout-integration-test', () => {
230
231
}
231
232
] ;
232
233
233
- fetchMock . postOnce ( apiUrl , checkoutLineItemsUpdateFixture ) ;
234
+ fetchMockPostOnce ( fetchMock , apiUrl , checkoutLineItemsUpdateFixture ) ;
234
235
235
236
return client . checkout . updateLineItems ( checkoutId , lineItems ) . then ( ( checkout ) => {
236
237
assert . equal ( checkout . id , checkoutId ) ;
@@ -248,7 +249,7 @@ suite('client-checkout-integration-test', () => {
248
249
}
249
250
] ;
250
251
251
- fetchMock . postOnce ( apiUrl , checkoutLineItemsUpdateWithUserErrorsFixture ) ;
252
+ fetchMockPostOnce ( fetchMock , apiUrl , checkoutLineItemsUpdateWithUserErrorsFixture ) ;
252
253
253
254
return client . checkout . updateLineItems ( checkoutId , lineItems ) . then ( ( ) => {
254
255
assert . ok ( false , 'Promise should not resolve' ) ;
@@ -260,7 +261,7 @@ suite('client-checkout-integration-test', () => {
260
261
test ( 'it resolves with a checkout on Client.checkout#removeLineItems' , ( ) => {
261
262
const checkoutId = checkoutLineItemsRemoveFixture . data . checkoutLineItemsRemove . checkout . id ;
262
263
263
- fetchMock . postOnce ( apiUrl , checkoutLineItemsRemoveFixture ) ;
264
+ fetchMockPostOnce ( fetchMock , apiUrl , checkoutLineItemsRemoveFixture ) ;
264
265
265
266
return client . checkout . removeLineItems ( checkoutId , [ 'line-item-id' ] ) . then ( ( checkout ) => {
266
267
assert . equal ( checkout . id , checkoutId ) ;
@@ -271,7 +272,7 @@ suite('client-checkout-integration-test', () => {
271
272
test ( 'it resolves with user errors on Client.checkout#removeLineItems when line item is invalid' , ( ) => {
272
273
const checkoutId = checkoutLineItemsRemoveFixture . data . checkoutLineItemsRemove . checkout . id ;
273
274
274
- fetchMock . postOnce ( apiUrl , checkoutLineItemsRemoveWithUserErrorsFixture ) ;
275
+ fetchMockPostOnce ( fetchMock , apiUrl , checkoutLineItemsRemoveWithUserErrorsFixture ) ;
275
276
276
277
return client . checkout . removeLineItems ( checkoutId , [ 'invalid-line-item-id' ] ) . then ( ( ) => {
277
278
assert . ok ( false , 'Promise should not resolve' ) ;
@@ -284,7 +285,7 @@ suite('client-checkout-integration-test', () => {
284
285
const checkoutId = checkoutDiscountCodeApplyV2Fixture . data . checkoutDiscountCodeApplyV2 . checkout . id ;
285
286
const discountCode = 'TENPERCENTOFF' ;
286
287
287
- fetchMock . postOnce ( apiUrl , checkoutDiscountCodeApplyV2Fixture ) ;
288
+ fetchMockPostOnce ( fetchMock , apiUrl , checkoutDiscountCodeApplyV2Fixture ) ;
288
289
289
290
return client . checkout . addDiscount ( checkoutId , discountCode ) . then ( ( checkout ) => {
290
291
assert . equal ( checkout . id , checkoutId ) ;
@@ -314,7 +315,7 @@ suite('client-checkout-integration-test', () => {
314
315
}
315
316
} ;
316
317
317
- fetchMock . postOnce ( apiUrl , checkoutDiscountCodeApplyV2WithCheckoutUserErrorsFixture ) ;
318
+ fetchMockPostOnce ( fetchMock , apiUrl , checkoutDiscountCodeApplyV2WithCheckoutUserErrorsFixture ) ;
318
319
319
320
const checkoutId = checkoutDiscountCodeApplyV2Fixture . data . checkoutDiscountCodeApplyV2 . checkout . id ;
320
321
const discountCode = 'INVALIDCODE' ;
@@ -329,7 +330,7 @@ suite('client-checkout-integration-test', () => {
329
330
test ( 'it resolves with a checkout on Client.checkout#removeDiscount' , ( ) => {
330
331
const checkoutId = checkoutDiscountCodeRemoveFixture . data . checkoutDiscountCodeRemove . checkout . id ;
331
332
332
- fetchMock . postOnce ( apiUrl , checkoutDiscountCodeRemoveFixture ) ;
333
+ fetchMockPostOnce ( fetchMock , apiUrl , checkoutDiscountCodeRemoveFixture ) ;
333
334
334
335
return client . checkout . removeDiscount ( checkoutId ) . then ( ( checkout ) => {
335
336
assert . equal ( checkout . id , checkoutId ) ;
@@ -345,7 +346,7 @@ suite('client-checkout-integration-test', () => {
345
346
countryCode : shippingCountry
346
347
} = checkoutShippingAddressUpdateV2Fixture . data . checkoutShippingAddressUpdateV2 . checkout . shippingAddress ;
347
348
348
- fetchMock . postOnce ( apiUrl , checkoutShippingAddressUpdateV2Fixture ) ;
349
+ fetchMockPostOnce ( fetchMock , apiUrl , checkoutShippingAddressUpdateV2Fixture ) ;
349
350
350
351
return client . checkout . updateShippingAddress ( checkoutId , shippingAddress ) . then ( ( checkout ) => {
351
352
assert . equal ( checkout . id , checkoutId ) ;
@@ -359,7 +360,7 @@ suite('client-checkout-integration-test', () => {
359
360
test ( 'it resolves with user errors on Client.checkout#updateShippingAddress with invalid address' , ( ) => {
360
361
const checkoutId = checkoutShippingAddressUpdateV2Fixture . data . checkoutShippingAddressUpdateV2 . checkout . id ;
361
362
362
- fetchMock . postOnce ( apiUrl , checkoutShippingAdddressUpdateV2WithUserErrorsFixture ) ;
363
+ fetchMockPostOnce ( fetchMock , apiUrl , checkoutShippingAdddressUpdateV2WithUserErrorsFixture ) ;
363
364
364
365
return client . checkout . updateShippingAddress ( checkoutId , shippingAddress ) . then ( ( ) => {
365
366
assert . ok ( false , 'Promise should not resolve.' ) ;
@@ -377,9 +378,9 @@ suite('client-checkout-integration-test', () => {
377
378
]
378
379
} ;
379
380
380
- fetchMock . postOnce ( apiUrl , checkoutCreateWithPaginatedLineItemsFixture )
381
- . postOnce ( apiUrl , secondPageLineItemsFixture )
382
- . postOnce ( apiUrl , thirdPageLineItemsFixture ) ;
381
+ fetchMockPostOnce ( fetchMock , apiUrl , checkoutCreateWithPaginatedLineItemsFixture ) ;
382
+ fetchMockPostOnce ( fetchMock , apiUrl , secondPageLineItemsFixture ) ;
383
+ fetchMockPostOnce ( fetchMock , apiUrl , thirdPageLineItemsFixture ) ;
383
384
384
385
return client . checkout . create ( input ) . then ( ( ) => {
385
386
assert . ok ( fetchMock . done ( ) ) ;
@@ -411,7 +412,7 @@ suite('client-checkout-integration-test', () => {
411
412
]
412
413
} ;
413
414
414
- fetchMock . postOnce ( apiUrl , checkoutCreateWithUserErrorsFixture ) ;
415
+ fetchMockPostOnce ( fetchMock , apiUrl , checkoutCreateWithUserErrorsFixture ) ;
415
416
416
417
return client . checkout . create ( input ) . then ( ( ) => {
417
418
assert . ok ( false , 'Promise should not resolve' ) ;
@@ -432,7 +433,7 @@ suite('client-checkout-integration-test', () => {
432
433
]
433
434
} ;
434
435
435
- fetchMock . postOnce ( apiUrl , checkoutCreateWithUserErrorsFixture ) ;
436
+ fetchMockPostOnce ( fetchMock , apiUrl , checkoutCreateWithUserErrorsFixture ) ;
436
437
437
438
return client . checkout . create ( input ) . then ( ( ) => {
438
439
assert . ok ( false , 'Promise should not resolve' ) ;
@@ -452,9 +453,9 @@ suite('client-checkout-integration-test', () => {
452
453
]
453
454
} ;
454
455
455
- fetchMock . postOnce ( apiUrl , checkoutCreateWithPaginatedLineItemsFixture )
456
- . postOnce ( apiUrl , secondPageLineItemsFixture )
457
- . postOnce ( apiUrl , thirdPageLineItemsFixture ) ;
456
+ fetchMockPostOnce ( fetchMock , apiUrl , checkoutCreateWithPaginatedLineItemsFixture ) ;
457
+ fetchMockPostOnce ( fetchMock , apiUrl , secondPageLineItemsFixture ) ;
458
+ fetchMockPostOnce ( fetchMock , apiUrl , thirdPageLineItemsFixture ) ;
458
459
459
460
return client . checkout . create ( input ) . then ( ( checkout ) => {
460
461
assert . ok ( checkout . errors ) ;
0 commit comments