Skip to content

Commit

Permalink
Merge branch 'develop' into add/10092-add-specific-type-and-min-suppo…
Browse files Browse the repository at this point in the history
…rted-amount-in-error-response-for-the-payments-below-min-supported-amount
  • Loading branch information
mgascam authored Jan 10, 2025
2 parents 282d4e1 + 82ac1b9 commit f7ea9c6
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 86 deletions.
4 changes: 4 additions & 0 deletions changelog/dev-10071-convert-shopper-pay-for-order-e2e-spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Add the Playwright Pay for Order spec and remove the equivalent Puppeteer spec.
4 changes: 4 additions & 0 deletions changelog/dev-10113-bump-e2e-dockerfile-php-xdebug-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Update the PHP version and the Xdebug version used in the E2E testing environment.
91 changes: 91 additions & 0 deletions tests/e2e-pw/specs/shopper/shopper-pay-for-order.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/**
* External dependencies
*/
import { test, expect } from '@playwright/test';

/**
* Internal dependencies
*/
import { config } from '../../config/default';
import * as shopper from '../../utils/shopper';
import * as shopperNavigation from '../../utils/shopper-navigation';
import * as devtools from '../../utils/devtools';
import { getMerchant, getShopper } from '../../utils/helpers';

const cardTestingPreventionStates = [
{ cardTestingPreventionEnabled: false },
{ cardTestingPreventionEnabled: true },
];

test.describe( 'Shopper > Pay for Order', () => {
cardTestingPreventionStates.forEach(
( { cardTestingPreventionEnabled } ) => {
test( `should be able to pay for a failed order with card testing protection ${ cardTestingPreventionEnabled }`, async ( {
browser,
} ) => {
const { merchantPage } = await getMerchant( browser );
const { shopperPage } = await getShopper( browser );

// Enable or disable card testing protection.
if ( ! cardTestingPreventionEnabled ) {
await devtools.disableCardTestingProtection( merchantPage );
} else {
await devtools.enableCardTestingProtection( merchantPage );
}

// Attempt to pay with a declined card.
await shopper.addCartProduct( shopperPage );
await shopper.setupCheckout(
shopperPage,
config.addresses.customer.billing
);
await shopper.fillCardDetails(
shopperPage,
config.cards.declined
);
await shopper.placeOrder( shopperPage );

await expect(
shopperPage.getByText( 'Your card was declined' ).first()
).toBeVisible();

// Go to the orders page and pay with a basic card.
await shopperNavigation.goToOrders( shopperPage );

const payForOrderButton = shopperPage
.locator( '.woocommerce-button.button.pay', {
hasText: 'Pay',
} )
.first();
await payForOrderButton.click();
await shopper.fillCardDetails(
shopperPage,
config.cards.basic
);

// Check for the fraud prevenction token presence.
const token = await shopperPage.evaluate( () => {
return ( window as any ).wcpayFraudPreventionToken;
} );

if ( cardTestingPreventionEnabled ) {
expect( token ).not.toBeUndefined();
} else {
expect( token ).toBeUndefined();
}

// Click the pay for order button.
await shopper.placeOrder( shopperPage );

await expect(
shopperPage.getByText( 'Order received' ).first()
).toBeVisible();

// Disable card testing protection if necessary.
if ( cardTestingPreventionEnabled ) {
await devtools.disableCardTestingProtection( merchantPage );
}
} );
}
);
} );
40 changes: 40 additions & 0 deletions tests/e2e-pw/utils/devtools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* External dependencies
*/
import { Page, expect } from '@playwright/test';

const goToDevToolsSettings = ( page: Page ) =>
page.goto( 'wp-admin/admin.php?page=wcpaydev', {
waitUntil: 'load',
} );

const saveDevToolsSettings = async ( page: Page ) => {
await page.getByRole( 'button', { name: 'Save Changes' } ).click();
expect( page.getByText( /Settings saved/ ) ).toBeVisible();
};

const getIsCardTestingProtectionEnabled = ( page: Page ) =>
page.getByLabel( 'Card testing mitigations enabled' ).isChecked();

const toggleCardTestingProtection = ( page: Page ) =>
page
.locator( 'label[for="wcpaydev_force_card_testing_protection_on"]' )
.click();

export const enableCardTestingProtection = async ( page: Page ) => {
await goToDevToolsSettings( page );

if ( ! ( await getIsCardTestingProtectionEnabled( page ) ) ) {
await toggleCardTestingProtection( page );
await saveDevToolsSettings( page );
}
};

export const disableCardTestingProtection = async ( page: Page ) => {
await goToDevToolsSettings( page );

if ( await getIsCardTestingProtectionEnabled( page ) ) {
await toggleCardTestingProtection( page );
await saveDevToolsSettings( page );
}
};
4 changes: 2 additions & 2 deletions tests/e2e/env/wordpress-xdebug/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM wordpress:6.0.2-php7.4
RUN pecl install xdebug-2.9.8 \
FROM wordpress:php8.1
RUN pecl install xdebug \
&& echo 'xdebug.remote_enable=1' >> $PHP_INI_DIR/php.ini \
&& echo 'xdebug.remote_port=9000' >> $PHP_INI_DIR/php.ini \
&& echo 'xdebug.remote_host=host.docker.internal' >> $PHP_INI_DIR/php.ini \
Expand Down
84 changes: 0 additions & 84 deletions tests/e2e/specs/wcpay/shopper/shopper-pay-for-order.spec.js

This file was deleted.

0 comments on commit f7ea9c6

Please sign in to comment.