Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move PriceSummaryFragment to peregrine #3007

Merged
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
const path = require('path');


/**
* `configureProject()` makes a config object for use in the `projects` array.
*
Expand Down Expand Up @@ -230,6 +231,8 @@ const jestConfig = {
})),
configureProject('pagebuilder', 'Pagebuilder', testReactComponents),
configureProject('peregrine', 'Peregrine', inPackage => ({
// Make sure we can test extension files.
moduleFileExtensions:['ee.js', 'ce.js', 'js', 'json', 'jsx', 'node'],
// Define global variables.
globals,
// Expose jsdom to tests.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { gql } from '@apollo/client';

export const DiscountSummaryFragment = gql`
fragment DiscountSummaryFragment on CartPrices {
discounts {
amount {
currency
value
}
label
}
}
`;
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { gql } from '@apollo/client';

import { DiscountSummaryFragment } from './discountSummary';
import { DiscountSummaryFragment } from './discountSummary.gql';
import { GiftCardSummaryFragment } from './queries/giftCardSummary';
import { ShippingSummaryFragment } from './shippingSummary';
import { TaxSummaryFragment } from './taxSummary';
import { ShippingSummaryFragment } from './shippingSummary.gql';
import { TaxSummaryFragment } from './taxSummary.gql';

export const GrandTotalFragment = gql`
fragment GrandTotalFragment on CartPrices {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { gql } from '@apollo/client';

export const GiftCardSummaryFragment = gql`
fragment GiftCardSummaryFragment on Cart {
id
__typename
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { gql } from '@apollo/client';

export const GiftCardSummaryFragment = gql`
fragment GiftCardSummaryFragment on Cart {
id
applied_gift_cards {
# code is "id" of the gift cards, used to merge cache data with incoming.
code
applied_balance {
value
currency
}
}
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { gql } from '@apollo/client';

export const ShippingSummaryFragment = gql`
fragment ShippingSummaryFragment on Cart {
id
shipping_addresses {
selected_shipping_method {
amount {
currency
value
}
}
street
}
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { gql } from '@apollo/client';

export const TaxSummaryFragment = gql`
fragment TaxSummaryFragment on CartPrices {
applied_taxes {
amount {
currency
value
}
}
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -108,25 +108,17 @@ const setCreditCardDetailsOnCartMutationResult = jest.fn().mockReturnValue([

const writeQuery = jest.fn();

const queries = {
const operations = {
getAllCountriesQuery,
getBillingAddressQuery,
getIsBillingAddressSameQuery,
getPaymentNonceQuery,
getShippingAddressQuery
};
const mutations = {
getShippingAddressQuery,
setBillingAddressMutation,
setCreditCardDetailsOnCartMutation
};

jest.mock('@apollo/client', () => {
return {
useQuery: jest.fn(),
useApolloClient: jest.fn(),
useMutation: jest.fn()
};
});
jest.mock('@apollo/client');

jest.mock('../../../../context/cart', () => ({
useCartContext: jest.fn().mockReturnValue([{ cartId: '123' }])
Expand Down Expand Up @@ -210,8 +202,7 @@ const getTalonProps = props => {
test('Should return correct shape', () => {
const { talonProps } = getTalonProps({
shouldSubmit: false,
queries,
mutations,
operations,
onSuccess: () => {},
onReady: () => {},
onError: () => {}
Expand All @@ -224,8 +215,7 @@ test('Shuold call onReady when payment is ready', () => {
const onReady = jest.fn();
const { talonProps } = getTalonProps({
shouldSubmit: false,
queries,
mutations,
operations,
onSuccess: () => {},
onReady,
onError: () => {}
Expand All @@ -243,8 +233,7 @@ test('Shuold call onError when payment nonce generation errored out', () => {

const { talonProps } = getTalonProps({
shouldSubmit: false,
queries,
mutations,
operations,
onSuccess: () => {},
onError,
onReady: () => {},
Expand Down Expand Up @@ -287,8 +276,7 @@ test('Should return errors from billing address and payment method mutations', (

const { talonProps } = getTalonProps({
shouldSubmit: false,
queries,
mutations,
operations,
onSuccess: () => {},
onError: () => {},
onReady: () => {},
Expand Down Expand Up @@ -332,8 +320,7 @@ test('Should return isBillingAddress and billingAddress from cache as initialVal

const { talonProps } = getTalonProps({
shouldSubmit: false,
queries,
mutations,
operations,
onSuccess: () => {},
onError: () => {},
onReady: () => {},
Expand Down Expand Up @@ -375,8 +362,7 @@ test('Should set billingAddress to {} if isBillingAddress is true in initialValu

const { talonProps } = getTalonProps({
shouldSubmit: false,
queries,
mutations,
operations,
onSuccess: () => {},
onError: () => {},
onReady: () => {},
Expand All @@ -391,8 +377,7 @@ test('Should set billingAddress to {} if isBillingAddress is true in initialValu
test('Should return isLoading true if isDropinLoading is true', () => {
const { talonProps } = getTalonProps({
shouldSubmit: false,
queries,
mutations,
operations,
onSuccess: () => {},
onError: () => {},
onReady: () => {},
Expand Down Expand Up @@ -433,8 +418,7 @@ describe('Testing payment nonce request workflow', () => {

getTalonProps({
shouldSubmit: true,
queries,
mutations,
operations,
onSuccess: () => {},
onReady: () => {},
onError: () => {},
Expand Down Expand Up @@ -484,8 +468,7 @@ describe('Testing payment nonce request workflow', () => {

getTalonProps({
shouldSubmit: true,
queries,
mutations,
operations,
onSuccess: () => {},
onReady: () => {},
onError: () => {},
Expand All @@ -511,8 +494,7 @@ describe('Testing payment nonce request workflow', () => {

getTalonProps({
shouldSubmit: true,
queries,
mutations,
operations,
onSuccess: () => {},
onReady: () => {},
onError: () => {},
Expand Down Expand Up @@ -540,8 +522,7 @@ describe('Testing payment nonce request workflow', () => {

getTalonProps({
shouldSubmit: true,
queries,
mutations,
operations,
onSuccess: () => {},
onReady: () => {},
onError: () => {},
Expand All @@ -564,8 +545,7 @@ describe('Testing payment success workflow', () => {
};
const { talonProps } = getTalonProps({
shouldSubmit: false,
queries,
mutations,
operations,
onSuccess: () => {},
onReady: () => {},
onError: () => {}
Expand All @@ -587,8 +567,7 @@ describe('Testing payment success workflow', () => {
test('Should call setCreditCardDetailsOnCartMutation on payment success', () => {
const { talonProps } = getTalonProps({
shouldSubmit: false,
queries,
mutations,
operations,
onSuccess: () => {},
onReady: () => {},
onError: () => {}
Expand Down Expand Up @@ -618,8 +597,7 @@ describe('Testing payment success workflow', () => {
const onSuccess = jest.fn();
const { talonProps } = getTalonProps({
shouldSubmit: false,
queries,
mutations,
operations,
onSuccess,
onReady: () => {},
onError: () => {},
Expand All @@ -644,8 +622,7 @@ describe('Testing payment success workflow', () => {
const onSuccess = jest.fn();
const { talonProps } = getTalonProps({
shouldSubmit: false,
queries,
mutations,
operations,
onSuccess,
onReady: () => {},
onError: () => {},
Expand All @@ -662,8 +639,7 @@ describe('Testing stepNumber', () => {
test('Should set stepNumber to 0 when onPaymentError is called', () => {
const { talonProps, update } = getTalonProps({
shouldSubmit: false,
queries,
mutations,
operations,
onSuccess: () => {},
onReady: () => {},
onError: () => {},
Expand All @@ -680,8 +656,7 @@ describe('Testing stepNumber', () => {
test('Should set stepNumber to 3 when onPaymentSuccess is called', () => {
const { talonProps, update } = getTalonProps({
shouldSubmit: false,
queries,
mutations,
operations,
onSuccess: () => {},
onReady: () => {},
onError: () => {}
Expand All @@ -698,8 +673,7 @@ describe('Testing stepNumber', () => {
test('Should set stepNumber to 0 when onPaymentReady is called', () => {
const { talonProps, update } = getTalonProps({
shouldSubmit: false,
queries,
mutations,
operations,
onSuccess: () => {},
onReady: () => {},
onError: () => {}
Expand All @@ -716,8 +690,7 @@ describe('Testing stepNumber', () => {
test('Should set stepNumber to 1 if shouldSubmit is set to true', () => {
const { talonProps } = getTalonProps({
shouldSubmit: true,
queries,
mutations,
operations,
onSuccess: () => {},
onReady: () => {},
onError: () => {}
Expand All @@ -739,8 +712,7 @@ describe('Testing stepNumber', () => {

const { talonProps } = getTalonProps({
shouldSubmit: false,
queries,
mutations,
operations,
onSuccess: () => {},
onReady: () => {},
onError: () => {}
Expand All @@ -764,8 +736,7 @@ describe('Testing stepNumber', () => {
const resetShouldSubmit = jest.fn();
const { talonProps } = getTalonProps({
shouldSubmit: false,
queries,
mutations,
operations,
onSuccess: () => {},
onReady: () => {},
onError: () => {},
Expand All @@ -789,8 +760,7 @@ describe('Testing stepNumber', () => {

const { talonProps } = getTalonProps({
shouldSubmit: false,
queries,
mutations,
operations,
onSuccess: () => {},
onReady: () => {},
onError: () => {},
Expand All @@ -814,8 +784,7 @@ describe('Testing stepNumber', () => {
const resetShouldSubmit = jest.fn();
const { talonProps } = getTalonProps({
shouldSubmit: false,
queries,
mutations,
operations,
onSuccess: () => {},
onReady: () => {},
onError: () => {},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { gql } from '@apollo/client';

import { PriceSummaryFragment } from '../../CartPage/PriceSummary/priceSummaryFragments';
import { PriceSummaryFragment } from '../../CartPage/PriceSummary/priceSummaryFragments.gql';
import { AvailablePaymentMethodsFragment } from './paymentInformation.gql';

// We disable linting for local fields because there is no way to add them to
Expand Down Expand Up @@ -156,14 +156,10 @@ export const SET_CC_DETAILS_ON_CART = gql`
`;

export default {
queries: {
getBillingAddressQuery: GET_BILLING_ADDRESS,
getIsBillingAddressSameQuery: GET_IS_BILLING_ADDRESS_SAME,
getPaymentNonceQuery: GET_PAYMENT_NONCE,
getShippingAddressQuery: GET_SHIPPING_ADDRESS
},
mutations: {
setBillingAddressMutation: SET_BILLING_ADDRESS,
setCreditCardDetailsOnCartMutation: SET_CC_DETAILS_ON_CART
}
getBillingAddressQuery: GET_BILLING_ADDRESS,
getIsBillingAddressSameQuery: GET_IS_BILLING_ADDRESS_SAME,
getPaymentNonceQuery: GET_PAYMENT_NONCE,
getShippingAddressQuery: GET_SHIPPING_ADDRESS,
setBillingAddressMutation: SET_BILLING_ADDRESS,
setCreditCardDetailsOnCartMutation: SET_CC_DETAILS_ON_CART
};
Loading