Skip to content

Commit

Permalink
Merge pull request #193 from davidchin/fix_billing_address
Browse files Browse the repository at this point in the history
CHECKOUT-4421: Make customer and billing address objects not mandatory for customer component
  • Loading branch information
davidchin authored Dec 16, 2019
2 parents c5f827d + 9c57787 commit 577988d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"homepage": "https://github.com/bigcommerce/checkout-js#readme",
"dependencies": {
"@bigcommerce/checkout-sdk": "^1.46.0",
"@bigcommerce/checkout-sdk": "^1.46.1",
"@bigcommerce/citadel": "^2.15.1",
"@bigcommerce/form-poster": "^1.2.2",
"@bigcommerce/memoize": "^1.0.0",
Expand Down
24 changes: 24 additions & 0 deletions src/app/customer/Customer.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,30 @@ describe('Customer', () => {
.toEqual(true);
});

it('renders guest form if billing address is undefined', () => {
jest.spyOn(checkoutService.getState().data, 'getBillingAddress')
.mockReturnValue(undefined);

const component = mount(
<CustomerTest viewType={ CustomerViewType.Guest } />
);

expect(component.find(GuestForm).exists())
.toEqual(true);
});

it('renders guest form if customer is undefined', () => {
jest.spyOn(checkoutService.getState().data, 'getCustomer')
.mockReturnValue(undefined);

const component = mount(
<CustomerTest viewType={ CustomerViewType.Guest } />
);

expect(component.find(GuestForm).exists())
.toEqual(true);
});

it('passes data to guest form', () => {
const component = mount(
<CustomerTest viewType={ CustomerViewType.Guest } />
Expand Down
6 changes: 3 additions & 3 deletions src/app/customer/Customer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export function mapToWithCheckoutCustomerProps(
const customer = getCustomer();
const config = getConfig();

if (!billingAddress || !checkout || !customer || !config) {
if (!checkout || !config) {
return null;
}

Expand All @@ -213,8 +213,8 @@ export function mapToWithCheckoutCustomerProps(
createAccountUrl: config.links.createAccountLink,
defaultShouldSubscribe: config.shopperConfig.defaultNewsletterSignup,
deinitializeCustomer: checkoutService.deinitializeCustomer,
email: billingAddress.email || customer.email,
firstName: customer.firstName,
email: (billingAddress && billingAddress.email) || (customer && customer.email),
firstName: customer && customer.firstName,
forgotPasswordUrl: config.links.forgotPasswordLink,
initializeCustomer: checkoutService.initializeCustomer,
isContinuingAsGuest: isContinuingAsGuest(),
Expand Down

0 comments on commit 577988d

Please sign in to comment.