Skip to content

Commit 44f40a9

Browse files
author
Luis Sanchez
committed
fix(order): CHECKOUT-3056 Store billing address state when order loads
1 parent ec7953b commit 44f40a9

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/billing/billing-address-reducer.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { getErrorResponse } from '../common/http-request/responses.mock';
77

88
import billingAddressReducer from './billing-address-reducer';
99
import BillingAddressState from './billing-address-state';
10+
import { OrderActionType } from '../order';
11+
import { getOrder } from '../order/orders.mock';
1012

1113
describe('billingAddressReducer', () => {
1214
let initialState: BillingAddressState;
@@ -26,6 +28,17 @@ describe('billingAddressReducer', () => {
2628
});
2729
});
2830

31+
it('returns billing address when order loads', () => {
32+
const action = createAction(OrderActionType.LoadOrderSucceeded, getOrder());
33+
const output = billingAddressReducer(initialState, action);
34+
35+
expect(output).toEqual({
36+
data: action.payload.billingAddress,
37+
errors: {},
38+
statuses: {},
39+
});
40+
});
41+
2942
it('returns loading state when checkout is requested', () => {
3043
const action = createAction(CheckoutActionType.LoadCheckoutRequested);
3144
const output = billingAddressReducer(initialState, action);

src/billing/billing-address-reducer.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { combineReducers } from '@bigcommerce/data-store';
22

33
import { Address } from '../address';
44
import { CheckoutAction, CheckoutActionType } from '../checkout';
5+
import { OrderAction, OrderActionType } from '../order';
56

67
import { BillingAddressAction, BillingAddressActionType } from './billing-address-actions';
78
import BillingAddressState, { BillingAddressErrorsState, BillingAddressStatusesState } from './billing-address-state';
@@ -13,9 +14,9 @@ const DEFAULT_STATE: BillingAddressState = {
1314

1415
export default function billingAddressReducer(
1516
state: BillingAddressState = DEFAULT_STATE,
16-
action: CheckoutAction
17+
action: CheckoutAction | BillingAddressAction | OrderAction
1718
): BillingAddressState {
18-
const reducer = combineReducers<BillingAddressState, CheckoutAction | BillingAddressAction>({
19+
const reducer = combineReducers<BillingAddressState, CheckoutAction | BillingAddressAction | OrderAction>({
1920
data: dataReducer,
2021
errors: errorsReducer,
2122
statuses: statusesReducer,
@@ -26,11 +27,12 @@ export default function billingAddressReducer(
2627

2728
function dataReducer(
2829
data: Address | undefined,
29-
action: CheckoutAction | BillingAddressAction
30+
action: CheckoutAction | BillingAddressAction | OrderAction
3031
): Address | undefined {
3132
switch (action.type) {
3233
case BillingAddressActionType.UpdateBillingAddressSucceeded:
3334
case CheckoutActionType.LoadCheckoutSucceeded:
35+
case OrderActionType.LoadOrderSucceeded:
3436
return action.payload ? action.payload.billingAddress : data;
3537

3638
default:
@@ -40,7 +42,7 @@ function dataReducer(
4042

4143
function errorsReducer(
4244
errors: BillingAddressErrorsState = DEFAULT_STATE.errors,
43-
action: CheckoutAction | BillingAddressAction
45+
action: CheckoutAction | BillingAddressAction | OrderAction
4446
): BillingAddressErrorsState {
4547
switch (action.type) {
4648
case CheckoutActionType.LoadCheckoutRequested:
@@ -64,7 +66,7 @@ function errorsReducer(
6466

6567
function statusesReducer(
6668
statuses: BillingAddressStatusesState = DEFAULT_STATE.statuses,
67-
action: CheckoutAction | BillingAddressAction
69+
action: CheckoutAction | BillingAddressAction | OrderAction
6870
): BillingAddressStatusesState {
6971
switch (action.type) {
7072
case CheckoutActionType.LoadCheckoutRequested:

0 commit comments

Comments
 (0)