From bb4a278e922f1a64c1fedc84dc24e7d5607e2859 Mon Sep 17 00:00:00 2001 From: Lars Date: Wed, 10 Feb 2021 22:31:31 +0100 Subject: [PATCH 01/10] wip --- .../PriceSummary/discountSummary.gql.js | 15 ++ .../PriceSummary/priceSummaryFragments.gql.js | 41 ++++++ .../queries/giftCardSummary.ce.js | 8 ++ .../queries/giftCardSummary.ee.js | 15 ++ .../PriceSummary/shippingSummary.gql.js | 18 +++ .../CartPage/PriceSummary/taxSummary.gql.js | 14 ++ .../PaymentInformation/creditCard.gql.js | 20 ++- .../paymentInformation.gql.js | 135 ++++++++++++++++++ .../PaymentInformation/useCreditCard.js | 23 ++- .../PaymentInformation/creditCard.js | 5 +- 10 files changed, 266 insertions(+), 28 deletions(-) create mode 100644 packages/peregrine/lib/talons/CartPage/PriceSummary/discountSummary.gql.js create mode 100644 packages/peregrine/lib/talons/CartPage/PriceSummary/priceSummaryFragments.gql.js create mode 100644 packages/peregrine/lib/talons/CartPage/PriceSummary/queries/giftCardSummary.ce.js create mode 100644 packages/peregrine/lib/talons/CartPage/PriceSummary/queries/giftCardSummary.ee.js create mode 100644 packages/peregrine/lib/talons/CartPage/PriceSummary/shippingSummary.gql.js create mode 100644 packages/peregrine/lib/talons/CartPage/PriceSummary/taxSummary.gql.js rename packages/{venia-ui/lib/components => peregrine/lib/talons}/CheckoutPage/PaymentInformation/creditCard.gql.js (89%) create mode 100644 packages/peregrine/lib/talons/CheckoutPage/PaymentInformation/paymentInformation.gql.js diff --git a/packages/peregrine/lib/talons/CartPage/PriceSummary/discountSummary.gql.js b/packages/peregrine/lib/talons/CartPage/PriceSummary/discountSummary.gql.js new file mode 100644 index 0000000000..f4a0527a81 --- /dev/null +++ b/packages/peregrine/lib/talons/CartPage/PriceSummary/discountSummary.gql.js @@ -0,0 +1,15 @@ +import { gql } from '@apollo/client'; + +export const DiscountSummaryFragment = gql` + fragment DiscountSummaryFragment on CartPrices { + discounts { + amount { + currency + value + } + label + } + } +`; + +export default DiscountSummary; diff --git a/packages/peregrine/lib/talons/CartPage/PriceSummary/priceSummaryFragments.gql.js b/packages/peregrine/lib/talons/CartPage/PriceSummary/priceSummaryFragments.gql.js new file mode 100644 index 0000000000..7e3677e105 --- /dev/null +++ b/packages/peregrine/lib/talons/CartPage/PriceSummary/priceSummaryFragments.gql.js @@ -0,0 +1,41 @@ +import { gql } from '@apollo/client'; + +import { DiscountSummaryFragment } from './discountSummary.gql'; +import { GiftCardSummaryFragment } from './queries/giftCardSummary'; +import { ShippingSummaryFragment } from './shippingSummary.gql'; +import { TaxSummaryFragment } from './taxSummary.gql'; + +export const GrandTotalFragment = gql` + fragment GrandTotalFragment on CartPrices { + grand_total { + currency + value + } + } +`; + +export const PriceSummaryFragment = gql` + fragment PriceSummaryFragment on Cart { + id + items { + id + quantity + } + ...ShippingSummaryFragment + prices { + ...TaxSummaryFragment + ...DiscountSummaryFragment + ...GrandTotalFragment + subtotal_excluding_tax { + currency + value + } + } + ...GiftCardSummaryFragment + } + ${DiscountSummaryFragment} + ${GiftCardSummaryFragment} + ${GrandTotalFragment} + ${ShippingSummaryFragment} + ${TaxSummaryFragment} +`; diff --git a/packages/peregrine/lib/talons/CartPage/PriceSummary/queries/giftCardSummary.ce.js b/packages/peregrine/lib/talons/CartPage/PriceSummary/queries/giftCardSummary.ce.js new file mode 100644 index 0000000000..53e757f048 --- /dev/null +++ b/packages/peregrine/lib/talons/CartPage/PriceSummary/queries/giftCardSummary.ce.js @@ -0,0 +1,8 @@ +import { gql } from '@apollo/client'; + +export const GiftCardSummaryFragment = gql` + fragment GiftCardSummaryFragment on Cart { + id + __typename + } +`; diff --git a/packages/peregrine/lib/talons/CartPage/PriceSummary/queries/giftCardSummary.ee.js b/packages/peregrine/lib/talons/CartPage/PriceSummary/queries/giftCardSummary.ee.js new file mode 100644 index 0000000000..3e7495f7af --- /dev/null +++ b/packages/peregrine/lib/talons/CartPage/PriceSummary/queries/giftCardSummary.ee.js @@ -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 + } + } + } +`; diff --git a/packages/peregrine/lib/talons/CartPage/PriceSummary/shippingSummary.gql.js b/packages/peregrine/lib/talons/CartPage/PriceSummary/shippingSummary.gql.js new file mode 100644 index 0000000000..2dfe4af474 --- /dev/null +++ b/packages/peregrine/lib/talons/CartPage/PriceSummary/shippingSummary.gql.js @@ -0,0 +1,18 @@ +import { gql } from '@apollo/client'; + +export const ShippingSummaryFragment = gql` + fragment ShippingSummaryFragment on Cart { + id + shipping_addresses { + selected_shipping_method { + amount { + currency + value + } + } + street + } + } +`; + +export default ShippingSummary; diff --git a/packages/peregrine/lib/talons/CartPage/PriceSummary/taxSummary.gql.js b/packages/peregrine/lib/talons/CartPage/PriceSummary/taxSummary.gql.js new file mode 100644 index 0000000000..223f396fed --- /dev/null +++ b/packages/peregrine/lib/talons/CartPage/PriceSummary/taxSummary.gql.js @@ -0,0 +1,14 @@ +import { gql } from '@apollo/client'; + +export const TaxSummaryFragment = gql` + fragment TaxSummaryFragment on CartPrices { + applied_taxes { + amount { + currency + value + } + } + } +`; + +export default TaxSummary; diff --git a/packages/venia-ui/lib/components/CheckoutPage/PaymentInformation/creditCard.gql.js b/packages/peregrine/lib/talons/CheckoutPage/PaymentInformation/creditCard.gql.js similarity index 89% rename from packages/venia-ui/lib/components/CheckoutPage/PaymentInformation/creditCard.gql.js rename to packages/peregrine/lib/talons/CheckoutPage/PaymentInformation/creditCard.gql.js index ee999bd0f7..60360cb430 100644 --- a/packages/venia-ui/lib/components/CheckoutPage/PaymentInformation/creditCard.gql.js +++ b/packages/peregrine/lib/talons/CheckoutPage/PaymentInformation/creditCard.gql.js @@ -1,7 +1,7 @@ import { gql } from '@apollo/client'; -import { PriceSummaryFragment } from '../../CartPage/PriceSummary/priceSummaryFragments'; -import { AvailablePaymentMethodsFragment } from './paymentInformation.gql'; +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 // the fetched schema. Additionally, since we don't want to make a network call @@ -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 }; diff --git a/packages/peregrine/lib/talons/CheckoutPage/PaymentInformation/paymentInformation.gql.js b/packages/peregrine/lib/talons/CheckoutPage/PaymentInformation/paymentInformation.gql.js new file mode 100644 index 0000000000..410ee3b354 --- /dev/null +++ b/packages/peregrine/lib/talons/CheckoutPage/PaymentInformation/paymentInformation.gql.js @@ -0,0 +1,135 @@ +import { gql } from '@apollo/client'; +import { PriceSummaryFragment } from '../../CartPage/PriceSummary/priceSummaryFragments.gql'; + +export const AvailablePaymentMethodsFragment = gql` + fragment AvailablePaymentMethodsFragment on Cart { + id + available_payment_methods { + code + title + } + } +`; + +export const GET_PAYMENT_INFORMATION = gql` + query getPaymentInformation($cartId: String!) { + cart(cart_id: $cartId) { + id + selected_payment_method { + code + } + shipping_addresses { + firstname + lastname + street + city + region { + code + } + postcode + country { + code + } + telephone + } + ...AvailablePaymentMethodsFragment + } + } + ${AvailablePaymentMethodsFragment} +`; +// We disable linting for local fields because there is no way to add them to +// the fetched schema. +// https://github.com/apollographql/eslint-plugin-graphql/issues/99 +/* eslint-disable graphql/template-strings */ +export const GET_PAYMENT_NONCE = gql` + query getPaymentNonce($cartId: String!) { + cart(cart_id: $cartId) @client { + id + paymentNonce + } + } +`; +/* eslint-enable graphql/template-strings */ + +export const SET_BILLING_ADDRESS = gql` + mutation setBillingAddress( + $cartId: String! + $firstname: String! + $lastname: String! + $street: [String]! + $city: String! + $regionCode: String! + $postcode: String! + $countryCode: String! + $telephone: String! + ) { + setBillingAddressOnCart( + input: { + cart_id: $cartId + billing_address: { + address: { + firstname: $firstname + lastname: $lastname + street: $street + city: $city + region: $regionCode + postcode: $postcode + country_code: $countryCode + telephone: $telephone + save_in_address_book: false + } + } + } + ) @connection(key: "setBillingAddressOnCart") { + cart { + id + billing_address { + firstname + lastname + country { + code + } + street + city + region { + code + } + postcode + telephone + } + ...PriceSummaryFragment + ...AvailablePaymentMethodsFragment + } + } + } + ${PriceSummaryFragment} + ${AvailablePaymentMethodsFragment} +`; + +// Sets the provided payment method object on the cart. +export const SET_FREE_PAYMENT_METHOD_ON_CART = gql` + mutation setPaymentMethodOnCart($cartId: String!) { + setPaymentMethodOnCart( + input: { cart_id: $cartId, payment_method: { code: "free" } } + ) @connection(key: "setPaymentMethodOnCart") { + cart { + id + selected_payment_method { + code + title + } + } + } + } +`; + +export default { + queries: { + getPaymentNonceQuery: GET_PAYMENT_NONCE, + getPaymentInformation: GET_PAYMENT_INFORMATION + }, + mutations: { + setBillingAddressMutation: SET_BILLING_ADDRESS, + setFreePaymentMethodMutation: SET_FREE_PAYMENT_METHOD_ON_CART + } +}; diff --git a/packages/peregrine/lib/talons/CheckoutPage/PaymentInformation/useCreditCard.js b/packages/peregrine/lib/talons/CheckoutPage/PaymentInformation/useCreditCard.js index e20c024af4..0d1d6ce012 100644 --- a/packages/peregrine/lib/talons/CheckoutPage/PaymentInformation/useCreditCard.js +++ b/packages/peregrine/lib/talons/CheckoutPage/PaymentInformation/useCreditCard.js @@ -4,6 +4,8 @@ import { useQuery, useApolloClient, useMutation } from '@apollo/client'; import { useCartContext } from '../../../context/cart'; +import DEFAULT_OPERATIONS from './creditCard.gql'; + /** * Maps address response data from GET_BILLING_ADDRESS and GET_SHIPPING_ADDRESS * queries to input names in the billing address form. @@ -48,11 +50,11 @@ export const mapAddressData = rawAddressData => { * @param {Function} props.onReady callback to invoke when the braintree dropin component is ready * @param {Function} props.onError callback to invoke when the braintree dropin component throws an error * @param {Function} props.resetShouldSubmit callback to reset the shouldSubmit flag - * @param {DocumentNode} props.queries.getBillingAddressQuery query to fetch billing address from cache - * @param {DocumentNode} props.queries.getIsBillingAddressSameQuery query to fetch is billing address same checkbox value from cache - * @param {DocumentNode} props.queries.getPaymentNonceQuery query to fetch payment nonce saved in cache - * @param {DocumentNode} props.mutations.setBillingAddressMutation mutation to update billing address on the cart - * @param {DocumentNode} props.mutations.setCreditCardDetailsOnCartMutation mutation to update payment method and payment nonce on the cart + * @param {DocumentNode} props.operations.getBillingAddressQuery query to fetch billing address from cache + * @param {DocumentNode} props.operations.getIsBillingAddressSameQuery query to fetch is billing address same checkbox value from cache + * @param {DocumentNode} props.operations.getPaymentNonceQuery query to fetch payment nonce saved in cache + * @param {DocumentNode} props.operations.setBillingAddressMutation mutation to update billing address on the cart + * @param {DocumentNode} props.operations.setCreditCardDetailsOnCartMutation mutation to update payment method and payment nonce on the cart * * @returns { * errors: Map, @@ -83,25 +85,22 @@ export const mapAddressData = rawAddressData => { export const useCreditCard = props => { const { onSuccess, - queries, - mutations, onReady, onError, shouldSubmit, resetShouldSubmit } = props; + const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations); + const { getBillingAddressQuery, getIsBillingAddressSameQuery, getPaymentNonceQuery, - getShippingAddressQuery - } = queries; - - const { + getShippingAddressQuery, setBillingAddressMutation, setCreditCardDetailsOnCartMutation - } = mutations; + } = operations; /** * Definitions diff --git a/packages/venia-ui/lib/components/CheckoutPage/PaymentInformation/creditCard.js b/packages/venia-ui/lib/components/CheckoutPage/PaymentInformation/creditCard.js index 391fd2b149..b1b86a539d 100644 --- a/packages/venia-ui/lib/components/CheckoutPage/PaymentInformation/creditCard.js +++ b/packages/venia-ui/lib/components/CheckoutPage/PaymentInformation/creditCard.js @@ -14,8 +14,6 @@ import BrainTreeDropin from './brainTreeDropIn'; import LoadingIndicator from '../../LoadingIndicator'; import { mergeClasses } from '../../../classify'; -import creditCardPaymentOperations from './creditCard.gql'; - import defaultClasses from './creditCard.css'; import FormError from '../../FormError'; @@ -57,8 +55,7 @@ const CreditCard = props => { onReady, onError, shouldSubmit, - resetShouldSubmit, - ...creditCardPaymentOperations + resetShouldSubmit }); const { From e8623d831248fdff39fcd8ff31aa6e6d6e506c81 Mon Sep 17 00:00:00 2001 From: Lars Date: Wed, 10 Feb 2021 23:12:15 +0100 Subject: [PATCH 02/10] Move PriceSummaryFragment to peregrine --- .../PaymentInformation/useCreditCard.js | 1 + .../CartPage/PriceSummary/discountSummary.js | 12 ------ .../CartPage/PriceSummary/priceSummary.js | 3 +- .../PriceSummary/priceSummaryFragments.js | 41 ------------------- .../CartPage/PriceSummary/shippingSummary.js | 15 ------- .../CartPage/PriceSummary/taxSummary.js | 11 ----- .../CartPage/cartPageFragments.gql.js | 2 +- .../paymentInformation.gql.js | 2 +- .../AddressForm/guestForm.gql.js | 2 +- .../shippingInformation.gql.js | 2 +- 10 files changed, 6 insertions(+), 85 deletions(-) delete mode 100644 packages/venia-ui/lib/components/CartPage/PriceSummary/priceSummaryFragments.js diff --git a/packages/peregrine/lib/talons/CheckoutPage/PaymentInformation/useCreditCard.js b/packages/peregrine/lib/talons/CheckoutPage/PaymentInformation/useCreditCard.js index 0d1d6ce012..e510a7b4bc 100644 --- a/packages/peregrine/lib/talons/CheckoutPage/PaymentInformation/useCreditCard.js +++ b/packages/peregrine/lib/talons/CheckoutPage/PaymentInformation/useCreditCard.js @@ -1,6 +1,7 @@ import { useCallback, useEffect, useState, useMemo } from 'react'; import { useFormState, useFormApi } from 'informed'; import { useQuery, useApolloClient, useMutation } from '@apollo/client'; +import mergeOperations from '@magento/peregrine/lib/util/shallowMerge'; import { useCartContext } from '../../../context/cart'; diff --git a/packages/venia-ui/lib/components/CartPage/PriceSummary/discountSummary.js b/packages/venia-ui/lib/components/CartPage/PriceSummary/discountSummary.js index 510f947a5f..32c58c6493 100644 --- a/packages/venia-ui/lib/components/CartPage/PriceSummary/discountSummary.js +++ b/packages/venia-ui/lib/components/CartPage/PriceSummary/discountSummary.js @@ -61,16 +61,4 @@ const DiscountSummary = props => { ) : null; }; -export const DiscountSummaryFragment = gql` - fragment DiscountSummaryFragment on CartPrices { - discounts { - amount { - currency - value - } - label - } - } -`; - export default DiscountSummary; diff --git a/packages/venia-ui/lib/components/CartPage/PriceSummary/priceSummary.js b/packages/venia-ui/lib/components/CartPage/PriceSummary/priceSummary.js index bd7971940c..c7bf5af1f6 100644 --- a/packages/venia-ui/lib/components/CartPage/PriceSummary/priceSummary.js +++ b/packages/venia-ui/lib/components/CartPage/PriceSummary/priceSummary.js @@ -10,8 +10,7 @@ import DiscountSummary from './discountSummary'; import GiftCardSummary from './giftCardSummary'; import ShippingSummary from './shippingSummary'; import TaxSummary from './taxSummary'; -import { PriceSummaryFragment } from './priceSummaryFragments'; - +import { PriceSummaryFragment } from '@magento/peregrine/lib/talons/CartPage/PriceSummary/priceSummaryFragments.gql'; const GET_PRICE_SUMMARY = gql` query getPriceSummary($cartId: String!) { cart(cart_id: $cartId) { diff --git a/packages/venia-ui/lib/components/CartPage/PriceSummary/priceSummaryFragments.js b/packages/venia-ui/lib/components/CartPage/PriceSummary/priceSummaryFragments.js deleted file mode 100644 index 6c2f4b977e..0000000000 --- a/packages/venia-ui/lib/components/CartPage/PriceSummary/priceSummaryFragments.js +++ /dev/null @@ -1,41 +0,0 @@ -import { gql } from '@apollo/client'; - -import { DiscountSummaryFragment } from './discountSummary'; -import { GiftCardSummaryFragment } from './queries/giftCardSummary'; -import { ShippingSummaryFragment } from './shippingSummary'; -import { TaxSummaryFragment } from './taxSummary'; - -export const GrandTotalFragment = gql` - fragment GrandTotalFragment on CartPrices { - grand_total { - currency - value - } - } -`; - -export const PriceSummaryFragment = gql` - fragment PriceSummaryFragment on Cart { - id - items { - id - quantity - } - ...ShippingSummaryFragment - prices { - ...TaxSummaryFragment - ...DiscountSummaryFragment - ...GrandTotalFragment - subtotal_excluding_tax { - currency - value - } - } - ...GiftCardSummaryFragment - } - ${DiscountSummaryFragment} - ${GiftCardSummaryFragment} - ${GrandTotalFragment} - ${ShippingSummaryFragment} - ${TaxSummaryFragment} -`; diff --git a/packages/venia-ui/lib/components/CartPage/PriceSummary/shippingSummary.js b/packages/venia-ui/lib/components/CartPage/PriceSummary/shippingSummary.js index 3c3de58bb9..d95fbc50ef 100644 --- a/packages/venia-ui/lib/components/CartPage/PriceSummary/shippingSummary.js +++ b/packages/venia-ui/lib/components/CartPage/PriceSummary/shippingSummary.js @@ -51,19 +51,4 @@ const ShippingSummary = props => { ); }; -export const ShippingSummaryFragment = gql` - fragment ShippingSummaryFragment on Cart { - id - shipping_addresses { - selected_shipping_method { - amount { - currency - value - } - } - street - } - } -`; - export default ShippingSummary; diff --git a/packages/venia-ui/lib/components/CartPage/PriceSummary/taxSummary.js b/packages/venia-ui/lib/components/CartPage/PriceSummary/taxSummary.js index 94dcd42d16..669f7ffe73 100644 --- a/packages/venia-ui/lib/components/CartPage/PriceSummary/taxSummary.js +++ b/packages/venia-ui/lib/components/CartPage/PriceSummary/taxSummary.js @@ -55,15 +55,4 @@ const TaxSummary = props => { ); }; -export const TaxSummaryFragment = gql` - fragment TaxSummaryFragment on CartPrices { - applied_taxes { - amount { - currency - value - } - } - } -`; - export default TaxSummary; diff --git a/packages/venia-ui/lib/components/CartPage/cartPageFragments.gql.js b/packages/venia-ui/lib/components/CartPage/cartPageFragments.gql.js index 2fa0a3520f..1ea4b66b73 100644 --- a/packages/venia-ui/lib/components/CartPage/cartPageFragments.gql.js +++ b/packages/venia-ui/lib/components/CartPage/cartPageFragments.gql.js @@ -2,7 +2,7 @@ import { gql } from '@apollo/client'; import { GiftCardFragment } from './GiftCards/giftCardFragments'; import { ProductListingFragment } from './ProductListing/productListingFragments'; -import { PriceSummaryFragment } from './PriceSummary/priceSummaryFragments'; +import { PriceSummaryFragment } from '@magento/peregrine/lib/talons/CartPage/PriceSummary/priceSummaryFragments.gql'; import { AppliedCouponsFragment } from './PriceAdjustments/CouponCode/couponCodeFragments'; export const CartPageFragment = gql` diff --git a/packages/venia-ui/lib/components/CheckoutPage/PaymentInformation/paymentInformation.gql.js b/packages/venia-ui/lib/components/CheckoutPage/PaymentInformation/paymentInformation.gql.js index 6d18639b89..22e8230e0a 100644 --- a/packages/venia-ui/lib/components/CheckoutPage/PaymentInformation/paymentInformation.gql.js +++ b/packages/venia-ui/lib/components/CheckoutPage/PaymentInformation/paymentInformation.gql.js @@ -1,5 +1,5 @@ import { gql } from '@apollo/client'; -import { PriceSummaryFragment } from '../../CartPage/PriceSummary/priceSummaryFragments'; +import { PriceSummaryFragment } from '@magento/peregrine/lib/talons/CartPage/PriceSummary/priceSummaryFragments.gql'; export const AvailablePaymentMethodsFragment = gql` fragment AvailablePaymentMethodsFragment on Cart { diff --git a/packages/venia-ui/lib/components/CheckoutPage/ShippingInformation/AddressForm/guestForm.gql.js b/packages/venia-ui/lib/components/CheckoutPage/ShippingInformation/AddressForm/guestForm.gql.js index 92b3d460f1..3133ff1ef3 100644 --- a/packages/venia-ui/lib/components/CheckoutPage/ShippingInformation/AddressForm/guestForm.gql.js +++ b/packages/venia-ui/lib/components/CheckoutPage/ShippingInformation/AddressForm/guestForm.gql.js @@ -1,8 +1,8 @@ import { gql } from '@apollo/client'; +import { PriceSummaryFragment } from '@magento/peregrine/lib/talons/CartPage/PriceSummary/priceSummaryFragments.gql'; import { ShippingInformationFragment } from '../shippingInformationFragments.gql'; import { ShippingMethodsCheckoutFragment } from '../../ShippingMethod/shippingMethodFragments.gql'; -import { PriceSummaryFragment } from '../../../CartPage/PriceSummary/priceSummaryFragments'; import { AvailablePaymentMethodsFragment } from '../../PaymentInformation/paymentInformation.gql'; export const SET_GUEST_SHIPPING_MUTATION = gql` diff --git a/packages/venia-ui/lib/components/CheckoutPage/ShippingInformation/shippingInformation.gql.js b/packages/venia-ui/lib/components/CheckoutPage/ShippingInformation/shippingInformation.gql.js index c5b32bb21f..ca1236b197 100644 --- a/packages/venia-ui/lib/components/CheckoutPage/ShippingInformation/shippingInformation.gql.js +++ b/packages/venia-ui/lib/components/CheckoutPage/ShippingInformation/shippingInformation.gql.js @@ -1,8 +1,8 @@ import { gql } from '@apollo/client'; +import { PriceSummaryFragment } from '@magento/peregrine/lib/talons/CartPage/PriceSummary/priceSummaryFragments.gql'; import { ShippingInformationFragment } from './shippingInformationFragments.gql'; import { ShippingMethodsCheckoutFragment } from '../ShippingMethod/shippingMethodFragments.gql'; -import { PriceSummaryFragment } from '../../CartPage/PriceSummary/priceSummaryFragments'; import { AvailablePaymentMethodsFragment } from '../PaymentInformation/paymentInformation.gql'; export const GET_SHIPPING_INFORMATION = gql` From 11cc258bea6970afc3ce022fa8a8c9495714b9d9 Mon Sep 17 00:00:00 2001 From: Lars Date: Wed, 10 Feb 2021 23:33:54 +0100 Subject: [PATCH 03/10] Fix unit tests --- .../PriceSummary/discountSummary.gql.js | 1 - .../PriceSummary/shippingSummary.gql.js | 2 - .../CartPage/PriceSummary/taxSummary.gql.js | 2 - .../__tests__/useCreditCard.spec.js | 75 +++++++------------ .../ShippingMethod/shippingMethod.gql.js | 2 +- 5 files changed, 26 insertions(+), 56 deletions(-) diff --git a/packages/peregrine/lib/talons/CartPage/PriceSummary/discountSummary.gql.js b/packages/peregrine/lib/talons/CartPage/PriceSummary/discountSummary.gql.js index f4a0527a81..fffe2ba292 100644 --- a/packages/peregrine/lib/talons/CartPage/PriceSummary/discountSummary.gql.js +++ b/packages/peregrine/lib/talons/CartPage/PriceSummary/discountSummary.gql.js @@ -12,4 +12,3 @@ export const DiscountSummaryFragment = gql` } `; -export default DiscountSummary; diff --git a/packages/peregrine/lib/talons/CartPage/PriceSummary/shippingSummary.gql.js b/packages/peregrine/lib/talons/CartPage/PriceSummary/shippingSummary.gql.js index 2dfe4af474..966ac9e398 100644 --- a/packages/peregrine/lib/talons/CartPage/PriceSummary/shippingSummary.gql.js +++ b/packages/peregrine/lib/talons/CartPage/PriceSummary/shippingSummary.gql.js @@ -14,5 +14,3 @@ export const ShippingSummaryFragment = gql` } } `; - -export default ShippingSummary; diff --git a/packages/peregrine/lib/talons/CartPage/PriceSummary/taxSummary.gql.js b/packages/peregrine/lib/talons/CartPage/PriceSummary/taxSummary.gql.js index 223f396fed..b730837f2a 100644 --- a/packages/peregrine/lib/talons/CartPage/PriceSummary/taxSummary.gql.js +++ b/packages/peregrine/lib/talons/CartPage/PriceSummary/taxSummary.gql.js @@ -10,5 +10,3 @@ export const TaxSummaryFragment = gql` } } `; - -export default TaxSummary; diff --git a/packages/peregrine/lib/talons/CheckoutPage/PaymentInformation/__tests__/useCreditCard.spec.js b/packages/peregrine/lib/talons/CheckoutPage/PaymentInformation/__tests__/useCreditCard.spec.js index bc9632ffbd..81ed1b6744 100644 --- a/packages/peregrine/lib/talons/CheckoutPage/PaymentInformation/__tests__/useCreditCard.spec.js +++ b/packages/peregrine/lib/talons/CheckoutPage/PaymentInformation/__tests__/useCreditCard.spec.js @@ -108,14 +108,12 @@ const setCreditCardDetailsOnCartMutationResult = jest.fn().mockReturnValue([ const writeQuery = jest.fn(); -const queries = { +const operations = { getAllCountriesQuery, getBillingAddressQuery, getIsBillingAddressSameQuery, getPaymentNonceQuery, - getShippingAddressQuery -}; -const mutations = { + getShippingAddressQuery, setBillingAddressMutation, setCreditCardDetailsOnCartMutation }; @@ -210,8 +208,7 @@ const getTalonProps = props => { test('Should return correct shape', () => { const { talonProps } = getTalonProps({ shouldSubmit: false, - queries, - mutations, + operations, onSuccess: () => {}, onReady: () => {}, onError: () => {} @@ -224,8 +221,7 @@ test('Shuold call onReady when payment is ready', () => { const onReady = jest.fn(); const { talonProps } = getTalonProps({ shouldSubmit: false, - queries, - mutations, + operations, onSuccess: () => {}, onReady, onError: () => {} @@ -243,8 +239,7 @@ test('Shuold call onError when payment nonce generation errored out', () => { const { talonProps } = getTalonProps({ shouldSubmit: false, - queries, - mutations, + operations, onSuccess: () => {}, onError, onReady: () => {}, @@ -287,8 +282,7 @@ test('Should return errors from billing address and payment method mutations', ( const { talonProps } = getTalonProps({ shouldSubmit: false, - queries, - mutations, + operations, onSuccess: () => {}, onError: () => {}, onReady: () => {}, @@ -332,8 +326,7 @@ test('Should return isBillingAddress and billingAddress from cache as initialVal const { talonProps } = getTalonProps({ shouldSubmit: false, - queries, - mutations, + operations, onSuccess: () => {}, onError: () => {}, onReady: () => {}, @@ -375,8 +368,7 @@ test('Should set billingAddress to {} if isBillingAddress is true in initialValu const { talonProps } = getTalonProps({ shouldSubmit: false, - queries, - mutations, + operations, onSuccess: () => {}, onError: () => {}, onReady: () => {}, @@ -391,8 +383,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: () => {}, @@ -433,8 +424,7 @@ describe('Testing payment nonce request workflow', () => { getTalonProps({ shouldSubmit: true, - queries, - mutations, + operations, onSuccess: () => {}, onReady: () => {}, onError: () => {}, @@ -484,8 +474,7 @@ describe('Testing payment nonce request workflow', () => { getTalonProps({ shouldSubmit: true, - queries, - mutations, + operations, onSuccess: () => {}, onReady: () => {}, onError: () => {}, @@ -511,8 +500,7 @@ describe('Testing payment nonce request workflow', () => { getTalonProps({ shouldSubmit: true, - queries, - mutations, + operations, onSuccess: () => {}, onReady: () => {}, onError: () => {}, @@ -540,8 +528,7 @@ describe('Testing payment nonce request workflow', () => { getTalonProps({ shouldSubmit: true, - queries, - mutations, + operations, onSuccess: () => {}, onReady: () => {}, onError: () => {}, @@ -564,8 +551,7 @@ describe('Testing payment success workflow', () => { }; const { talonProps } = getTalonProps({ shouldSubmit: false, - queries, - mutations, + operations, onSuccess: () => {}, onReady: () => {}, onError: () => {} @@ -587,8 +573,7 @@ describe('Testing payment success workflow', () => { test('Should call setCreditCardDetailsOnCartMutation on payment success', () => { const { talonProps } = getTalonProps({ shouldSubmit: false, - queries, - mutations, + operations, onSuccess: () => {}, onReady: () => {}, onError: () => {} @@ -618,8 +603,7 @@ describe('Testing payment success workflow', () => { const onSuccess = jest.fn(); const { talonProps } = getTalonProps({ shouldSubmit: false, - queries, - mutations, + operations, onSuccess, onReady: () => {}, onError: () => {}, @@ -644,8 +628,7 @@ describe('Testing payment success workflow', () => { const onSuccess = jest.fn(); const { talonProps } = getTalonProps({ shouldSubmit: false, - queries, - mutations, + operations, onSuccess, onReady: () => {}, onError: () => {}, @@ -662,8 +645,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: () => {}, @@ -680,8 +662,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: () => {} @@ -698,8 +679,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: () => {} @@ -716,8 +696,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: () => {} @@ -739,8 +718,7 @@ describe('Testing stepNumber', () => { const { talonProps } = getTalonProps({ shouldSubmit: false, - queries, - mutations, + operations, onSuccess: () => {}, onReady: () => {}, onError: () => {} @@ -764,8 +742,7 @@ describe('Testing stepNumber', () => { const resetShouldSubmit = jest.fn(); const { talonProps } = getTalonProps({ shouldSubmit: false, - queries, - mutations, + operations, onSuccess: () => {}, onReady: () => {}, onError: () => {}, @@ -789,8 +766,7 @@ describe('Testing stepNumber', () => { const { talonProps } = getTalonProps({ shouldSubmit: false, - queries, - mutations, + operations, onSuccess: () => {}, onReady: () => {}, onError: () => {}, @@ -814,8 +790,7 @@ describe('Testing stepNumber', () => { const resetShouldSubmit = jest.fn(); const { talonProps } = getTalonProps({ shouldSubmit: false, - queries, - mutations, + operations, onSuccess: () => {}, onReady: () => {}, onError: () => {}, diff --git a/packages/venia-ui/lib/components/CheckoutPage/ShippingMethod/shippingMethod.gql.js b/packages/venia-ui/lib/components/CheckoutPage/ShippingMethod/shippingMethod.gql.js index 7af06d3816..e7c2b811ab 100644 --- a/packages/venia-ui/lib/components/CheckoutPage/ShippingMethod/shippingMethod.gql.js +++ b/packages/venia-ui/lib/components/CheckoutPage/ShippingMethod/shippingMethod.gql.js @@ -1,6 +1,6 @@ import { gql } from '@apollo/client'; -import { PriceSummaryFragment } from '@magento/venia-ui/lib/components/CartPage/PriceSummary/priceSummaryFragments'; +import { PriceSummaryFragment } from '@magento/peregrine/lib/talons/CartPage/PriceSummary/priceSummaryFragments.gql'; import { ShippingInformationFragment } from '../ShippingInformation/shippingInformationFragments.gql'; import { From f38e1b27f90eccc1b2ac774a07d9a632a67847ad Mon Sep 17 00:00:00 2001 From: Lars Date: Wed, 10 Feb 2021 23:37:11 +0100 Subject: [PATCH 04/10] Fix lint --- .../lib/talons/CartPage/PriceSummary/discountSummary.gql.js | 1 - .../lib/components/CartPage/PriceSummary/discountSummary.js | 1 - .../lib/components/CartPage/PriceSummary/shippingSummary.js | 1 - .../venia-ui/lib/components/CartPage/PriceSummary/taxSummary.js | 1 - 4 files changed, 4 deletions(-) diff --git a/packages/peregrine/lib/talons/CartPage/PriceSummary/discountSummary.gql.js b/packages/peregrine/lib/talons/CartPage/PriceSummary/discountSummary.gql.js index fffe2ba292..8212e02c66 100644 --- a/packages/peregrine/lib/talons/CartPage/PriceSummary/discountSummary.gql.js +++ b/packages/peregrine/lib/talons/CartPage/PriceSummary/discountSummary.gql.js @@ -11,4 +11,3 @@ export const DiscountSummaryFragment = gql` } } `; - diff --git a/packages/venia-ui/lib/components/CartPage/PriceSummary/discountSummary.js b/packages/venia-ui/lib/components/CartPage/PriceSummary/discountSummary.js index 32c58c6493..c746b02325 100644 --- a/packages/venia-ui/lib/components/CartPage/PriceSummary/discountSummary.js +++ b/packages/venia-ui/lib/components/CartPage/PriceSummary/discountSummary.js @@ -1,6 +1,5 @@ import React, { Fragment } from 'react'; import { FormattedMessage } from 'react-intl'; -import { gql } from '@apollo/client'; import Price from '@magento/venia-ui/lib/components/Price'; import { mergeClasses } from '../../../classify'; diff --git a/packages/venia-ui/lib/components/CartPage/PriceSummary/shippingSummary.js b/packages/venia-ui/lib/components/CartPage/PriceSummary/shippingSummary.js index d95fbc50ef..a191f61ef9 100644 --- a/packages/venia-ui/lib/components/CartPage/PriceSummary/shippingSummary.js +++ b/packages/venia-ui/lib/components/CartPage/PriceSummary/shippingSummary.js @@ -1,6 +1,5 @@ import React from 'react'; import { FormattedMessage, useIntl } from 'react-intl'; -import { gql } from '@apollo/client'; import Price from '@magento/venia-ui/lib/components/Price'; import { mergeClasses } from '../../../classify'; diff --git a/packages/venia-ui/lib/components/CartPage/PriceSummary/taxSummary.js b/packages/venia-ui/lib/components/CartPage/PriceSummary/taxSummary.js index 669f7ffe73..36e69f5124 100644 --- a/packages/venia-ui/lib/components/CartPage/PriceSummary/taxSummary.js +++ b/packages/venia-ui/lib/components/CartPage/PriceSummary/taxSummary.js @@ -1,6 +1,5 @@ import React from 'react'; import { useIntl } from 'react-intl'; -import { gql } from '@apollo/client'; import Price from '@magento/venia-ui/lib/components/Price'; import { mergeClasses } from '../../../classify'; From 924ac9855b8e3592c3319710cd264ca42e857085 Mon Sep 17 00:00:00 2001 From: Lars Date: Thu, 11 Feb 2021 00:01:21 +0100 Subject: [PATCH 05/10] Fix test --- .../PaymentInformation/__tests__/useCreditCard.spec.js | 8 +------- .../CheckoutPage/PaymentInformation/creditCard.gql.js | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/packages/peregrine/lib/talons/CheckoutPage/PaymentInformation/__tests__/useCreditCard.spec.js b/packages/peregrine/lib/talons/CheckoutPage/PaymentInformation/__tests__/useCreditCard.spec.js index 81ed1b6744..ccdde47b26 100644 --- a/packages/peregrine/lib/talons/CheckoutPage/PaymentInformation/__tests__/useCreditCard.spec.js +++ b/packages/peregrine/lib/talons/CheckoutPage/PaymentInformation/__tests__/useCreditCard.spec.js @@ -118,13 +118,7 @@ const operations = { 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' }]) diff --git a/packages/peregrine/lib/talons/CheckoutPage/PaymentInformation/creditCard.gql.js b/packages/peregrine/lib/talons/CheckoutPage/PaymentInformation/creditCard.gql.js index 60360cb430..9c4ef7808d 100644 --- a/packages/peregrine/lib/talons/CheckoutPage/PaymentInformation/creditCard.gql.js +++ b/packages/peregrine/lib/talons/CheckoutPage/PaymentInformation/creditCard.gql.js @@ -1,7 +1,7 @@ import { gql } from '@apollo/client'; import { PriceSummaryFragment } from '../../CartPage/PriceSummary/priceSummaryFragments.gql'; -import { AvailablePaymentMethodsFragment } from 'paymentInformation.gql'; +import { AvailablePaymentMethodsFragment } from './paymentInformation.gql'; // We disable linting for local fields because there is no way to add them to // the fetched schema. Additionally, since we don't want to make a network call From 7dd6c143e7889928ac5962709ad68665fc87d61e Mon Sep 17 00:00:00 2001 From: sirugh Date: Thu, 11 Feb 2021 09:36:18 -0600 Subject: [PATCH 06/10] use default moduleFileExtensions and add ee.js and ce.js so that jest can read those extensions in peregrine --- jest.config.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/jest.config.js b/jest.config.js index ecf172b50b..c38bc986e9 100644 --- a/jest.config.js +++ b/jest.config.js @@ -6,6 +6,9 @@ */ const path = require('path'); +// Default config at https://jestjs.io/docs/en/configuration +const { defaults } = require('jest-config'); + /** * `configureProject()` makes a config object for use in the `projects` array. * @@ -55,7 +58,7 @@ const testReactComponents = inPackage => ({ '@magento/venia-drivers': '/packages/venia-ui/lib/drivers/index.js' }, - moduleFileExtensions: ['ee.js', 'ce.js', 'js', 'json', 'jsx', 'node'], + moduleFileExtensions: [...defaults.moduleFileExtensions, 'ee.js', 'ce.js'], // Reproduce the Webpack resolution config that lets Venia import // from `src` instead of with relative paths: modulePaths: [ @@ -229,6 +232,12 @@ const jestConfig = { })), configureProject('pagebuilder', 'Pagebuilder', testReactComponents), configureProject('peregrine', 'Peregrine', inPackage => ({ + // Make sure we can test extension files. + moduleFileExtensions: [ + ...defaults.moduleFileExtensions, + 'ee.js', + 'ce.js' + ], // Expose jsdom to tests. setupFiles: [ // Shim DOM properties not supported by jsdom From 108fdc9eeabcfb98672ce107cf340b463d548186 Mon Sep 17 00:00:00 2001 From: Lars Date: Wed, 17 Feb 2021 22:01:38 +0100 Subject: [PATCH 07/10] Chnage jest.config --- jest.config.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/jest.config.js b/jest.config.js index 2a42bfe61e..b4105ee5f6 100644 --- a/jest.config.js +++ b/jest.config.js @@ -6,8 +6,6 @@ */ const path = require('path'); -// Default config at https://jestjs.io/docs/en/configuration -const { defaults } = require('jest-config'); /** * `configureProject()` makes a config object for use in the `projects` array. @@ -139,7 +137,7 @@ const testReactComponents = inPackage => ({ '@magento/venia-drivers': '/packages/venia-ui/lib/drivers/index.js' }, - moduleFileExtensions: [...defaults.moduleFileExtensions, 'ee.js', 'ce.js'], + moduleFileExtensions: ['ee.js', 'ce.js', 'js', 'json', 'jsx', 'node'], // Reproduce the Webpack resolution config that lets Venia import // from `src` instead of with relative paths: modulePaths: [ @@ -234,11 +232,7 @@ const jestConfig = { configureProject('pagebuilder', 'Pagebuilder', testReactComponents), configureProject('peregrine', 'Peregrine', inPackage => ({ // Make sure we can test extension files. - moduleFileExtensions: [ - ...defaults.moduleFileExtensions, - 'ee.js', - 'ce.js' - ], + moduleFileExtensions:['ee.js', 'ce.js', 'js', 'json', 'jsx', 'node'], // Define global variables. globals, // Expose jsdom to tests. From 8fcb1e4a043dc00ab86fa46afc50ba103f6d7390 Mon Sep 17 00:00:00 2001 From: Lars Roettig Date: Wed, 17 Feb 2021 22:12:44 +0100 Subject: [PATCH 08/10] Update jest.config.js Co-authored-by: Stephen --- jest.config.js | 1 - 1 file changed, 1 deletion(-) diff --git a/jest.config.js b/jest.config.js index b4105ee5f6..2956aacecf 100644 --- a/jest.config.js +++ b/jest.config.js @@ -6,7 +6,6 @@ */ const path = require('path'); - /** * `configureProject()` makes a config object for use in the `projects` array. * From 2d850b71c45d42d1e2989df86229a21664ab9f14 Mon Sep 17 00:00:00 2001 From: Lars Roettig Date: Wed, 17 Feb 2021 22:12:56 +0100 Subject: [PATCH 09/10] Update jest.config.js Co-authored-by: Stephen --- jest.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jest.config.js b/jest.config.js index 2956aacecf..1be0a83954 100644 --- a/jest.config.js +++ b/jest.config.js @@ -231,7 +231,7 @@ 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'], + moduleFileExtensions: ['ee.js', 'ce.js', 'js', 'json', 'jsx', 'node'], // Define global variables. globals, // Expose jsdom to tests. From ca2bdaf26492052aca8212800f00b0003525a27b Mon Sep 17 00:00:00 2001 From: Lars Date: Thu, 18 Feb 2021 18:54:48 +0100 Subject: [PATCH 10/10] fix format --- jest.config.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/jest.config.js b/jest.config.js index 1be0a83954..dcb14c5eb9 100644 --- a/jest.config.js +++ b/jest.config.js @@ -231,7 +231,14 @@ 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'], + moduleFileExtensions: [ + 'ee.js', + 'ce.js', + 'js', + 'json', + 'jsx', + 'node' + ], // Define global variables. globals, // Expose jsdom to tests.