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:
parent
11b1e31ac3
commit
ec9cdbdbf7
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: fix
|
||||
|
||||
Fix k6 performance test that checks for incorrect title when viewing order page
|
|
@ -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`
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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"' ),
|
||||
} );
|
||||
} );
|
||||
}
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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 #<mark class="order-number">${ my_account_order_id }</mark> was placed`,
|
||||
footer: FOOTER_TEXT,
|
||||
} );
|
||||
} );
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
);
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 ) {
|
||||
|
|
|
@ -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 ) {
|
||||
|
|
Loading…
Reference in New Issue