Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Pre-Orders E2E Shortcode/Blocks Tests #3932

Merged
merged 23 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f29ffe3
Clean-up: Remove unused 'loginCustomerAndSaveState' function
lovo-h Feb 22, 2025
89c9382
Refactor: Re-use 'installPluginFromRepository()' function
lovo-h Feb 22, 2025
b66a2c2
Clean-up: Remove unused 'checkWooGutenbergProductsBlockVersion' import
lovo-h Feb 22, 2025
a95eb33
Add 'woocommerce-pre-orders' plugin as part of e2e global-setup
lovo-h Feb 22, 2025
a3625fb
Rephrase plugin installation errors' verbiage
lovo-h Feb 22, 2025
a4b1fbf
Add 'products' utility to re-use product data
lovo-h Feb 22, 2025
36055eb
Add Pre-Order e2e tests
lovo-h Feb 22, 2025
1d58d42
Update Stripe iFrame selectors
lovo-h Feb 25, 2025
fde397f
Fix legacy tests: Differentiate between UPE and legacy iFrame
lovo-h Feb 25, 2025
00ca1fe
Fix setup script to include the Pre-Orders plugin
lovo-h Feb 25, 2025
bd2e091
Add additional logging for Pre-Orders installation steps
lovo-h Feb 25, 2025
9249ba3
Merge branch 'develop' into add/pre-orders-e2e-tests
diegocurbelo Feb 25, 2025
97e1788
Enable DEBUG mode for docker setup
diegocurbelo Feb 25, 2025
3d21f42
Disable DEBUG mode
lovo-h Feb 25, 2025
7ba1bec
Code cleanup: Re-use E2E_ROOT variable
lovo-h Feb 25, 2025
fb40165
Fix installation path for Woo Pre-Orders
lovo-h Feb 25, 2025
1fdfaf3
Code clean-up: Add options variable for readability
lovo-h Feb 25, 2025
3d55a3a
Fix legacy E2E tests: Retrieve independent CC input iFrames
lovo-h Feb 26, 2025
218b89f
Merge branch 'develop' into add/pre-orders-e2e-tests
lovo-h Feb 26, 2025
d838091
Only run Pre-Order E2E tests if the plugin is installed
lovo-h Feb 27, 2025
f327b8b
Add quotation marks around text selectors
lovo-h Feb 27, 2025
1e90f06
Log selector used when error thrown because CC input field not found
lovo-h Feb 27, 2025
6e8ab30
Merge branch 'develop' into add/pre-orders-e2e-tests
lovo-h Feb 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions tests/e2e/bin/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,32 @@ rm -rf $E2E_ROOT/woocommerce-subscriptions.zip

redirect_output cli wp plugin activate woocommerce-subscriptions

