/** * External dependencies */ import * as wpDataFunctions from '@wordpress/data'; import { previewCart } from '@woocommerce/resource-previews'; import { PAYMENT_STORE_KEY, CART_STORE_KEY } from '@woocommerce/block-data'; import { registerPaymentMethod, registerExpressPaymentMethod, __experimentalDeRegisterPaymentMethod, __experimentalDeRegisterExpressPaymentMethod, } from '@woocommerce/blocks-registry'; import { CanMakePaymentArgument } from '@woocommerce/types'; /** * Internal dependencies */ import { checkPaymentMethodsCanPay } from '../utils/check-payment-methods'; const requiredKeyCheck = ( args: CanMakePaymentArgument ) => { const requiredKeys = [ 'billingData', 'billingAddress', 'cart', 'cartNeedsShipping', 'cartTotals', 'paymentMethods', 'paymentRequirements', 'selectedShippingMethods', 'shippingAddress', ]; const argKeys = Object.keys( args ); const requiredCartKeys = [ 'cartCoupons', 'cartItems', 'crossSellsProducts', 'cartFees', 'cartItemsCount', 'cartItemsWeight', 'cartNeedsPayment', 'cartNeedsShipping', 'cartItemErrors', 'cartTotals', 'cartIsLoading', 'cartErrors', 'billingData', 'billingAddress', 'shippingAddress', 'extensions', 'shippingRates', 'isLoadingRates', 'cartHasCalculatedShipping', 'paymentRequirements', 'receiveCart', ]; const cartKeys = Object.keys( args.cart ); const requiredTotalsKeys = [ 'total_items', 'total_items_tax', 'total_fees', 'total_fees_tax', 'total_discount', 'total_discount_tax', 'total_shipping', 'total_shipping_tax', 'total_price', 'total_tax', 'tax_lines', 'currency_code', 'currency_symbol', 'currency_minor_unit', 'currency_decimal_separator', 'currency_thousand_separator', 'currency_prefix', 'currency_suffix', ]; const totalsKeys = Object.keys( args.cartTotals ); return ( requiredKeys.every( ( key ) => argKeys.includes( key ) ) && requiredTotalsKeys.every( ( key ) => totalsKeys.includes( key ) ) && requiredCartKeys.every( ( key ) => cartKeys.includes( key ) ) ); }; const mockedCanMakePayment = jest.fn().mockImplementation( requiredKeyCheck ); const mockedExpressCanMakePayment = jest .fn() .mockImplementation( requiredKeyCheck ); const registerMockPaymentMethods = ( savedCards = true ) => { [ 'credit-card' ].forEach( ( name ) => { registerPaymentMethod( { name, label: name, content: