|
| 1 | +/** |
| 2 | + * External dependencies |
| 3 | + */ |
| 4 | +import { test, expect } from '@playwright/test'; |
| 5 | + |
| 6 | +/** |
| 7 | + * Internal dependencies |
| 8 | + */ |
| 9 | +import { config } from '../../config/default'; |
| 10 | +import * as shopper from '../../utils/shopper'; |
| 11 | +import * as shopperNavigation from '../../utils/shopper-navigation'; |
| 12 | +import * as devtools from '../../utils/devtools'; |
| 13 | +import { getMerchant, getShopper } from '../../utils/helpers'; |
| 14 | + |
| 15 | +const cardTestingPreventionStates = [ |
| 16 | + { cardTestingPreventionEnabled: false }, |
| 17 | + { cardTestingPreventionEnabled: true }, |
| 18 | +]; |
| 19 | + |
| 20 | +test.describe( 'Shopper > Pay for Order', () => { |
| 21 | + cardTestingPreventionStates.forEach( |
| 22 | + ( { cardTestingPreventionEnabled } ) => { |
| 23 | + test( `should be able to pay for a failed order with card testing protection ${ cardTestingPreventionEnabled }`, async ( { |
| 24 | + browser, |
| 25 | + } ) => { |
| 26 | + const { merchantPage } = await getMerchant( browser ); |
| 27 | + const { shopperPage } = await getShopper( browser ); |
| 28 | + |
| 29 | + // Enable or disable card testing protection. |
| 30 | + if ( ! cardTestingPreventionEnabled ) { |
| 31 | + await devtools.disableCardTestingProtection( merchantPage ); |
| 32 | + } else { |
| 33 | + await devtools.enableCardTestingProtection( merchantPage ); |
| 34 | + } |
| 35 | + |
| 36 | + // Attempt to pay with a declined card. |
| 37 | + await shopper.addCartProduct( shopperPage ); |
| 38 | + await shopper.setupCheckout( |
| 39 | + shopperPage, |
| 40 | + config.addresses.customer.billing |
| 41 | + ); |
| 42 | + await shopper.fillCardDetails( |
| 43 | + shopperPage, |
| 44 | + config.cards.declined |
| 45 | + ); |
| 46 | + await shopper.placeOrder( shopperPage ); |
| 47 | + |
| 48 | + await expect( |
| 49 | + shopperPage.getByText( 'Your card was declined' ).first() |
| 50 | + ).toBeVisible(); |
| 51 | + |
| 52 | + // Go to the orders page and pay with a basic card. |
| 53 | + await shopperNavigation.goToOrders( shopperPage ); |
| 54 | + |
| 55 | + const payForOrderButton = shopperPage |
| 56 | + .locator( '.woocommerce-button.button.pay', { |
| 57 | + hasText: 'Pay', |
| 58 | + } ) |
| 59 | + .first(); |
| 60 | + await payForOrderButton.click(); |
| 61 | + await shopper.fillCardDetails( |
| 62 | + shopperPage, |
| 63 | + config.cards.basic |
| 64 | + ); |
| 65 | + |
| 66 | + // Check for the fraud prevenction token presence. |
| 67 | + const token = await shopperPage.evaluate( () => { |
| 68 | + return ( window as any ).wcpayFraudPreventionToken; |
| 69 | + } ); |
| 70 | + |
| 71 | + if ( cardTestingPreventionEnabled ) { |
| 72 | + expect( token ).not.toBeUndefined(); |
| 73 | + } else { |
| 74 | + expect( token ).toBeUndefined(); |
| 75 | + } |
| 76 | + |
| 77 | + // Click the pay for order button. |
| 78 | + await shopper.placeOrder( shopperPage ); |
| 79 | + |
| 80 | + await expect( |
| 81 | + shopperPage.getByText( 'Order received' ).first() |
| 82 | + ).toBeVisible(); |
| 83 | + |
| 84 | + // Disable card testing protection if necessary. |
| 85 | + if ( cardTestingPreventionEnabled ) { |
| 86 | + await devtools.disableCardTestingProtection( merchantPage ); |
| 87 | + } |
| 88 | + } ); |
| 89 | + } |
| 90 | + ); |
| 91 | +} ); |
0 commit comments