step "Installing Woo Pre-Orders"
echo " - Fetching latest version"
LATEST_RELEASE_ASSET_ID=$(curl -sH "Authorization: token $GITHUB_TOKEN" https://api.github.com/repos/woocommerce/woocommerce-pre-orders/releases/latest | jq -r '.assets[0].id')

redirect_output curl -sLJ \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/octet-stream" \
--output $E2E_ROOT/woocommerce-pre-orders.zip \
https://api.github.com/repos/woocommerce/woocommerce-pre-orders/releases/assets/"$LATEST_RELEASE_ASSET_ID"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is an open-source plugin that anyone can contribute to, only people with access to this repository would be able to run the E2E tests. Wondering if we should not run pre-order tests by default.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or perhaps skip pre-order tests if the plugin isn’t installed successfully?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Addressed in d838091.


echo " - Installing"
redirect_output cli wp plugin install /var/www/html/wp-content/plugins/woocommerce-gateway-stripe/tests/e2e/woocommerce-pre-orders.zip --force

echo " - Removing lingering zip"
rm -rf $E2E_ROOT/woocommerce-pre-orders.zip

echo " - Activating"
redirect_output cli wp plugin activate woocommerce-pre-orders

echo
echo "============================================================"
echo "WordPress => $(cli wp core version)"
echo "WooCommerce => $(cli wp plugin get woocommerce --field=version)"
echo "Stripe => $(cli wp plugin get woocommerce-gateway-stripe --field=version)"
echo "Subscriptions => $(cli wp plugin get woocommerce-subscriptions --field=version)"
echo "Pre-Orders => $(cli wp plugin get woocommerce-pre-orders --field=version)"
echo "============================================================"
echo
step "E2E environment up and running at http://localhost:8088/wp-admin/"
75 changes: 54 additions & 21 deletions tests/e2e/config/global-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import {
installPluginFromRepository,
setupWoo,
setupStripe,
installWooSubscriptionsFromRepo,
checkWooGutenbergProductsBlockVersion,
} from '../utils/playwright-setup';

dotenv.config( {
Expand All @@ -21,6 +19,7 @@ const {
ADMIN_USER,
ADMIN_PASSWORD,
PLUGIN_VERSION,
PLUGIN_REPOSITORY,
WOO_SETUP,
STRIPE_SETUP,
STRIPE_PUB_KEY,
Expand All @@ -38,6 +37,41 @@ function wait( milliseconds ) {
} );
}

/**
* Install plugins from the respective repositories.
*
* @param {Page} page Playwright page fixture.
*
* @returns {Promise<unknown>}
*/
async function installPlugins( page ) {
let pluginSlug;

try {
// Install WooCommerce Subscriptions.
pluginSlug = 'woocommerce-subscriptions';
await installPluginFromRepository(
page,
`woocommerce/${ pluginSlug }`,
pluginSlug
);
// Install WooCommerce Pre-Orders.
pluginSlug = 'woocommerce-pre-orders';
await installPluginFromRepository(
page,
`woocommerce/${ pluginSlug }`,
pluginSlug
);
} catch ( e ) {
console.error( e );
console.error(
`Cannot proceed e2e test, as we could not install ${ pluginSlug }.`,
'Please check if the GITHUB_TOKEN env variable is valid.'
);
process.exit( 1 );
}
}

module.exports = async ( config ) => {
console.time( 'Total Setup Time' );
const { stateDir, baseURL, userAgent } = config.projects[ 0 ].use;
Expand Down Expand Up @@ -125,13 +159,13 @@ module.exports = async ( config ) => {
} )
.then( async () => {
const apiTokensPage = await adminContext.newPage();
const updatePluginPage = await adminContext.newPage();
const wooSubscriptionsInstallPage = await adminContext.newPage();
const pluginsInstallPage01 = await adminContext.newPage();
const pluginsInstallPage02 = await adminContext.newPage();

// create consumer token and update plugin in parallel.
let restApiKeysFinished = false;
let pluginUpdateFinished = false;
let wooSubscriptionsInstallFinished = false;
let pluginsInstallFinished = false;
let stripeSetupFinished = false;

createApiTokens( apiTokensPage )
Expand All @@ -146,14 +180,20 @@ module.exports = async ( config ) => {
} );

if ( PLUGIN_VERSION ) {
installPluginFromRepository( updatePluginPage )
installPluginFromRepository(
pluginsInstallPage01,
PLUGIN_REPOSITORY,
'woocommerce-gateway-stripe',
PLUGIN_VERSION
)
.then( () => {
pluginUpdateFinished = true;
} )
.catch( ( e ) => {
console.error( e );
console.error(
'Cannot proceed e2e test, as we could not update the plugin. Please check if the test site has been setup correctly.'
'Cannot proceed with e2e tests, as the plugin could not be installed.',
'Please check if the site has been setup correctly.'
);
process.exit( 1 );
} );
Expand All @@ -165,22 +205,15 @@ module.exports = async ( config ) => {
}

if ( WOO_SETUP && GITHUB_TOKEN ) {
installWooSubscriptionsFromRepo( wooSubscriptionsInstallPage )
.then( () => {
wooSubscriptionsInstallFinished = true;
} )
.catch( ( e ) => {
console.error( e );
console.error(
'Cannot proceed e2e test, as we could not install WooCommerce Subscriptions. Please check if the GITHUB_TOKEN env variable is valid.'
);
process.exit( 1 );
} );
installPlugins( pluginsInstallPage02 ).then( () => {
pluginsInstallFinished = true;
} );
} else {
console.log(
'Skipping WC Subscriptions setup. The version already installed on the test site will be used if needed.'
'Skipping plugins installation.',
'The plugin versions pre-installed on the site will be used, if needed.'
);
wooSubscriptionsInstallFinished = true;
pluginsInstallFinished = true;
}

if ( STRIPE_SETUP ) {
Expand Down Expand Up @@ -210,7 +243,7 @@ module.exports = async ( config ) => {
! pluginUpdateFinished ||
! restApiKeysFinished ||
! stripeSetupFinished ||
! wooSubscriptionsInstallFinished
! pluginsInstallFinished
) {
await wait( 1000 );
}
Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/test-data/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
"subscription": {
"name": "Subscription Product",
"type": "subscription"
},
"pre-order": {
"name": "Pre-Order Product",
"type": "simple"
}
},
"addresses": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect } from '@playwright/test';
import config from 'config';
import { payments, api } from '../../../utils';
import { api, payments, products } from '../../../utils';

const {
setupShortcodeCheckout,
Expand All @@ -10,22 +10,7 @@ const {
let productId;

test.beforeAll( async () => {
const product = {
...config.get( 'products.subscription' ),
regular_price: '9.99',
meta_data: [
{
key: '_subscription_period',
value: 'month',
},
{
key: '_subscription_period_interval',
value: '1',
},
],
};

productId = await api.create.product( product );
productId = await api.create.product( products.subscriptionData() );
} );

test.afterAll( async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect } from '@playwright/test';
import config from 'config';
import { payments, api, user } from '../../../utils';
import { api, payments, products, user } from '../../../utils';

const {
setupShortcodeCheckout,
Expand All @@ -25,22 +25,7 @@ test.beforeAll( async () => {

await api.create.customer( user );

const product = {
...config.get( 'products.subscription' ),
regular_price: '9.99',
meta_data: [
{
key: '_subscription_period',
value: 'month',
},
{
key: '_subscription_period_interval',
value: '1',
},
],
};

productId = await api.create.product( product );
productId = await api.create.product( products.subscriptionData() );
} );

test.afterAll( async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
import { test, expect } from '@playwright/test';
import config from 'config';
import { payments, api } from '../../../utils';
import { api, payments, products } from '../../../utils';

const { setupBlocksCheckout, fillCreditCardDetailsLegacy } = payments;

let productId;

test.beforeAll( async () => {
const product = {
...config.get( 'products.subscription' ),
regular_price: '9.99',
meta_data: [
{
key: '_subscription_period',
value: 'month',
},
{
key: '_subscription_period_interval',
value: '1',
},
],
};

productId = await api.create.product( product );
productId = await api.create.product( products.subscriptionData() );
} );

test.afterAll( async () => {
Expand Down
48 changes: 48 additions & 0 deletions tests/e2e/tests/checkout/blocks/pre-order-product.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { test, expect } from '@playwright/test';
import config from 'config';
import { api, payments, products } from '../../../utils';
import { isPluginInstalled } from '../../../utils/plugin-utils';

const { setupBlocksCheckout, fillCreditCardDetails } = payments;

let productId;

test.skip( async () => {
return ! ( await isPluginInstalled( 'woocommerce-pre-orders' ) );
}, 'Woo Pre-Orders plugin is not active. Skipping tests.' );

test.beforeAll( async () => {
productId = await api.create.product( products.preOrderData() );
} );

test.afterAll( async () => {
if ( ! productId ) {
return;
}

await api.deletePost.product( productId );
} );

test( 'customer can purchase a pre-order product @blocks @pre-orders', async ( {
page,
} ) => {
await page.goto( `?p=${ productId }` );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we are using permalinks but this is easier for redirecting the browser to the product URL without knowing the post slug.

await page.locator( 'button[name="add-to-cart"]' ).click();

// Subscriptions will create an account for this checkout, we need a random email.
const customerData = {
...config.get( 'addresses.customer.billing' ),
email:
Date.now() + '+' + config.get( 'addresses.customer.billing.email' ),
};

await setupBlocksCheckout( page, customerData );
await fillCreditCardDetails( page, config.get( 'cards.no-3ds' ) );

await page.locator( 'text="Place Order"' ).click();
await page.waitForURL( '**/checkout/order-received/**' );

await expect( page.locator( 'h1.entry-title' ) ).toHaveText(
'Order received'
);
} );
19 changes: 2 additions & 17 deletions tests/e2e/tests/checkout/blocks/subscription-product.spec.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
import { test, expect } from '@playwright/test';
import config from 'config';
import { payments, api } from '../../../utils';
import { api, payments, products } from '../../../utils';

const { setupBlocksCheckout, fillCreditCardDetails } = payments;

let productId;

test.beforeAll( async () => {
const product = {
...config.get( 'products.subscription' ),
regular_price: '9.99',
meta_data: [
{
key: '_subscription_period',
value: 'month',
},
{
key: '_subscription_period_interval',
value: '1',
},
],
};

productId = await api.create.product( product );
productId = await api.create.product( products.subscriptionData() );
} );

test.afterAll( async () => {
Expand Down
Loading
Loading