Fix and improve k6 perf test My Account Open Order (#51334)

* Add customer id to orders and update test to look for proper title

* Add changelog

* Update my account open orders test and assign customer ID

* Fix linting issues

* Add final fix to the my account open order test

* Add customer order to test

* Add comment on the top of the file

* Add two more comments to the top of the file to avoid linting failure

* Revert changes made to response in test and orders

* Rename response to r in orders

* Remove unnecessary code from orders

* Move order creation to setup and update tests

* Include check for the order ID validation

* Relogic add customer order

* Rename test comment

* Update setup to create customer and config, readme, relevant tests

* Remove console log from the test
This commit is contained in:
Veljko V. 2024-09-19 11:14:20 +02:00 committed by GitHub
parent 11b1e31ac3
commit ec9cdbdbf7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 171 additions and 28 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Fix k6 performance test that checks for incorrect title when viewing order page

View File

@ -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_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` 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_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_password | password for customer user | yes `__ENV.C_PW`
customer_user_id | user id for customer user | yes `__ENV.C_UID` 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` hpos_status | set to true if site is using order tables | yes `__ENV.HPOS`

View File

@ -9,10 +9,13 @@ export const admin_username = __ENV.A_USER || 'admin';
export const admin_password = __ENV.A_PW || 'password'; export const admin_password = __ENV.A_PW || 'password';
export const admin_acc_login = __ENV.A_ACC_LOGIN || false; export const admin_acc_login = __ENV.A_ACC_LOGIN || false;
export const customer_username = export const customer_username = __ENV.C_USER || 'customer';
__ENV.C_USER || 'customer@woocommercecoree2etestsuite.com'; export const customer_email =
__ENV.C_EMAIL || 'customer@woocommercecoree2etestsuite.com';
export const customer_password = __ENV.C_PW || 'password'; export const customer_password = __ENV.C_PW || 'password';
export const customer_user_id = __ENV.C_UID || '2'; 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; export const hpos_status = __ENV.HPOS || false;

View File

@ -84,8 +84,8 @@ export function ordersAPI() {
); );
check( response, { check( response, {
'status is 201': ( r ) => r.status === 201, 'status is 201': ( r ) => r.status === 201,
"body contains: 'Pending' Status": ( response ) => "body contains: 'Pending' Status": ( r ) =>
response.body.includes( '"status":"pending"' ), r.body.includes( '"status":"pending"' ),
} ); } );
post_id = findBetween( response.body, '{"id":', ',' ); post_id = findBetween( response.body, '{"id":', ',' );
@ -102,8 +102,8 @@ export function ordersAPI() {
); );
check( response, { check( response, {
'status is 200': ( r ) => r.status === 200, 'status is 200': ( r ) => r.status === 200,
'body contains: Order ID': ( response ) => 'body contains: Order ID': ( r ) =>
response.body.includes( `"id":${ post_id }` ), r.body.includes( `"id":${ post_id }` ),
} ); } );
} }
} ); } );
@ -116,8 +116,8 @@ export function ordersAPI() {
} ); } );
check( response, { check( response, {
'status is 200': ( r ) => r.status === 200, 'status is 200': ( r ) => r.status === 200,
'body contains: Order ID': ( response ) => 'body contains: Order ID': ( r ) =>
response.body.includes( '[{"id":' ), r.body.includes( '[{"id":' ),
} ); } );
} }
} ); } );
@ -134,8 +134,8 @@ export function ordersAPI() {
); );
check( response, { check( response, {
'status is 200': ( r ) => r.status === 200, 'status is 200': ( r ) => r.status === 200,
"body contains: 'Completed' Status": ( response ) => "body contains: 'Completed' Status": ( r ) =>
response.body.includes( '"status":"completed"' ), r.body.includes( '"status":"completed"' ),
} ); } );
} }
} ); } );
@ -152,8 +152,8 @@ export function ordersAPI() {
); );
check( response, { check( response, {
'status is 200': ( r ) => r.status === 200, 'status is 200': ( r ) => r.status === 200,
'body contains: Order ID': ( response ) => 'body contains: Order ID': ( r ) =>
response.body.includes( `"id":${ post_id }` ), r.body.includes( `"id":${ post_id }` ),
} ); } );
} }
} ); } );
@ -176,8 +176,8 @@ export function ordersAPI() {
); );
check( response, { check( response, {
'status is 200': ( r ) => r.status === 200, 'status is 200': ( r ) => r.status === 200,
'body contains: Create batch prefix': ( response ) => 'body contains: Create batch prefix': ( r ) =>
response.body.includes( 'create":[{"id"' ), r.body.includes( 'create":[{"id"' ),
} ); } );
post_ids = findBetween( response.body, '{"id":', ',"parent_id', true ); post_ids = findBetween( response.body, '{"id":', ',"parent_id', true );
@ -213,8 +213,8 @@ export function ordersAPI() {
); );
check( response, { check( response, {
'status is 200': ( r ) => r.status === 200, 'status is 200': ( r ) => r.status === 200,
'body contains: Update batch prefix': ( response ) => 'body contains: Update batch prefix': ( r ) =>
response.body.includes( 'update":[{"id"' ), r.body.includes( 'update":[{"id"' ),
} ); } );
} ); } );
} }

