Skip to content

Commit 3672098

Browse files
Test helper for fixtures
1 parent 21fdc34 commit 3672098

4 files changed

+80
-52
lines changed

test/client-checkout-integration-test.js

+29-28
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import assert from 'assert';
22
import Client from '../src/client';
33
import fetchMock from './isomorphic-fetch-mock'; // eslint-disable-line import/no-unresolved
4+
import fetchMockPostOnce from './fetch-mock-helper';
45

56
// fixtures
67
import checkoutFixture from '../fixtures/checkout-fixture';
@@ -57,7 +58,7 @@ suite('client-checkout-integration-test', () => {
5758
});
5859

5960
test('it resolves with a checkout on Client.checkout#fetch', () => {
60-
fetchMock.postOnce(apiUrl, checkoutFixture);
61+
fetchMockPostOnce(fetchMock, apiUrl, checkoutFixture);
6162

6263
const checkoutId = checkoutFixture.data.node.id;
6364

@@ -68,7 +69,7 @@ suite('client-checkout-integration-test', () => {
6869
});
6970

7071
test('it resolves with null on Client.checkout#fetch for a bad checkoutId', () => {
71-
fetchMock.postOnce(apiUrl, checkoutNullFixture);
72+
fetchMockPostOnce(fetchMock, apiUrl, checkoutNullFixture);
7273

7374
const checkoutId = checkoutFixture.data.node.id;
7475

@@ -89,7 +90,7 @@ suite('client-checkout-integration-test', () => {
8990
shippingAddress: {}
9091
};
9192

92-
fetchMock.postOnce(apiUrl, checkoutCreateFixture);
93+
fetchMockPostOnce(fetchMock, apiUrl, checkoutCreateFixture);
9394

9495
return client.checkout.create(input).then((checkout) => {
9596
assert.equal(checkout.id, checkoutCreateFixture.data.checkoutCreate.checkout.id);
@@ -108,7 +109,7 @@ suite('client-checkout-integration-test', () => {
108109
]
109110
};
110111

111-
fetchMock.postOnce(apiUrl, checkoutUpdateAttributesV2Fixture);
112+
fetchMockPostOnce(fetchMock, apiUrl, checkoutUpdateAttributesV2Fixture);
112113

113114
return client.checkout.updateAttributes(checkoutId, input).then((checkout) => {
114115
assert.equal(checkout.id, checkoutUpdateAttributesV2Fixture.data.checkoutAttributesUpdateV2.checkout.id);
@@ -124,7 +125,7 @@ suite('client-checkout-integration-test', () => {
124125
note: 'Very long note'
125126
};
126127

127-
fetchMock.postOnce(apiUrl, checkoutUpdateAttributesV2WithUserErrorsFixture);
128+
fetchMockPostOnce(fetchMock, apiUrl, checkoutUpdateAttributesV2WithUserErrorsFixture);
128129

129130
return client.checkout.updateAttributes(checkoutId, input).then(() => {
130131
assert.ok(false, 'Promise should not resolve');
@@ -139,7 +140,7 @@ suite('client-checkout-integration-test', () => {
139140
email: 'user@example.com'
140141
};
141142

142-
fetchMock.postOnce(apiUrl, checkoutUpdateEmailV2Fixture);
143+
fetchMockPostOnce(fetchMock, apiUrl, checkoutUpdateEmailV2Fixture);
143144

144145
return client.checkout.updateEmail(checkoutId, input).then((checkout) => {
145146
assert.equal(checkout.id, checkoutUpdateEmailV2Fixture.data.checkoutEmailUpdateV2.checkout.id);
@@ -151,7 +152,7 @@ suite('client-checkout-integration-test', () => {
151152
test('it resolve with user errors on Client.checkout#updateEmail when email is invalid', () => {
152153
const checkoutId = checkoutUpdateEmailV2Fixture.data.checkoutEmailUpdateV2.checkout.id;
153154

154-
fetchMock.postOnce(apiUrl, checkoutUpdateEmailV2WithUserErrorsFixture);
155+
fetchMockPostOnce(fetchMock, apiUrl, checkoutUpdateEmailV2WithUserErrorsFixture);
155156

156157
return client.checkout.updateEmail(checkoutId, {email: 'invalid-email'}).then(() => {
157158
assert.ok(false, 'Promise should not resolve');
@@ -167,7 +168,7 @@ suite('client-checkout-integration-test', () => {
167168
{variantId: 'id2', quantity: 2}
168169
];
169170

170-
fetchMock.postOnce(apiUrl, checkoutLineItemsAddFixture);
171+
fetchMockPostOnce(fetchMock, apiUrl, checkoutLineItemsAddFixture);
171172

172173
return client.checkout.addLineItems(checkoutId, lineItems).then((checkout) => {
173174
assert.equal(checkout.id, checkoutId);
@@ -181,7 +182,7 @@ suite('client-checkout-integration-test', () => {
181182
{variantId: '', quantity: 1}
182183
];
183184

184-
fetchMock.postOnce(apiUrl, checkoutLineItemsAddWithUserErrorsFixture);
185+
fetchMockPostOnce(fetchMock, apiUrl, checkoutLineItemsAddWithUserErrorsFixture);
185186

186187
return client.checkout.addLineItems(checkoutId, lineItems).then(() => {
187188
assert.ok(false, 'Promise should not resolve');
@@ -197,7 +198,7 @@ suite('client-checkout-integration-test', () => {
197198
{variantId: 'id2', quantity: 2}
198199
];
199200

200-
fetchMock.postOnce(apiUrl, checkoutLineItemsReplaceFixture);
201+
fetchMockPostOnce(fetchMock, apiUrl, checkoutLineItemsReplaceFixture);
201202

202203
return client.checkout.replaceLineItems(checkoutId, lineItems).then((checkout) => {
203204
assert.equal(checkout.id, checkoutId);
@@ -211,7 +212,7 @@ suite('client-checkout-integration-test', () => {
211212
{variantId: '', quantity: 1}
212213
];
213214

214-
fetchMock.postOnce(apiUrl, checkoutLineItemsReplaceWithUserErrorsFixture);
215+
fetchMockPostOnce(fetchMock, apiUrl, checkoutLineItemsReplaceWithUserErrorsFixture);
215216

216217
return client.checkout.replaceLineItems(checkoutId, lineItems).then(() => {
217218
assert.ok(false, 'Promise should not resolve');
@@ -230,7 +231,7 @@ suite('client-checkout-integration-test', () => {
230231
}
231232
];
232233

233-
fetchMock.postOnce(apiUrl, checkoutLineItemsUpdateFixture);
234+
fetchMockPostOnce(fetchMock, apiUrl, checkoutLineItemsUpdateFixture);
234235

235236
return client.checkout.updateLineItems(checkoutId, lineItems).then((checkout) => {
236237
assert.equal(checkout.id, checkoutId);
@@ -248,7 +249,7 @@ suite('client-checkout-integration-test', () => {
248249
}
249250
];
250251

251-
fetchMock.postOnce(apiUrl, checkoutLineItemsUpdateWithUserErrorsFixture);
252+
fetchMockPostOnce(fetchMock, apiUrl, checkoutLineItemsUpdateWithUserErrorsFixture);
252253

253254
return client.checkout.updateLineItems(checkoutId, lineItems).then(() => {
254255
assert.ok(false, 'Promise should not resolve');
@@ -260,7 +261,7 @@ suite('client-checkout-integration-test', () => {
260261
test('it resolves with a checkout on Client.checkout#removeLineItems', () => {
261262
const checkoutId = checkoutLineItemsRemoveFixture.data.checkoutLineItemsRemove.checkout.id;
262263

263-
fetchMock.postOnce(apiUrl, checkoutLineItemsRemoveFixture);
264+
fetchMockPostOnce(fetchMock, apiUrl, checkoutLineItemsRemoveFixture);
264265

265266
return client.checkout.removeLineItems(checkoutId, ['line-item-id']).then((checkout) => {
266267
assert.equal(checkout.id, checkoutId);
@@ -271,7 +272,7 @@ suite('client-checkout-integration-test', () => {
271272
test('it resolves with user errors on Client.checkout#removeLineItems when line item is invalid', () => {
272273
const checkoutId = checkoutLineItemsRemoveFixture.data.checkoutLineItemsRemove.checkout.id;
273274

274-
fetchMock.postOnce(apiUrl, checkoutLineItemsRemoveWithUserErrorsFixture);
275+
fetchMockPostOnce(fetchMock, apiUrl, checkoutLineItemsRemoveWithUserErrorsFixture);
275276

276277
return client.checkout.removeLineItems(checkoutId, ['invalid-line-item-id']).then(() => {
277278
assert.ok(false, 'Promise should not resolve');
@@ -284,7 +285,7 @@ suite('client-checkout-integration-test', () => {
284285
const checkoutId = checkoutDiscountCodeApplyV2Fixture.data.checkoutDiscountCodeApplyV2.checkout.id;
285286
const discountCode = 'TENPERCENTOFF';
286287

287-
fetchMock.postOnce(apiUrl, checkoutDiscountCodeApplyV2Fixture);
288+
fetchMockPostOnce(fetchMock, apiUrl, checkoutDiscountCodeApplyV2Fixture);
288289

289290
return client.checkout.addDiscount(checkoutId, discountCode).then((checkout) => {
290291
assert.equal(checkout.id, checkoutId);
@@ -314,7 +315,7 @@ suite('client-checkout-integration-test', () => {
314315
}
315316
};
316317

317-
fetchMock.postOnce(apiUrl, checkoutDiscountCodeApplyV2WithCheckoutUserErrorsFixture);
318+
fetchMockPostOnce(fetchMock, apiUrl, checkoutDiscountCodeApplyV2WithCheckoutUserErrorsFixture);
318319

319320
const checkoutId = checkoutDiscountCodeApplyV2Fixture.data.checkoutDiscountCodeApplyV2.checkout.id;
320321
const discountCode = 'INVALIDCODE';
@@ -329,7 +330,7 @@ suite('client-checkout-integration-test', () => {
329330
test('it resolves with a checkout on Client.checkout#removeDiscount', () => {
330331
const checkoutId = checkoutDiscountCodeRemoveFixture.data.checkoutDiscountCodeRemove.checkout.id;
331332

332-
fetchMock.postOnce(apiUrl, checkoutDiscountCodeRemoveFixture);
333+
fetchMockPostOnce(fetchMock, apiUrl, checkoutDiscountCodeRemoveFixture);
333334

334335
return client.checkout.removeDiscount(checkoutId).then((checkout) => {
335336
assert.equal(checkout.id, checkoutId);
@@ -345,7 +346,7 @@ suite('client-checkout-integration-test', () => {
345346
countryCode: shippingCountry
346347
} = checkoutShippingAddressUpdateV2Fixture.data.checkoutShippingAddressUpdateV2.checkout.shippingAddress;
347348

348-
fetchMock.postOnce(apiUrl, checkoutShippingAddressUpdateV2Fixture);
349+
fetchMockPostOnce(fetchMock, apiUrl, checkoutShippingAddressUpdateV2Fixture);
349350

350351
return client.checkout.updateShippingAddress(checkoutId, shippingAddress).then((checkout) => {
351352
assert.equal(checkout.id, checkoutId);
@@ -359,7 +360,7 @@ suite('client-checkout-integration-test', () => {
359360
test('it resolves with user errors on Client.checkout#updateShippingAddress with invalid address', () => {
360361
const checkoutId = checkoutShippingAddressUpdateV2Fixture.data.checkoutShippingAddressUpdateV2.checkout.id;
361362

362-
fetchMock.postOnce(apiUrl, checkoutShippingAdddressUpdateV2WithUserErrorsFixture);
363+
fetchMockPostOnce(fetchMock, apiUrl, checkoutShippingAdddressUpdateV2WithUserErrorsFixture);
363364

364365
return client.checkout.updateShippingAddress(checkoutId, shippingAddress).then(() => {
365366
assert.ok(false, 'Promise should not resolve.');
@@ -377,9 +378,9 @@ suite('client-checkout-integration-test', () => {
377378
]
378379
};
379380

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);
383384

384385
return client.checkout.create(input).then(() => {
385386
assert.ok(fetchMock.done());
@@ -411,7 +412,7 @@ suite('client-checkout-integration-test', () => {
411412
]
412413
};
413414

414-
fetchMock.postOnce(apiUrl, checkoutCreateWithUserErrorsFixture);
415+
fetchMockPostOnce(fetchMock, apiUrl, checkoutCreateWithUserErrorsFixture);
415416

416417
return client.checkout.create(input).then(() => {
417418
assert.ok(false, 'Promise should not resolve');
@@ -432,7 +433,7 @@ suite('client-checkout-integration-test', () => {
432433
]
433434
};
434435

435-
fetchMock.postOnce(apiUrl, checkoutCreateWithUserErrorsFixture);
436+
fetchMockPostOnce(fetchMock, apiUrl, checkoutCreateWithUserErrorsFixture);
436437

437438
return client.checkout.create(input).then(() => {
438439
assert.ok(false, 'Promise should not resolve');
@@ -452,9 +453,9 @@ suite('client-checkout-integration-test', () => {
452453
]
453454
};
454455

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);
458459

459460
return client.checkout.create(input).then((checkout) => {
460461
assert.ok(checkout.errors);

0 commit comments

Comments
 (0)