Skip to content

Commit 894bb67

Browse files
E2E: Test the basic Affirm payment flow (#4436)
* E2E: Test the basic Affirm payment flow * Add changelog entries * Update code comment Co-authored-by: Diego Curbelo <[email protected]> * Update Affirm payment test to include Stripe URL in validation * Update URLs in shortcode checkout Also update the code comment --------- Co-authored-by: Diego Curbelo <[email protected]>
1 parent b55652d commit 894bb67

File tree

5 files changed

+91
-0
lines changed

5 files changed

+91
-0
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
* Tweak - Remove Payment Method Configurations fallback cache
4141
* Tweak - Update deprecation notice message to specify that legacy checkout experience has been deprecated since version 9.6.0
4242
* Update - Remove legacy checkout checkbox from settings
43+
* Dev - Add e2e tests to cover Affirm purchase flow
4344

4445
= 9.5.3 - 2025-06-23 =
4546
* Fix - Reimplement mapping of Express Checkout state values to align with WooCommerce's expected state formats

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,5 +152,6 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
152152
* Dev - Add Klarna e2e tests
153153
* Tweak - Update deprecation notice message to specify that legacy checkout experience has been deprecated since version 9.6.0
154154
* Update - Remove legacy checkout checkbox from settings
155+
* Dev - Add e2e tests to cover Affirm purchase flow
155156

156157
[See changelog for full details across versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { test, expect } from '@playwright/test';
2+
import { admin, payments } from '../../../utils';
3+
4+
const { setupAffirmCheckout } = payments;
5+
6+
test.describe( 'Affirm payment tests @blocks', () => {
7+
test.beforeAll( async ( { browser } ) => {
8+
await test.step( 'Setup test environment', async () => {
9+
// Enable Affirm in admin
10+
await admin.togglePaymentMethod( browser, 'Affirm', true );
11+
} );
12+
} );
13+
14+
test.describe.configure( { mode: 'parallel' } );
15+
16+
test( 'customer can pay with Affirm @smoke', async ( { page } ) => {
17+
await setupAffirmCheckout( page, 'blocks' );
18+
await page.locator( 'text=Place order' ).click();
19+
// Since we don't have control over the Affirm payment flow,
20+
// verifying the redirect to Stripe or Affirm is all we can do consistently
21+
// without introducing a flaky test.
22+
await expect( page ).toHaveURL( /.*(affirm\.com|stripe\.com)/ );
23+
} );
24+
} );
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { test, expect } from '@playwright/test';
2+
import { admin, payments } from '../../../utils';
3+
4+
const { setupAffirmCheckout } = payments;
5+
6+
test.describe( 'Affirm payment tests @shortcode', () => {
7+
test.beforeAll( async ( { browser } ) => {
8+
await test.step( 'Setup test environment', async () => {
9+
// Enable Affirm in admin
10+
await admin.togglePaymentMethod( browser, 'Affirm', true );
11+
} );
12+
} );
13+
14+
test.describe.configure( { mode: 'parallel' } );
15+
16+
test( 'customer can pay with Affirm @smoke', async ( { page } ) => {
17+
await setupAffirmCheckout( page, 'shortcode' );
18+
await page.locator( 'text=Place order' ).click();
19+
// Since we don't have control over the Affirm payment flow,
20+
// verifying the redirect to Stripe or Affirm is all we can do consistently
21+
// without introducing a flaky test.
22+
await expect( page ).toHaveURL( /.*(affirm\.com|stripe\.com)/ );
23+
} );
24+
} );

tests/e2e/utils/payments.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,46 @@ export const fillBECSDetails = async ( page, checkoutType = 'blocks' ) => {
859859
await stripeFrame.locator( '[name="auBsb"]' ).fill( '000000' );
860860
};
861861

862+
/**
863+
* Set up the checkout page for Affirm payment.
864+
*
865+
* @param {Page} page Playwright page fixture.
866+
* @param {string} checkoutType The type of checkout ('blocks' or 'shortcode').
867+
*/
868+
export const setupAffirmCheckout = async ( page, checkoutType = 'blocks' ) => {
869+
// Affirm is only available when the price is above $50.
870+
const lineItems = [ [ config.get( 'products.simple.name' ), 5 ] ];
871+
872+
await emptyCart( page );
873+
await setupCart( page, lineItems );
874+
875+
const isBlocks = checkoutType === 'blocks';
876+
877+
// Fill billing details
878+
const billingDetails = config.get( 'addresses.customer.billing' );
879+
if ( isBlocks ) {
880+
await setupBlocksCheckout( page, billingDetails );
881+
} else {
882+
await setupShortcodeCheckout( page, billingDetails );
883+
}
884+
885+
await page.waitForTimeout( 1000 );
886+
887+
// Wait for the payment method selector to be available
888+
if ( isBlocks ) {
889+
await page
890+
.locator( 'label', { hasText: 'Affirm' } )
891+
.waitFor( { state: 'visible', timeout: 5000 } );
892+
await page.locator( 'label' ).filter( { hasText: 'Affirm' } ).click();
893+
} else {
894+
await page
895+
.getByText( 'Affirm' )
896+
.waitFor( { state: 'visible', timeout: 5000 } );
897+
await page.getByText( 'Affirm' ).click();
898+
}
899+
await page.waitForTimeout( 1000 );
900+
};
901+
862902
/**
863903
* Set up the checkout page for Klarna payment.
864904
*
@@ -895,6 +935,7 @@ export const setupKlarnaCheckout = async ( page, checkoutType = 'blocks' ) => {
895935
}
896936
await page.waitForTimeout( 1000 );
897937
};
938+
898939
/**
899940
* Complete the Klarna payment flow.
900941
*

0 commit comments

Comments
 (0)