View File

@ -14,7 +14,7 @@ import {
*/ */
import { import {
base_url, base_url,
customer_username, customer_email,
customer_password, customer_password,
addresses_customer_billing_first_name, addresses_customer_billing_first_name,
addresses_customer_billing_last_name, addresses_customer_billing_last_name,
@ -139,7 +139,7 @@ export function checkoutCustomerLogin() {
const response = http.post( const response = http.post(
`${ base_url }/checkout`, `${ base_url }/checkout`,
{ {
username: `${ customer_username }`, username: `${ customer_email }`,
password: `${ customer_password }`, password: `${ customer_password }`,
'woocommerce-login-nonce': `${ woocommerce_login_nonce }`, 'woocommerce-login-nonce': `${ woocommerce_login_nonce }`,
_wp_http_referer: '%2Fcheckout', _wp_http_referer: '%2Fcheckout',

View File

@ -2,7 +2,7 @@
/** /**
* External dependencies * External dependencies
*/ */
import { sleep, group } from 'k6'; import { sleep, group, check } from 'k6';
import http from 'k6/http'; import http from 'k6/http';
import { import {
randomIntBetween, 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, { checkResponse( response, 200, {
title: `My account ${ STORE_NAME }`, title: `Order #${ my_account_order_id } ${ STORE_NAME }`,
body: my_account_order_id, body: `Order #<mark class="order-number">${ my_account_order_id }</mark> was placed`,
footer: FOOTER_TEXT, footer: FOOTER_TEXT,
} ); } );
} ); } );

View File

@ -11,7 +11,7 @@ import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.1.0/index.js';
*/ */
import { import {
base_url, base_url,
customer_username, customer_email,
customer_password, customer_password,
think_time_min, think_time_min,
think_time_max, think_time_max,
@ -74,7 +74,7 @@ export function myAccount() {
response = http.post( response = http.post(
`${ base_url }/my-account`, `${ base_url }/my-account`,
{ {
username: `${ customer_username }`, username: `${ customer_email }`,
password: `${ customer_password }`, password: `${ customer_password }`,
'woocommerce-login-nonce': `${ woocommerce_login_nonce }`, 'woocommerce-login-nonce': `${ woocommerce_login_nonce }`,
_wp_http_referer: '/my-account', _wp_http_referer: '/my-account',

View File

@ -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,
}
);
}

View File

@ -1,3 +1,6 @@
/* eslint-disable jsdoc/require-property-description */
/* eslint-disable @woocommerce/dependency-group */
/* eslint-disable import/no-unresolved */
/** /**
* k6 dependencies * k6 dependencies
*/ */
@ -13,9 +16,10 @@ import { base_url, admin_username, admin_password } from '../config.js';
/** /**
* Convert Cart & Checkout pages to shortcode. * Convert Cart & Checkout pages to shortcode.
*/ */
export function useCartCheckoutShortcodes() { export function setCartCheckoutShortcodes() {
/** /**
* A WordPress page. * A WordPress page.
*
* @typedef {Object} WPPage * @typedef {Object} WPPage
* @property {number} id * @property {number} id
* @property {string} slug * @property {string} slug

View File

@ -21,6 +21,7 @@ import { ordersSearch } from '../requests/merchant/orders-search.js';
import { addOrder } from '../requests/merchant/add-order.js'; import { addOrder } from '../requests/merchant/add-order.js';
import { ordersAPI } from '../requests/api/orders.js'; import { ordersAPI } from '../requests/api/orders.js';
import { homeWCAdmin } from '../requests/merchant/home-wc-admin.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 shopper_request_threshold = 'p(95)<10000';
const merchant_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() { export function shopperBrowseFlow() {
homePage(); homePage();
shopPage(); shopPage();

View File

@ -22,7 +22,8 @@ import { ordersFilter } from '../requests/merchant/orders-filter.js';
import { addOrder } from '../requests/merchant/add-order.js'; import { addOrder } from '../requests/merchant/add-order.js';
import { ordersAPI } from '../requests/api/orders.js'; import { ordersAPI } from '../requests/api/orders.js';
import { homeWCAdmin } from '../requests/merchant/home-wc-admin.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 shopper_request_threshold = 'p(95)<10000';
const merchant_request_threshold = 'p(95)<10000'; const merchant_request_threshold = 'p(95)<10000';
@ -250,7 +251,8 @@ export const options = {
}; };
export function setup() { export function setup() {
useCartCheckoutShortcodes(); setCartCheckoutShortcodes();
addCustomerOrder();
} }
export function shopperBrowseFlow() { export function shopperBrowseFlow() {
@ -277,7 +279,12 @@ export function cartFlow() {
} }
export function allMerchantFlow() { export function allMerchantFlow() {
wpLogin(); wpLogin();
homeWCAdmin( { other: false, orders: false, reviews: false, products: false} ); homeWCAdmin( {
other: false,
orders: false,
reviews: false,
products: false,
} );
addOrder(); addOrder();
orders(); orders();
ordersSearch(); ordersSearch();

View File

@ -25,6 +25,7 @@ import { myAccountMerchantLogin } from '../requests/merchant/my-account-merchant
import { wpLogin } from '../requests/merchant/wp-login.js'; import { wpLogin } from '../requests/merchant/wp-login.js';
import { ordersAPI } from '../requests/api/orders.js'; import { ordersAPI } from '../requests/api/orders.js';
import { admin_acc_login } from '../config.js'; import { admin_acc_login } from '../config.js';
import { addCustomerOrder } from '../setup/add-customer-order.js';
const shopper_request_threshold = 'p(95)<100000'; const shopper_request_threshold = 'p(95)<100000';
const merchant_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. // Use myAccountMerchantLogin() instead of wpLogin() if having issues with login.
export function merchantOrderFlows() { export function merchantOrderFlows() {
if ( admin_acc_login === true ) { if ( admin_acc_login === true ) {
@ -277,7 +282,12 @@ export function merchantOtherFlows() {
wpLogin(); wpLogin();
} }
homeWCAdmin( { other: false, products: false, reviews: false } ); 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(); coupons();
} }
export function shopperBrowsingFlows() { export function shopperBrowsingFlows() {

View File

@ -25,6 +25,7 @@ import { wpLogin } from '../requests/merchant/wp-login.js';
import { myAccountMerchantLogin } from '../requests/merchant/my-account-merchant.js'; import { myAccountMerchantLogin } from '../requests/merchant/my-account-merchant.js';
import { ordersAPI } from '../requests/api/orders.js'; import { ordersAPI } from '../requests/api/orders.js';
import { admin_acc_login } from '../config.js'; import { admin_acc_login } from '../config.js';
import { addCustomerOrder } from '../setup/add-customer-order.js';
const shopper_request_threshold = 'p(95)<10000'; const shopper_request_threshold = 'p(95)<10000';
const merchant_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() { export function shopperBrowseFlow() {
homePage(); homePage();
shopPage(); shopPage();

View File

@ -26,6 +26,7 @@ import { myAccountMerchantLogin } from '../requests/merchant/my-account-merchant
import { wpLogin } from '../requests/merchant/wp-login.js'; import { wpLogin } from '../requests/merchant/wp-login.js';
import { ordersAPI } from '../requests/api/orders.js'; import { ordersAPI } from '../requests/api/orders.js';
import { admin_acc_login } from '../config.js'; import { admin_acc_login } from '../config.js';
import { addCustomerOrder } from '../setup/add-customer-order.js';
const shopper_request_threshold = 'p(95)<100000'; const shopper_request_threshold = 'p(95)<100000';
const merchant_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. // Use myAccountMerchantLogin() instead of wpLogin() if having issues with login.
export function merchantOrderFlows() { export function merchantOrderFlows() {
if ( admin_acc_login === true ) { if ( admin_acc_login === true ) {

View File

@ -26,6 +26,7 @@ import { myAccountMerchantLogin } from '../requests/merchant/my-account-merchant
import { wpLogin } from '../requests/merchant/wp-login.js'; import { wpLogin } from '../requests/merchant/wp-login.js';
import { ordersAPI } from '../requests/api/orders.js'; import { ordersAPI } from '../requests/api/orders.js';
import { admin_acc_login } from '../config.js'; import { admin_acc_login } from '../config.js';
import { addCustomerOrder } from '../setup/add-customer-order.js';
const shopper_request_threshold = 'p(95)<100000'; const shopper_request_threshold = 'p(95)<100000';
const merchant_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. // Use myAccountMerchantLogin() instead of wpLogin() if having issues with login.
export function merchantOrderFlows() { export function merchantOrderFlows() {
if ( admin_acc_login === true ) { if ( admin_acc_login === true ) {