diff --git a/plugins/woocommerce/changelog/k6-performance-fix-my-account-open-orders-test b/plugins/woocommerce/changelog/k6-performance-fix-my-account-open-orders-test new file mode 100644 index 00000000000..ba1449e0385 --- /dev/null +++ b/plugins/woocommerce/changelog/k6-performance-fix-my-account-open-orders-test @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Fix k6 performance test that checks for incorrect title when viewing order page diff --git a/plugins/woocommerce/tests/performance/README.md b/plugins/woocommerce/tests/performance/README.md index d5554c63035..8cb416a6101 100644 --- a/plugins/woocommerce/tests/performance/README.md +++ b/plugins/woocommerce/tests/performance/README.md @@ -75,6 +75,7 @@ admin_username | username for admin user | yes `__ENV.A_USER` admin_password | password for admin user | yes `__ENV.A_PW` admin_acc_login | set to true if site needs to use my account for admin login | yes `__ENV.A_ACC_LOGIN` customer_username | username for customer user | yes `__ENV.C_USER` +customer_email | email for customer user | yes `__ENV.C_EMAIL` customer_password | password for customer user | yes `__ENV.C_PW` customer_user_id | user id for customer user | yes `__ENV.C_UID` hpos_status | set to true if site is using order tables | yes `__ENV.HPOS` diff --git a/plugins/woocommerce/tests/performance/config.js b/plugins/woocommerce/tests/performance/config.js index d4638940de0..6b9db4491c5 100644 --- a/plugins/woocommerce/tests/performance/config.js +++ b/plugins/woocommerce/tests/performance/config.js @@ -9,10 +9,13 @@ export const admin_username = __ENV.A_USER || 'admin'; export const admin_password = __ENV.A_PW || 'password'; export const admin_acc_login = __ENV.A_ACC_LOGIN || false; -export const customer_username = - __ENV.C_USER || 'customer@woocommercecoree2etestsuite.com'; +export const customer_username = __ENV.C_USER || 'customer'; +export const customer_email = + __ENV.C_EMAIL || 'customer@woocommercecoree2etestsuite.com'; export const customer_password = __ENV.C_PW || 'password'; export const customer_user_id = __ENV.C_UID || '2'; +export const customer_first_name = 'Jane'; +export const customer_last_name = 'Smith'; export const hpos_status = __ENV.HPOS || false; diff --git a/plugins/woocommerce/tests/performance/requests/api/orders.js b/plugins/woocommerce/tests/performance/requests/api/orders.js index 26ca0fb6a98..f3913a93bc9 100644 --- a/plugins/woocommerce/tests/performance/requests/api/orders.js +++ b/plugins/woocommerce/tests/performance/requests/api/orders.js @@ -84,8 +84,8 @@ export function ordersAPI() { ); check( response, { 'status is 201': ( r ) => r.status === 201, - "body contains: 'Pending' Status": ( response ) => - response.body.includes( '"status":"pending"' ), + "body contains: 'Pending' Status": ( r ) => + r.body.includes( '"status":"pending"' ), } ); post_id = findBetween( response.body, '{"id":', ',' ); @@ -102,8 +102,8 @@ export function ordersAPI() { ); check( response, { 'status is 200': ( r ) => r.status === 200, - 'body contains: Order ID': ( response ) => - response.body.includes( `"id":${ post_id }` ), + 'body contains: Order ID': ( r ) => + r.body.includes( `"id":${ post_id }` ), } ); } } ); @@ -116,8 +116,8 @@ export function ordersAPI() { } ); check( response, { 'status is 200': ( r ) => r.status === 200, - 'body contains: Order ID': ( response ) => - response.body.includes( '[{"id":' ), + 'body contains: Order ID': ( r ) => + r.body.includes( '[{"id":' ), } ); } } ); @@ -134,8 +134,8 @@ export function ordersAPI() { ); check( response, { 'status is 200': ( r ) => r.status === 200, - "body contains: 'Completed' Status": ( response ) => - response.body.includes( '"status":"completed"' ), + "body contains: 'Completed' Status": ( r ) => + r.body.includes( '"status":"completed"' ), } ); } } ); @@ -152,8 +152,8 @@ export function ordersAPI() { ); check( response, { 'status is 200': ( r ) => r.status === 200, - 'body contains: Order ID': ( response ) => - response.body.includes( `"id":${ post_id }` ), + 'body contains: Order ID': ( r ) => + r.body.includes( `"id":${ post_id }` ), } ); } } ); @@ -176,8 +176,8 @@ export function ordersAPI() { ); check( response, { 'status is 200': ( r ) => r.status === 200, - 'body contains: Create batch prefix': ( response ) => - response.body.includes( 'create":[{"id"' ), + 'body contains: Create batch prefix': ( r ) => + r.body.includes( 'create":[{"id"' ), } ); post_ids = findBetween( response.body, '{"id":', ',"parent_id', true ); @@ -213,8 +213,8 @@ export function ordersAPI() { ); check( response, { 'status is 200': ( r ) => r.status === 200, - 'body contains: Update batch prefix': ( response ) => - response.body.includes( 'update":[{"id"' ), + 'body contains: Update batch prefix': ( r ) => + r.body.includes( 'update":[{"id"' ), } ); } ); } diff --git a/plugins/woocommerce/tests/performance/requests/shopper/checkout-customer-login.js b/plugins/woocommerce/tests/performance/requests/shopper/checkout-customer-login.js index 4be19fc4824..f4dc42d257b 100644 --- a/plugins/woocommerce/tests/performance/requests/shopper/checkout-customer-login.js +++ b/plugins/woocommerce/tests/performance/requests/shopper/checkout-customer-login.js @@ -14,7 +14,7 @@ import { */ import { base_url, - customer_username, + customer_email, customer_password, addresses_customer_billing_first_name, addresses_customer_billing_last_name, @@ -139,7 +139,7 @@ export function checkoutCustomerLogin() { const response = http.post( `${ base_url }/checkout`, { - username: `${ customer_username }`, + username: `${ customer_email }`, password: `${ customer_password }`, 'woocommerce-login-nonce': `${ woocommerce_login_nonce }`, _wp_http_referer: '%2Fcheckout', diff --git a/plugins/woocommerce/tests/performance/requests/shopper/my-account-orders.js b/plugins/woocommerce/tests/performance/requests/shopper/my-account-orders.js index 789a3eb185f..f257e1890d5 100644 --- a/plugins/woocommerce/tests/performance/requests/shopper/my-account-orders.js +++ b/plugins/woocommerce/tests/performance/requests/shopper/my-account-orders.js @@ -2,7 +2,7 @@ /** * External dependencies */ -import { sleep, group } from 'k6'; +import { sleep, group, check } from 'k6'; import http from 'k6/http'; import { randomIntBetween, @@ -98,9 +98,15 @@ export function myAccountOrders() { } ); + check( my_account_order_id, { + 'order ID is not undefined': () => { + return !! my_account_order_id; + }, + } ); + checkResponse( response, 200, { - title: `My account – ${ STORE_NAME }`, - body: my_account_order_id, + title: `Order #${ my_account_order_id } – ${ STORE_NAME }`, + body: `Order #${ my_account_order_id } was placed`, footer: FOOTER_TEXT, } ); } ); diff --git a/plugins/woocommerce/tests/performance/requests/shopper/my-account.js b/plugins/woocommerce/tests/performance/requests/shopper/my-account.js index ec1f70c930b..1f4def3b77d 100644 --- a/plugins/woocommerce/tests/performance/requests/shopper/my-account.js +++ b/plugins/woocommerce/tests/performance/requests/shopper/my-account.js @@ -11,7 +11,7 @@ import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.1.0/index.js'; */ import { base_url, - customer_username, + customer_email, customer_password, think_time_min, think_time_max, @@ -74,7 +74,7 @@ export function myAccount() { response = http.post( `${ base_url }/my-account`, { - username: `${ customer_username }`, + username: `${ customer_email }`, password: `${ customer_password }`, 'woocommerce-login-nonce': `${ woocommerce_login_nonce }`, _wp_http_referer: '/my-account', diff --git a/plugins/woocommerce/tests/performance/setup/add-customer-order.js b/plugins/woocommerce/tests/performance/setup/add-customer-order.js new file mode 100644 index 00000000000..543e27c8e90 --- /dev/null +++ b/plugins/woocommerce/tests/performance/setup/add-customer-order.js @@ -0,0 +1,88 @@ +/* eslint-disable jsdoc/require-property-description */ +/* eslint-disable @woocommerce/dependency-group */ +/* eslint-disable import/no-unresolved */ +/** + * k6 dependencies + */ +import encoding from 'k6/encoding'; +import http from 'k6/http'; + +/** + * Internal dependencies + */ +import { + base_url, + admin_username, + admin_password, + customer_username, + customer_email, + customer_password, + customer_first_name, + customer_last_name, +} from '../config.js'; + +/** + * Add a customer order specifically for my-account-orders.js test + */ +export function addCustomerOrder() { + let response; + const customerUsername = 'customer'; + + const credentials = `${ admin_username }:${ admin_password }`; + const encodedCredentials = encoding.b64encode( credentials ); + const requestHeaders = { + Authorization: `Basic ${ encodedCredentials }`, + 'Content-Type': 'application/json', + }; + + // Fetch the list of customers + response = http.get( `${ base_url }/wp-json/wc/v3/customers`, { + headers: requestHeaders, + } ); + + // Parse the response body as JSON to find the customer by username + const customers = JSON.parse( response.body ); + let customerId = null; + + for ( let i = 0; i < customers.length; i++ ) { + if ( customers[ i ].username === customerUsername ) { + customerId = customers[ i ].id; + break; + } + } + + // If customer doesn't exist, create the customer + if ( ! customerId ) { + console.log( + `Customer with username ${ customer_username } not found. Creating new customer...` + ); + const createCustomerData = { + username: customer_username, + password: customer_password, + email: customer_email, + first_name: customer_first_name, + last_name: customer_last_name, + }; + + response = http.post( + `${ base_url }/wp-json/wc/v3/customers`, + JSON.stringify( createCustomerData ), + { + headers: requestHeaders, + } + ); + } + + // Create a new order for the identified customer + const createCustomerOrderData = { + customer_id: customerId, + status: 'completed', + }; + response = http.post( + `${ base_url }/wp-json/wc/v3/orders`, + JSON.stringify( createCustomerOrderData ), + { + headers: requestHeaders, + } + ); +} diff --git a/plugins/woocommerce/tests/performance/setup/cart-checkout-shortcode.js b/plugins/woocommerce/tests/performance/setup/cart-checkout-shortcode.js index eaa5204ef70..77f61655366 100644 --- a/plugins/woocommerce/tests/performance/setup/cart-checkout-shortcode.js +++ b/plugins/woocommerce/tests/performance/setup/cart-checkout-shortcode.js @@ -1,3 +1,6 @@ +/* eslint-disable jsdoc/require-property-description */ +/* eslint-disable @woocommerce/dependency-group */ +/* eslint-disable import/no-unresolved */ /** * k6 dependencies */ @@ -13,9 +16,10 @@ import { base_url, admin_username, admin_password } from '../config.js'; /** * Convert Cart & Checkout pages to shortcode. */ -export function useCartCheckoutShortcodes() { +export function setCartCheckoutShortcodes() { /** * A WordPress page. + * * @typedef {Object} WPPage * @property {number} id * @property {string} slug diff --git a/plugins/woocommerce/tests/performance/tests/gh-action-daily-ext-requests.js b/plugins/woocommerce/tests/performance/tests/gh-action-daily-ext-requests.js index 7ecec81086e..f0ce502d2c2 100644 --- a/plugins/woocommerce/tests/performance/tests/gh-action-daily-ext-requests.js +++ b/plugins/woocommerce/tests/performance/tests/gh-action-daily-ext-requests.js @@ -21,6 +21,7 @@ import { ordersSearch } from '../requests/merchant/orders-search.js'; import { addOrder } from '../requests/merchant/add-order.js'; import { ordersAPI } from '../requests/api/orders.js'; import { homeWCAdmin } from '../requests/merchant/home-wc-admin.js'; +import { addCustomerOrder } from '../setup/add-customer-order.js'; const shopper_request_threshold = 'p(95)<10000'; const merchant_request_threshold = 'p(95)<10000'; @@ -247,6 +248,10 @@ export const options = { }, }; +export function setup() { + addCustomerOrder(); +} + export function shopperBrowseFlow() { homePage(); shopPage(); diff --git a/plugins/woocommerce/tests/performance/tests/gh-action-pr-requests.js b/plugins/woocommerce/tests/performance/tests/gh-action-pr-requests.js index c06aed22d2b..37780d605dc 100644 --- a/plugins/woocommerce/tests/performance/tests/gh-action-pr-requests.js +++ b/plugins/woocommerce/tests/performance/tests/gh-action-pr-requests.js @@ -22,7 +22,8 @@ import { ordersFilter } from '../requests/merchant/orders-filter.js'; import { addOrder } from '../requests/merchant/add-order.js'; import { ordersAPI } from '../requests/api/orders.js'; import { homeWCAdmin } from '../requests/merchant/home-wc-admin.js'; -import { useCartCheckoutShortcodes } from '../setup/cart-checkout-shortcode.js'; +import { setCartCheckoutShortcodes } from '../setup/cart-checkout-shortcode.js'; +import { addCustomerOrder } from '../setup/add-customer-order.js'; const shopper_request_threshold = 'p(95)<10000'; const merchant_request_threshold = 'p(95)<10000'; @@ -250,7 +251,8 @@ export const options = { }; export function setup() { - useCartCheckoutShortcodes(); + setCartCheckoutShortcodes(); + addCustomerOrder(); } export function shopperBrowseFlow() { @@ -277,7 +279,12 @@ export function cartFlow() { } export function allMerchantFlow() { wpLogin(); - homeWCAdmin( { other: false, orders: false, reviews: false, products: false} ); + homeWCAdmin( { + other: false, + orders: false, + reviews: false, + products: false, + } ); addOrder(); orders(); ordersSearch(); diff --git a/plugins/woocommerce/tests/performance/tests/hpos-baseline-load.js b/plugins/woocommerce/tests/performance/tests/hpos-baseline-load.js index 17a937d903b..291a2e4e2ec 100644 --- a/plugins/woocommerce/tests/performance/tests/hpos-baseline-load.js +++ b/plugins/woocommerce/tests/performance/tests/hpos-baseline-load.js @@ -25,6 +25,7 @@ import { myAccountMerchantLogin } from '../requests/merchant/my-account-merchant import { wpLogin } from '../requests/merchant/wp-login.js'; import { ordersAPI } from '../requests/api/orders.js'; import { admin_acc_login } from '../config.js'; +import { addCustomerOrder } from '../setup/add-customer-order.js'; const shopper_request_threshold = 'p(95)<100000'; const merchant_request_threshold = 'p(95)<100000'; @@ -256,6 +257,10 @@ export const options = { }, }; +export function setup() { + addCustomerOrder(); +} + // Use myAccountMerchantLogin() instead of wpLogin() if having issues with login. export function merchantOrderFlows() { if ( admin_acc_login === true ) { @@ -277,7 +282,12 @@ export function merchantOtherFlows() { wpLogin(); } homeWCAdmin( { other: false, products: false, reviews: false } ); - addProduct( { heartbeat: false, other: false, permalink: false, update: false } ); + addProduct( { + heartbeat: false, + other: false, + permalink: false, + update: false, + } ); coupons(); } export function shopperBrowsingFlows() { diff --git a/plugins/woocommerce/tests/performance/tests/simple-all-requests.js b/plugins/woocommerce/tests/performance/tests/simple-all-requests.js index 52c79b9dc52..172503d45fe 100644 --- a/plugins/woocommerce/tests/performance/tests/simple-all-requests.js +++ b/plugins/woocommerce/tests/performance/tests/simple-all-requests.js @@ -25,6 +25,7 @@ import { wpLogin } from '../requests/merchant/wp-login.js'; import { myAccountMerchantLogin } from '../requests/merchant/my-account-merchant.js'; import { ordersAPI } from '../requests/api/orders.js'; import { admin_acc_login } from '../config.js'; +import { addCustomerOrder } from '../setup/add-customer-order.js'; const shopper_request_threshold = 'p(95)<10000'; const merchant_request_threshold = 'p(95)<10000'; @@ -251,6 +252,10 @@ export const options = { }, }; +export function setup() { + addCustomerOrder(); +} + export function shopperBrowseFlow() { homePage(); shopPage(); diff --git a/plugins/woocommerce/tests/performance/tests/wc-baseline-load.js b/plugins/woocommerce/tests/performance/tests/wc-baseline-load.js index cd39d327319..988cf49b16c 100644 --- a/plugins/woocommerce/tests/performance/tests/wc-baseline-load.js +++ b/plugins/woocommerce/tests/performance/tests/wc-baseline-load.js @@ -26,6 +26,7 @@ import { myAccountMerchantLogin } from '../requests/merchant/my-account-merchant import { wpLogin } from '../requests/merchant/wp-login.js'; import { ordersAPI } from '../requests/api/orders.js'; import { admin_acc_login } from '../config.js'; +import { addCustomerOrder } from '../setup/add-customer-order.js'; const shopper_request_threshold = 'p(95)<100000'; const merchant_request_threshold = 'p(95)<100000'; @@ -282,6 +283,10 @@ export const options = { }, }; +export function setup() { + addCustomerOrder(); +} + // Use myAccountMerchantLogin() instead of wpLogin() if having issues with login. export function merchantOrderFlows() { if ( admin_acc_login === true ) { diff --git a/plugins/woocommerce/tests/performance/tests/wc-regression-test-load.js b/plugins/woocommerce/tests/performance/tests/wc-regression-test-load.js index 57a4698feff..69c9d33d52d 100644 --- a/plugins/woocommerce/tests/performance/tests/wc-regression-test-load.js +++ b/plugins/woocommerce/tests/performance/tests/wc-regression-test-load.js @@ -26,6 +26,7 @@ import { myAccountMerchantLogin } from '../requests/merchant/my-account-merchant import { wpLogin } from '../requests/merchant/wp-login.js'; import { ordersAPI } from '../requests/api/orders.js'; import { admin_acc_login } from '../config.js'; +import { addCustomerOrder } from '../setup/add-customer-order.js'; const shopper_request_threshold = 'p(95)<100000'; const merchant_request_threshold = 'p(95)<100000'; @@ -282,6 +283,10 @@ export const options = { }, }; +export function setup() { + addCustomerOrder(); +} + // Use myAccountMerchantLogin() instead of wpLogin() if having issues with login. export function merchantOrderFlows() { if ( admin_acc_login === true ) {