Skip to content

Commit 6d17003

Browse files
committed
feat(core): CHECKOUT-9513 Pass in initial state to avoid request waterfall
1 parent de84abd commit 6d17003

File tree

17 files changed

+470
-408
lines changed

17 files changed

+470
-408
lines changed

.circleci/config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,9 @@ workflows:
243243
<<: *pull_request_filter
244244
requires:
245245
- build-prerelease
246-
- sdk-on-cdn:
247-
filters:
248-
<<: *pull_request_filter
246+
# - sdk-on-cdn:
247+
# filters:
248+
# <<: *pull_request_filter
249249
- security/scan:
250250
name: "Gitleaks secrets scan"
251251
filters:

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"prettier": "@bigcommerce/eslint-config/prettier",
4949
"homepage": "https://github.com/bigcommerce/checkout-js#readme",
5050
"dependencies": {
51-
"@bigcommerce/checkout-sdk": "^1.802.0",
51+
"@bigcommerce/checkout-sdk": "github:bigcommerce/checkout-sdk-js#ebd940f321bed459b41b8fa7c493a119f26af84a",
5252
"@bigcommerce/citadel": "^2.15.1",
5353
"@bigcommerce/form-poster": "^1.2.2",
5454
"@bigcommerce/memoize": "^1.0.0",

packages/core/src/app/billing/Billing.test.tsx

Lines changed: 62 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
type BillingAddress,
3+
type CheckoutInitialState,
34
type CheckoutService,
45
createCheckoutService,
56
createEmbeddedCheckoutMessenger,
@@ -23,12 +24,14 @@ import {
2324
import {
2425
CheckoutPageNodeObject,
2526
CheckoutPreset,
27+
checkoutSettings,
2628
checkoutWithBillingEmail,
2729
checkoutWithDigitalCart,
2830
checkoutWithShipping,
2931
checkoutWithShippingAndBilling,
3032
consignment,
3133
customer,
34+
formFields,
3235
payments,
3336
shippingAddress,
3437
shippingAddress2,
@@ -128,7 +131,9 @@ describe('Billing step', () => {
128131
});
129132

130133
it('completes the billing step as a guest and goes to the payment step', async () => {
131-
checkout.use(CheckoutPreset.CheckoutWithShipping);
134+
checkoutService = checkout.use(CheckoutPreset.CheckoutWithShipping);
135+
136+
jest.spyOn(checkoutService, 'updateBillingAddress');
132137

133138
render(<CheckoutTest {...defaultProps} />);
134139

@@ -153,7 +158,9 @@ describe('Billing step', () => {
153158
});
154159

155160
it('edit the billing address and goes back to the payment step', async () => {
156-
checkout.use(CheckoutPreset.CheckoutWithShippingAndBilling);
161+
checkoutService = checkout.use(CheckoutPreset.CheckoutWithShippingAndBilling);
162+
163+
jest.spyOn(checkoutService, 'updateBillingAddress');
157164

158165
render(<CheckoutTest {...defaultProps} />);
159166

@@ -186,14 +193,16 @@ describe('Billing step', () => {
186193
});
187194

188195
it('should show order comments', async () => {
189-
checkout.updateCheckout(
190-
'get',
191-
'/checkout/*',
192-
{
193-
...checkoutWithBillingEmail,
194-
cart: checkoutWithDigitalCart.cart,
196+
checkoutService = createCheckoutService({
197+
initialState: {
198+
config: checkoutSettings,
199+
checkout: {
200+
...checkoutWithBillingEmail,
201+
cart: checkoutWithDigitalCart.cart,
202+
},
203+
formFields,
195204
},
196-
);
205+
});
197206

198207
render(<CheckoutTest {...defaultProps} />);
199208

@@ -203,17 +212,19 @@ describe('Billing step', () => {
203212
});
204213

205214
it('should show PoweredByPayPalFastlaneLabel', async () => {
206-
checkout.updateCheckout(
207-
'get',
208-
'/checkout/*',
209-
{
210-
...checkoutWithShipping,
211-
billingAddress:checkoutWithBillingEmail.billingAddress,
212-
payments:[
213-
getCheckoutPayment(),
214-
],
215+
checkoutService = createCheckoutService({
216+
initialState: {
217+
config: checkoutSettings,
218+
checkout: {
219+
...checkoutWithShipping,
220+
billingAddress:checkoutWithBillingEmail.billingAddress,
221+
payments:[
222+
getCheckoutPayment(),
223+
],
224+
},
225+
formFields,
215226
},
216-
);
227+
});
217228

218229
render(<CheckoutTest {...defaultProps} />);
219230

@@ -223,11 +234,9 @@ describe('Billing step', () => {
223234
});
224235

225236
it('should show PoweredByPayPalFastlaneLabel and custom form fields', async () => {
226-
checkout.use(CheckoutPreset.CheckoutWithBillingEmailAndCustomFormFields);
227-
checkout.updateCheckout(
228-
'get',
229-
'/checkout/*',
230-
{
237+
checkoutService = checkout.use(CheckoutPreset.CheckoutWithBillingEmailAndCustomFormFields, {
238+
config: checkoutSettings,
239+
checkout: {
231240
...checkoutWithShipping,
232241
billingAddress:checkoutWithBillingEmail.billingAddress,
233242
consignments: [
@@ -273,7 +282,8 @@ describe('Billing step', () => {
273282
getCheckoutPayment(),
274283
],
275284
},
276-
);
285+
formFields,
286+
});
277287

278288
render(<CheckoutTest {...defaultProps} />);
279289

@@ -292,11 +302,15 @@ describe('Billing step', () => {
292302

293303
describe('registered customer', () => {
294304
it('completes the billing step after selecting a valid address', async () => {
295-
checkout.updateCheckout(
296-
'get',
297-
'/checkout/*',
298-
checkoutWithCustomer
299-
);
305+
checkoutService = createCheckoutService({
306+
initialState: {
307+
config: checkoutSettings,
308+
checkout: checkoutWithCustomer,
309+
formFields,
310+
},
311+
});
312+
313+
jest.spyOn(checkoutService, 'updateBillingAddress');
300314

301315
render(<CheckoutTest {...defaultProps} />);
302316

@@ -354,11 +368,15 @@ describe('Billing step', () => {
354368
phone: shippingAddress3.phone,
355369
} as BillingAddress;
356370

357-
checkout.updateCheckout(
358-
'get',
359-
'/checkout/*',
360-
checkoutWithCustomer
361-
);
371+
checkoutService = createCheckoutService({
372+
initialState: {
373+
config: checkoutSettings,
374+
checkout: checkoutWithCustomer,
375+
formFields,
376+
},
377+
});
378+
379+
jest.spyOn(checkoutService, 'updateBillingAddress');
362380

363381
render(<CheckoutTest {...defaultProps} />);
364382

@@ -405,11 +423,15 @@ describe('Billing step', () => {
405423
});
406424

407425
it('completes the billing step after creating a new address even with existing addresses', async () => {
408-
checkout.updateCheckout(
409-
'get',
410-
'/checkout/*',
411-
checkoutWithCustomer
412-
);
426+
checkoutService = createCheckoutService({
427+
initialState: {
428+
config: checkoutSettings,
429+
checkout: checkoutWithCustomer,
430+
formFields,
431+
},
432+
});
433+
434+
jest.spyOn(checkoutService, 'updateBillingAddress');
413435

414436
render(<CheckoutTest {...defaultProps} />);
415437

0 commit comments

Comments
 (0)