Skip to content

Commit

Permalink
Merge branch 'develop' into jimbo/webpack-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sirugh authored May 28, 2020
2 parents 86b7d6a + 841e669 commit 1f4a625
Show file tree
Hide file tree
Showing 43 changed files with 1,433 additions and 505 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ If you are looking for an issue to work on, visit our [backlog board][] and look

If you have any project questions, concerns, or contribution ideas, join our [#pwa slack channel][]!

### Community Maintainer
A community point of contact approved by the Core Team to help with project administration.

[![larsroettig-image]][larsroettig]
[![Jordaneisenburger-image]][Jordaneisenburger]

### Community contributors

The PWA Studio project welcomes all codebase and documentation contributions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

exports[`Should return correct shape 1`] = `
Object {
"currentSelectedPaymentMethod": "braintree",
"doneEditing": false,
"handlePaymentError": [Function],
"handlePaymentSuccess": [Function],
"hideEditModal": [Function],
"isEditModalHidden": true,
"isEditModalActive": false,
"isLoading": false,
"showEditModal": [Function],
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ Object {
"street2": "Apt 123",
},
"isBillingAddressSame": false,
"paymentNonce": "*****",
"isLoading": false,
"paymentNonce": Object {
"code": "braintree",
"title": "Braintree",
},
"selectedPaymentMethod": undefined,
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jest.mock('@apollo/react-hooks', () => {
useQuery: jest.fn().mockReturnValue({
data: {
cart: {
selectedPaymentMethod: { code: 'braintree' }
selected_payment_method: { code: 'braintree' }
}
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import React from 'react';
import { usePaymentInformation } from '../usePaymentInformation';
import createTestInstance from '../../../../util/createTestInstance';
import { useAppContext } from '../../../../context/app';
import { useQuery, useMutation } from '@apollo/react-hooks';
import { CHECKOUT_STEP } from '../../useCheckoutPage';

jest.mock('../../../../context/cart', () => ({
useCartContext: jest.fn().mockReturnValue([{ cartId: '123' }])
Expand All @@ -18,7 +20,34 @@ jest.mock('../../../../context/app', () => ({
}));

jest.mock('@apollo/react-hooks', () => {
return { useQuery: jest.fn() };
return {
useQuery: jest.fn().mockReturnValue({
data: {
cart: {
available_payment_methods: [{ code: 'braintree' }],
selected_payment_method: {},
shipping_addresses: [
{
firstname: 'I',
lastname: 'love',
street: ['graphql'],
city: 'it',
region: {
code: 'is'
},
postcode: 90210,
country: {
code: 'great'
},
telephone: 1234567890
}
]
}
},
loading: false
}),
useMutation: jest.fn().mockReturnValue([jest.fn(), { loading: false }])
};
});

jest.mock('informed', () => {
Expand All @@ -27,9 +56,18 @@ jest.mock('informed', () => {
};
});

const getPaymentDetailsQuery = 'getPaymentDetailsQuery';
const queries = {
getPaymentDetailsQuery
const defaultTalonProps = {
mutations: {
setFreePaymentMethodMutation: 'setFreePaymentMethodMutation',
setBillingAddressMutation: 'setBillingAddressMutation'
},
onSave: jest.fn(),
queries: {
getPaymentDetailsQuery: 'getPaymentDetailsQuery'
},
resetShouldSubmit: jest.fn(),
setCheckoutStep: jest.fn(),
shouldSubmit: false
};

const Component = props => {
Expand All @@ -52,7 +90,7 @@ const getTalonProps = props => {
};

test('Should return correct shape', () => {
const { talonProps } = getTalonProps({ queries });
const { talonProps } = getTalonProps({ ...defaultTalonProps });

expect(talonProps).toMatchSnapshot();
});
Expand All @@ -64,7 +102,7 @@ test('hideEditModal should call closeDrawer from app context', () => {
{ toggleDrawer: () => {}, closeDrawer }
]);

const { talonProps } = getTalonProps({ queries });
const { talonProps } = getTalonProps({ ...defaultTalonProps });

talonProps.hideEditModal();

Expand All @@ -78,9 +116,126 @@ test('showEditModal should call toggleDrawer from app context', () => {
{ closeDrawer: () => {}, toggleDrawer }
]);

const { talonProps } = getTalonProps({ queries });
const { talonProps } = getTalonProps({ ...defaultTalonProps });

talonProps.showEditModal();

expect(toggleDrawer).toHaveBeenCalledWith('edit.payment');
});

test('resets to payment step when selected method is not available', () => {
useQuery.mockReturnValueOnce({
data: {
cart: {
available_payment_methods: [{ code: 'braintree' }],
selected_payment_method: { code: 'free' },
shipping_addresses: {}
}
},
loading: false
});

createTestInstance(<Component {...defaultTalonProps} />);

expect(defaultTalonProps.resetShouldSubmit).toHaveBeenCalled();
expect(defaultTalonProps.setCheckoutStep).toHaveBeenCalledWith(
CHECKOUT_STEP.PAYMENT
);
});

test('selects the free payment method if available and not selected', () => {
const runMutation = jest.fn();

useMutation.mockReturnValueOnce([
runMutation,
{
loading: false
}
]);

useQuery.mockReturnValueOnce({
data: {
cart: {
available_payment_methods: [{ code: 'free' }],
selected_payment_method: { code: 'braintree' },
shipping_addresses: {}
}
},
loading: false
});

createTestInstance(<Component {...defaultTalonProps} />);

expect(runMutation).toHaveBeenCalled();
});

test('sets shipping address as billing address whenever "free" is selected', () => {
const setFreePaymentMethod = jest.fn();
const setBillingAddress = jest.fn();

useMutation
.mockReturnValueOnce([
setFreePaymentMethod,
{
loading: false
}
])
.mockReturnValueOnce([setBillingAddress]);

useQuery.mockReturnValueOnce({
data: {
cart: {
available_payment_methods: [{ code: 'free' }],
prices: {
grand_total: {
value: 10
}
},
selected_payment_method: { code: 'free' },
shipping_addresses: [
{
firstname: 'I',
lastname: 'love',
street: ['graphql'],
city: 'it',
region: {
code: 'is'
},
postcode: 90210,
country: {
code: 'great'
},
telephone: 1234567890
}
]
}
},
loading: false
});

createTestInstance(<Component {...defaultTalonProps} />);

expect(setBillingAddress).toHaveBeenCalled();
});

test('calls onSave if free is selected and available and shouldSubmit is true', () => {
useQuery.mockReturnValueOnce({
data: {
cart: {
available_payment_methods: [{ code: 'free' }],
selected_payment_method: { code: 'free' },
shipping_addresses: {}
}
},
loading: false
});

const newProps = {
...defaultTalonProps,
shouldSubmit: true
};

createTestInstance(<Component {...newProps} />);

expect(defaultTalonProps.onSave).toHaveBeenCalled();
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,25 @@ jest.mock('../../../../context/cart', () => ({
}));

jest.mock('@apollo/react-hooks', () => ({
useQuery: jest
.fn()
.mockReturnValueOnce({
data: {
cart: {
billingAddress: {
firstName: 'Goosey',
lastName: 'Goose',
country: { code: 'United States of Gooseland' },
street: ['12345 Gooseey Blvd', 'Apt 123'],
city: { code: 'Goostin' },
region: 'Gooseyork',
postalCode: '12345',
phoneNumber: '1234567890'
}
}
useQuery: jest.fn().mockReturnValueOnce({
loading: false,
data: {
cart: {
billingAddress: {
firstName: 'Goosey',
lastName: 'Goose',
country: { code: 'United States of Gooseland' },
street: ['12345 Gooseey Blvd', 'Apt 123'],
city: { code: 'Goostin' },
region: 'Gooseyork',
postalCode: '12345',
phoneNumber: '1234567890'
},
isBillingAddressSame: false,
paymentNonce: { code: 'braintree', title: 'Braintree' }
}
})
.mockReturnValueOnce({
data: {
cart: {
isBillingAddressSame: false
}
}
})
.mockReturnValueOnce({ data: { cart: { paymentNonce: '*****' } } })
.mockReturnValue()
}
})
}));

const Component = props => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,14 @@ export const useCreditCard = props => {
shouldSubmit,
resetShouldSubmit
} = props;

const {
getBillingAddressQuery,
getIsBillingAddressSameQuery,
getPaymentNonceQuery,
getShippingAddressQuery
} = queries;

const {
setBillingAddressMutation,
setCreditCardDetailsOnCartMutation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const useEditModal = props => {
}
);
const selectedPaymentMethod = selectedPaymentMethodData
? selectedPaymentMethodData.cart.selectedPaymentMethod.code
? selectedPaymentMethodData.cart.selected_payment_method.code
: null;

/**
Expand Down
Loading

0 comments on commit 1f4a625

Please # to comment.