diff --git a/plugins/woocommerce/changelog/add-k6-order-api-tests b/plugins/woocommerce/changelog/add-k6-order-api-tests new file mode 100644 index 00000000000..d4fe651516f --- /dev/null +++ b/plugins/woocommerce/changelog/add-k6-order-api-tests @@ -0,0 +1,5 @@ +Significance: patch +Type: add +Comment: Additional k6 order tests + + diff --git a/plugins/woocommerce/tests/performance/README.md b/plugins/woocommerce/tests/performance/README.md index 1b246cbff21..8b00be00b4c 100644 --- a/plugins/woocommerce/tests/performance/README.md +++ b/plugins/woocommerce/tests/performance/README.md @@ -79,6 +79,7 @@ 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_PW` customer_username | username for customer user | yes `__ENV.C_USER` customer_password | password for customer user | yes `__ENV.C_PW` +customer_user_id | user id for customer user | yes `__ENV.C_UID` cot_status | set to true if site is using order tables | yes `__ENV.C_PW` admin_orders_base_url | url part for order urls when posts table is used | no cot_admin_orders_base_url | url part for order urls when orders table is used | no diff --git a/plugins/woocommerce/tests/performance/config.js b/plugins/woocommerce/tests/performance/config.js index c2b8ada3fef..76abf6e546b 100644 --- a/plugins/woocommerce/tests/performance/config.js +++ b/plugins/woocommerce/tests/performance/config.js @@ -9,6 +9,7 @@ export const admin_acc_login = __ENV.A_ACC_LOGIN || false; export const customer_username = __ENV.C_USER || 'customer@woocommercecoree2etestsuite.com'; export const customer_password = __ENV.C_PW || 'password'; +export const customer_user_id = __ENV.C_UID || '2'; export const cot_status = __ENV.COT || false; diff --git a/plugins/woocommerce/tests/performance/requests/api/orders.js b/plugins/woocommerce/tests/performance/requests/api/orders.js new file mode 100644 index 00000000000..fbb88aadcfd --- /dev/null +++ b/plugins/woocommerce/tests/performance/requests/api/orders.js @@ -0,0 +1,212 @@ +/* eslint-disable no-shadow */ +/* eslint-disable import/no-unresolved */ +/** + * External dependencies + */ +import encoding from 'k6/encoding'; +import http from 'k6/http'; +import { check, group } from 'k6'; +import { findBetween } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js'; + +/** + * Internal dependencies + */ +import { + base_url, + admin_username, + admin_password, + addresses_guest_billing_first_name, + addresses_guest_billing_last_name, + addresses_guest_billing_country, + addresses_guest_billing_address_1, + addresses_guest_billing_address_2, + addresses_guest_billing_city, + addresses_guest_billing_state, + addresses_guest_billing_postcode, + addresses_guest_billing_phone, + addresses_guest_billing_email, +} from '../../config.js'; + +export function ordersAPI() { + const credentials = `${ admin_username }:${ admin_password }`; + const encodedCredentials = encoding.b64encode( credentials ); + const requestHeaders = { + Authorization: `Basic ${ encodedCredentials }`, + 'Content-Type': 'application/json', + }; + + const createData = { + billing: { + first_name: `${ addresses_guest_billing_first_name }`, + last_name: `${ addresses_guest_billing_last_name }`, + address_1: `${ addresses_guest_billing_address_1 }`, + address_2: `${ addresses_guest_billing_address_2 }`, + city: `${ addresses_guest_billing_city }`, + state: `${ addresses_guest_billing_state }`, + postcode: `${ addresses_guest_billing_postcode }`, + country: `${ addresses_guest_billing_country }`, + email: `${ addresses_guest_billing_email }`, + phone: `${ addresses_guest_billing_phone }`, + }, + shipping: { + first_name: `${ addresses_guest_billing_first_name }`, + last_name: `${ addresses_guest_billing_last_name }`, + address_1: `${ addresses_guest_billing_address_1 }`, + address_2: `${ addresses_guest_billing_address_2 }`, + city: `${ addresses_guest_billing_city }`, + state: `${ addresses_guest_billing_state }`, + postcode: `${ addresses_guest_billing_postcode }`, + country: `${ addresses_guest_billing_country }`, + }, + }; + + let batchData; + const createBatchData = []; + const updateBatchData = []; + + const batchSize = 10; + + const updateData = { + status: 'completed', + }; + let post_id; + let post_ids; + let response; + + group( 'API Create Order', function () { + response = http.post( + `${ base_url }/wp-json/wc/v3/orders`, + JSON.stringify( createData ), + { + headers: requestHeaders, + tags: { name: 'API - Create Order' }, + } + ); + check( response, { + 'status is 201': ( r ) => r.status === 201, + "body contains: 'Pending' Status": ( response ) => + response.body.includes( '"status":"pending"' ), + } ); + + post_id = findBetween( response.body, '{"id":', ',' ); + } ); + + group( 'API Retrieve Order', function () { + response = http.get( + `${ base_url }/wp-json/wc/v3/orders/${ post_id }`, + { + headers: requestHeaders, + tags: { name: 'API - Retrieve Order' }, + } + ); + check( response, { + 'status is 200': ( r ) => r.status === 200, + 'body contains: Order ID': ( response ) => + response.body.includes( `"id":${ post_id }` ), + } ); + } ); + + group( 'API List Orders', function () { + response = http.get( `${ base_url }/wp-json/wc/v3/orders`, { + headers: requestHeaders, + tags: { name: 'API - List Orders' }, + } ); + check( response, { + 'status is 200': ( r ) => r.status === 200, + 'body contains: Order ID': ( response ) => + response.body.includes( '[{"id":' ), + } ); + } ); + + group( 'API Update Order', function () { + response = http.put( + `${ base_url }/wp-json/wc/v3/orders/${ post_id }`, + JSON.stringify( updateData ), + { + headers: requestHeaders, + tags: { name: 'API - Update Order (Status)' }, + } + ); + check( response, { + 'status is 200': ( r ) => r.status === 200, + "body contains: 'Completed' Status": ( response ) => + response.body.includes( '"status":"completed"' ), + } ); + } ); + + group( 'API Delete Order', function () { + response = http.del( + `${ base_url }/wp-json/wc/v3/orders/${ post_id }`, + JSON.stringify( { force: true } ), + { + headers: requestHeaders, + tags: { name: 'API - Delete Order' }, + } + ); + check( response, { + 'status is 200': ( r ) => r.status === 200, + 'body contains: Order ID': ( response ) => + response.body.includes( `"id":${ post_id }` ), + } ); + } ); + + group( 'API Batch Create Orders', function () { + for ( let index = 0; index < batchSize; index++ ) { + createBatchData.push( createData ); + } + batchData = { + create: createBatchData, + }; + + response = http.post( + `${ base_url }/wp-json/wc/v3/orders/batch`, + JSON.stringify( batchData ), + { + headers: requestHeaders, + tags: { name: 'API - Batch Create Orders' }, + } + ); + check( response, { + 'status is 200': ( r ) => r.status === 200, + 'body contains: Create batch prefix': ( response ) => + response.body.includes( 'create":[{"id"' ), + } ); + + post_ids = findBetween( response.body, '{"id":', ',"parent_id', true ); + } ); + + group( 'API Batch Update Orders', function () { + let updateBatchItem; + + for ( let index = 0; index < batchSize; index++ ) { + updateBatchItem = { + id: `${ post_ids[ index ] }`, + status: 'completed', + }; + updateBatchData.push( updateBatchItem ); + } + batchData = { + update: updateBatchData, + }; + + response = http.post( + `${ base_url }/wp-json/wc/v3/orders/batch`, + JSON.stringify( batchData ), + { + headers: requestHeaders, + tags: { + name: 'API - Batch Update (Status) Orders', + }, + } + ); + check( response, { + 'status is 200': ( r ) => r.status === 200, + 'body contains: Update batch prefix': ( response ) => + response.body.includes( 'update":[{"id"' ), + } ); + } ); +} + +export default function () { + ordersAPI(); +} diff --git a/plugins/woocommerce/tests/performance/requests/merchant/add-order.js b/plugins/woocommerce/tests/performance/requests/merchant/add-order.js new file mode 100644 index 00000000000..6020ffaa832 --- /dev/null +++ b/plugins/woocommerce/tests/performance/requests/merchant/add-order.js @@ -0,0 +1,587 @@ +/* eslint-disable no-shadow */ +/* eslint-disable import/no-unresolved */ +/** + * External dependencies + */ +import { sleep, check, group } from 'k6'; +import http from 'k6/http'; +import { + randomIntBetween, + findBetween, +} from 'https://jslib.k6.io/k6-utils/1.1.0/index.js'; + +/** + * Internal dependencies + */ +import { + base_url, + cot_status, + addresses_guest_billing_first_name, + addresses_guest_billing_last_name, + addresses_guest_billing_company, + addresses_guest_billing_country, + addresses_guest_billing_address_1, + addresses_guest_billing_address_2, + addresses_guest_billing_city, + addresses_guest_billing_state, + addresses_guest_billing_postcode, + addresses_guest_billing_phone, + addresses_guest_billing_email, + payment_method, + think_time_min, + think_time_max, +} from '../../config.js'; +import { + htmlRequestHeader, + jsonAPIRequestHeader, + jsonRequestHeader, + commonRequestHeaders, + commonGetRequestHeaders, + contentTypeRequestHeader, + commonPostRequestHeaders, + commonAPIGetRequestHeaders, + commonNonStandardHeaders, +} from '../../headers.js'; + +// Change URL if COT is enabled and being used +let admin_new_order_base; +let admin_new_order_assert; +let admin_created_order_assert; +let admin_open_order_base; +let admin_open_order_assert; +let admin_update_order_base; +let admin_update_order_id; +let admin_update_order_params; +let admin_update_order_assert; + +if ( cot_status === true ) { + admin_new_order_base = 'admin.php?page=wc-orders&action=new'; + admin_update_order_base = 'admin.php?page=wc-orders&action=edit'; + admin_new_order_assert = 'Edit order '; + admin_open_order_assert = 'Edit order '; + admin_created_order_assert = 'changed from auto-draft to'; + admin_update_order_assert = 'changed from auto-draft to'; +} else { + admin_new_order_base = 'post-new.php?post_type=shop_order'; + admin_update_order_base = 'post.php'; + admin_new_order_assert = 'Add new order'; + admin_open_order_assert = 'Edit order'; + admin_created_order_assert = 'Order updated.'; + admin_update_order_assert = 'Order updated.'; +} + +const date = new Date(); +const order_date = date.toJSON().slice( 0, 10 ); + +export function addOrder() { + let response; + let ajax_nonce_add_meta; + let wpnonce; + let closed_postboxes_nonce; + let sample_permalink_nonce; + let woocommerce_meta_nonce; + let meta_box_order_nonce; + let post_id; + let hpos_post_id; + let api_x_wp_nonce; + let apiNonceHeader; + let heartbeat_nonce; + + group( 'Add Order', function () { + const requestHeaders = Object.assign( + {}, + htmlRequestHeader, + commonRequestHeaders, + commonGetRequestHeaders, + commonNonStandardHeaders + ); + + response = http.get( + `${ base_url }/wp-admin/${ admin_new_order_base }`, + { + headers: requestHeaders, + tags: { name: 'Merchant - New Order Page' }, + } + ); + check( response, { + 'is status 200': ( r ) => r.status === 200, + "body contains: 'Add new order' header": ( response ) => + response.body.includes( `${ admin_new_order_assert }` ), + } ); + + // Correlate nonce values for use in subsequent requests. + ajax_nonce_add_meta = response + .html() + .find( 'input[id=_ajax_nonce-add-meta]' ) + .first() + .attr( 'value' ); + wpnonce = response + .html() + .find( 'input[id=_wpnonce]' ) + .first() + .attr( 'value' ); + closed_postboxes_nonce = response + .html() + .find( 'input[id=closedpostboxesnonce]' ) + .first() + .attr( 'value' ); + sample_permalink_nonce = response + .html() + .find( 'input[id=samplepermalinknonce]' ) + .first() + .attr( 'value' ); + woocommerce_meta_nonce = response + .html() + .find( 'input[id=woocommerce_meta_nonce]' ) + .first() + .attr( 'value' ); + meta_box_order_nonce = response + .html() + .find( 'input[id=meta-box-order-nonce]' ) + .first() + .attr( 'value' ); + post_id = response + .html() + .find( 'input[id=post_ID]' ) + .first() + .attr( 'value' ); + hpos_post_id = findBetween( response.body, 'post_id":"', '",' ); + heartbeat_nonce = findBetween( + response.body, + 'heartbeatSettings = {"nonce":"', + '"};' + ); + api_x_wp_nonce = findBetween( + response.body, + 'wp.apiFetch.createNonceMiddleware( "', + '" )' + ); + + // Create request header with nonce value for use in subsequent requests. + apiNonceHeader = { + 'x-wp-nonce': `${ api_x_wp_nonce }`, + }; + } ); + + sleep( randomIntBetween( `${ think_time_min }`, `${ think_time_max }` ) ); + + group( 'All Orders - Other Requests', function () { + const requestHeaders = Object.assign( + {}, + jsonAPIRequestHeader, + commonRequestHeaders, + commonAPIGetRequestHeaders, + apiNonceHeader, + commonNonStandardHeaders + ); + + response = http.get( + `${ base_url }/wp-json/wc-admin/onboarding/tasks?_locale=user`, + { + headers: requestHeaders, + tags: { name: 'Merchant - wc-admin/onboarding/tasks?' }, + } + ); + check( response, { + 'is status 200': ( r ) => r.status === 200, + } ); + + response = http.get( + `${ base_url }/wp-json/wc-analytics/admin/notes?page=1&per_page=25&` + + `type=error%2Cupdate&status=unactioned&_locale=user`, + { + headers: requestHeaders, + tags: { name: 'Merchant - wc-analytics/admin/notes?' }, + } + ); + check( response, { + 'is status 200': ( r ) => r.status === 200, + } ); + + response = http.get( + `${ base_url }/wp-json/wc-admin/options?options=woocommerce_ces_tracks_queue&_locale=user`, + { + headers: requestHeaders, + tags: { + name: 'Merchant - wc-admin/options?options=woocommerce_ces_tracks_queue', + }, + } + ); + check( response, { + 'is status 200': ( r ) => r.status === 200, + } ); + } ); + + group( 'WP Admin Heartbeat', function () { + const requestHeaders = Object.assign( + {}, + jsonRequestHeader, + commonRequestHeaders, + contentTypeRequestHeader, + commonPostRequestHeaders, + commonNonStandardHeaders + ); + + response = http.post( + `${ base_url }/wp-admin/admin-ajax.php`, + `_nonce=${ heartbeat_nonce }&action=heartbeat&has_focus=true&interval=15&screen_id=shop_order`, + { + headers: requestHeaders, + tags: { name: 'Merchant - action=heartbeat' }, + } + ); + check( response, { + 'is status 200': ( r ) => r.status === 200, + } ); + } ); + + sleep( randomIntBetween( `${ think_time_min }`, `${ think_time_max }` ) ); + + group( 'Create New Order', function () { + const requestHeaders = Object.assign( + {}, + htmlRequestHeader, + commonRequestHeaders, + commonGetRequestHeaders, + contentTypeRequestHeader, + commonNonStandardHeaders + ); + + const date = new Date(); + const order_date = date.toJSON().slice( 0, 10 ); + + const orderParams = new URLSearchParams( [ + [ '_ajax_nonce-add-meta', `${ ajax_nonce_add_meta }` ], + [ '_billing_address_1', `${ addresses_guest_billing_address_1 }` ], + [ '_billing_address_2', `${ addresses_guest_billing_address_2 }` ], + [ '_billing_city', `${ addresses_guest_billing_city }` ], + [ '_billing_company', `${ addresses_guest_billing_company }` ], + [ '_billing_country', `${ addresses_guest_billing_country }` ], + [ '_billing_email', `${ addresses_guest_billing_email }` ], + [ + '_billing_first_name', + `${ addresses_guest_billing_first_name }`, + ], + [ '_billing_last_name', `${ addresses_guest_billing_last_name }` ], + [ '_billing_phone', `${ addresses_guest_billing_phone }` ], + [ '_billing_postcode', `${ addresses_guest_billing_postcode }` ], + [ '_billing_state', `${ addresses_guest_billing_state }` ], + [ '_shipping_address_1', `${ addresses_guest_billing_address_1 }` ], + [ '_shipping_address_2', `${ addresses_guest_billing_address_2 }` ], + [ '_shipping_city', `${ addresses_guest_billing_city }` ], + [ '_shipping_company', `${ addresses_guest_billing_company }` ], + [ '_shipping_country', `${ addresses_guest_billing_country }` ], + [ + '_shipping_first_name', + `${ addresses_guest_billing_first_name }`, + ], + [ '_shipping_last_name', `${ addresses_guest_billing_last_name }` ], + [ '_shipping_phone', `${ addresses_guest_billing_phone }` ], + [ '_shipping_postcode', `${ addresses_guest_billing_postcode }` ], + [ '_shipping_state', `${ addresses_guest_billing_state }` ], + [ '_payment_method', `${ payment_method }` ], + [ '_transaction_id', '' ], + [ '_wp_http_referer', '' ], + [ '_wp_original_http_referer', '' ], + [ '_wpnonce', `${ wpnonce }` ], + [ 'action', 'editpost' ], + [ 'auto_draft', '1' ], //no + [ 'closedpostboxesnonce', `${ closed_postboxes_nonce }` ], + [ 'customer_user', '' ], + [ 'excerpt', '' ], + [ 'meta-box-order-nonce', `${ meta_box_order_nonce }` ], + [ 'metakeyinput', '' ], + [ 'metakeyselect', '%23NONE%23' ], + [ 'metavalue', '' ], + [ 'order_date', `${ order_date }` ], + [ 'order_date_hour', '01' ], + [ 'order_date_minute', '01' ], + [ 'order_date_second', '01' ], + [ 'order_note', '' ], + [ 'order_note_type', '' ], + [ 'order_status', 'wc-pending' ], //change + [ 'original_post_status', 'auto-draft' ], //wc-pending + [ 'original_post_title', '' ], //string + [ 'originalaction', 'editpost' ], + [ 'post_ID', `${ post_id }` ], + [ 'post_author', '1' ], + [ 'post_status', 'auto-draft' ], //pending + [ 'post_title', '%2COrder' ], //string + [ 'post_type', 'shop_order' ], + [ 'referredby', '' ], + [ 'samplepermalinknonce', `${ sample_permalink_nonce }` ], + [ 'save', 'Create' ], //Update + [ 'user_ID', '1' ], + [ 'wc_order_action', '' ], + [ 'woocommerce_meta_nonce', `${ woocommerce_meta_nonce }` ], + ] ); + + const cotOrderParams = new URLSearchParams( [ + [ '_ajax_nonce-add-meta', `${ ajax_nonce_add_meta }` ], + [ '_billing_address_1', `${ addresses_guest_billing_address_1 }` ], + [ '_billing_address_2', `${ addresses_guest_billing_address_2 }` ], + [ '_billing_city', `${ addresses_guest_billing_city }` ], + [ '_billing_company', `${ addresses_guest_billing_company }` ], + [ '_billing_country', `${ addresses_guest_billing_country }` ], + [ '_billing_email', `${ addresses_guest_billing_email }` ], + [ + '_billing_first_name', + `${ addresses_guest_billing_first_name }`, + ], + [ '_billing_last_name', `${ addresses_guest_billing_last_name }` ], + [ '_billing_phone', `${ addresses_guest_billing_phone }` ], + [ '_billing_postcode', `${ addresses_guest_billing_postcode }` ], + [ '_billing_state', `${ addresses_guest_billing_state }` ], + [ '_shipping_address_1', `${ addresses_guest_billing_address_1 }` ], + [ '_shipping_address_2', `${ addresses_guest_billing_address_2 }` ], + [ '_shipping_city', `${ addresses_guest_billing_city }` ], + [ '_shipping_company', `${ addresses_guest_billing_company }` ], + [ '_shipping_country', `${ addresses_guest_billing_country }` ], + [ + '_shipping_first_name', + `${ addresses_guest_billing_first_name }`, + ], + [ '_shipping_last_name', `${ addresses_guest_billing_last_name }` ], + [ '_shipping_phone', `${ addresses_guest_billing_phone }` ], + [ '_shipping_postcode', `${ addresses_guest_billing_postcode }` ], + [ '_shipping_state', `${ addresses_guest_billing_state }` ], + [ '_payment_method', `${ payment_method }` ], + [ '_transaction_id', '' ], + [ '_wp_http_referer', '' ], + [ '_wpnonce', `${ wpnonce }` ], + [ 'action', 'edit_order' ], + [ 'customer_user', '' ], + [ 'excerpt', '' ], + [ 'metakeyinput', '' ], + [ 'metavalue', '' ], + [ 'order_date', `${ order_date }` ], + [ 'order_date_hour', '01' ], + [ 'order_date_minute', '01' ], + [ 'order_date_second', '01' ], + [ 'order_note', '' ], + [ 'order_note_type', '' ], + [ 'order_status', 'wc-pending' ], + [ 'original_order_status', 'auto-draft' ], //pending + [ 'post_status', 'auto-draft' ], //pending + [ 'post_title', 'Order' ], + [ 'referredby', '' ], + [ 'save', 'Create' ], //Save + [ 'wc_order_action', '' ], + [ 'woocommerce_meta_nonce', `${ woocommerce_meta_nonce }` ], + ] ); + + if ( cot_status === true ) { + admin_update_order_base = `${ admin_update_order_base }&id=${ hpos_post_id }`; + admin_update_order_params = cotOrderParams.toString(); + } else { + admin_update_order_params = orderParams.toString(); + } + + response = http.post( + `${ base_url }/wp-admin/${ admin_update_order_base }`, + admin_update_order_params.toString(), + { + headers: requestHeaders, + tags: { name: 'Merchant - Create New Order' }, + } + ); + check( response, { + 'is status 200': ( r ) => r.status === 200, + "body contains: 'Edit order' header": ( response ) => + response.body.includes( `${ admin_open_order_assert }` ), + "body contains: 'Order updated' confirmation": ( response ) => + response.body.includes( `${ admin_created_order_assert }` ), + } ); + } ); + + sleep( randomIntBetween( `${ think_time_min }`, `${ think_time_max }` ) ); + + group( 'Open Order', function () { + const requestHeaders = Object.assign( + {}, + htmlRequestHeader, + commonRequestHeaders, + commonGetRequestHeaders, + commonNonStandardHeaders + ); + + if ( cot_status === true ) { + admin_open_order_base = `${ admin_update_order_base }&id=${ hpos_post_id }`; + } else { + admin_open_order_base = `${ admin_update_order_base }?post=${ post_id }`; + } + + response = http.get( + `${ base_url }/wp-admin/${ admin_open_order_base }&action=edit`, + { + headers: requestHeaders, + tags: { name: 'Merchant - Open Order' }, + } + ); + check( response, { + 'is status 200': ( r ) => r.status === 200, + "body contains: 'Edit order' header": ( response ) => + response.body.includes( `${ admin_open_order_assert }` ), + } ); + } ); + + sleep( randomIntBetween( `${ think_time_min }`, `${ think_time_max }` ) ); + + group( 'Update Order', function () { + const requestHeaders = Object.assign( + {}, + htmlRequestHeader, + commonRequestHeaders, + commonGetRequestHeaders, + contentTypeRequestHeader, + commonNonStandardHeaders + ); + + const orderParams = new URLSearchParams( [ + [ '_ajax_nonce-add-meta', `${ ajax_nonce_add_meta }` ], + [ '_billing_address_1', `${ addresses_guest_billing_address_1 }` ], + [ '_billing_address_2', `${ addresses_guest_billing_address_2 }` ], + [ '_billing_city', `${ addresses_guest_billing_city }` ], + [ '_billing_company', `${ addresses_guest_billing_company }` ], + [ '_billing_country', `${ addresses_guest_billing_country }` ], + [ '_billing_email', `${ addresses_guest_billing_email }` ], + [ + '_billing_first_name', + `${ addresses_guest_billing_first_name }`, + ], + [ '_billing_last_name', `${ addresses_guest_billing_last_name }` ], + [ '_billing_phone', `${ addresses_guest_billing_phone }` ], + [ '_billing_postcode', `${ addresses_guest_billing_postcode }` ], + [ '_billing_state', `${ addresses_guest_billing_state }` ], + [ '_shipping_address_1', `${ addresses_guest_billing_address_1 }` ], + [ '_shipping_address_2', `${ addresses_guest_billing_address_2 }` ], + [ '_shipping_city', `${ addresses_guest_billing_city }` ], + [ '_shipping_company', `${ addresses_guest_billing_company }` ], + [ '_shipping_country', `${ addresses_guest_billing_country }` ], + [ + '_shipping_first_name', + `${ addresses_guest_billing_first_name }`, + ], + [ '_shipping_last_name', `${ addresses_guest_billing_last_name }` ], + [ '_shipping_phone', `${ addresses_guest_billing_phone }` ], + [ '_shipping_postcode', `${ addresses_guest_billing_postcode }` ], + [ '_shipping_state', `${ addresses_guest_billing_state }` ], + [ '_payment_method', `${ payment_method }` ], + [ '_transaction_id', '' ], + [ '_wp_http_referer', '' ], + [ '_wp_original_http_referer', '' ], + [ '_wpnonce', `${ wpnonce }` ], + [ 'action', 'editpost' ], + [ 'closedpostboxesnonce', `${ closed_postboxes_nonce }` ], + [ 'customer_user', '' ], + [ 'excerpt', '' ], + [ 'meta-box-order-nonce', `${ meta_box_order_nonce }` ], + [ 'metakeyinput', '' ], + [ 'metakeyselect', '%23NONE%23' ], + [ 'metavalue', '' ], + [ 'order_date', `${ order_date }` ], + [ 'order_date_hour', '01' ], + [ 'order_date_minute', '01' ], + [ 'order_date_second', '01' ], + [ 'order_note', '' ], + [ 'order_note_type', '' ], + [ 'order_status', 'wc-completed' ], + [ 'original_post_status', 'wc-pending' ], + [ 'original_post_title', '' ], //string + [ 'originalaction', 'editpost' ], + [ 'post_ID', `${ post_id }` ], + [ 'post_author', '1' ], + [ 'post_status', 'pending' ], + [ 'post_title', '%2COrder' ], //string + [ 'post_type', 'shop_order' ], + [ 'referredby', '' ], + [ 'samplepermalinknonce', `${ sample_permalink_nonce }` ], + [ 'save', 'Update' ], + [ 'user_ID', '1' ], + [ 'wc_order_action', '' ], + [ 'woocommerce_meta_nonce', `${ woocommerce_meta_nonce }` ], + ] ); + + const cotOrderParams = new URLSearchParams( [ + [ '_ajax_nonce-add-meta', `${ ajax_nonce_add_meta }` ], + [ '_billing_address_1', `${ addresses_guest_billing_address_1 }` ], + [ '_billing_address_2', `${ addresses_guest_billing_address_2 }` ], + [ '_billing_city', `${ addresses_guest_billing_city }` ], + [ '_billing_company', `${ addresses_guest_billing_company }` ], + [ '_billing_country', `${ addresses_guest_billing_country }` ], + [ '_billing_email', `${ addresses_guest_billing_email }` ], + [ + '_billing_first_name', + `${ addresses_guest_billing_first_name }`, + ], + [ '_billing_last_name', `${ addresses_guest_billing_last_name }` ], + [ '_billing_phone', `${ addresses_guest_billing_phone }` ], + [ '_billing_postcode', `${ addresses_guest_billing_postcode }` ], + [ '_billing_state', `${ addresses_guest_billing_state }` ], + [ '_shipping_address_1', `${ addresses_guest_billing_address_1 }` ], + [ '_shipping_address_2', `${ addresses_guest_billing_address_2 }` ], + [ '_shipping_city', `${ addresses_guest_billing_city }` ], + [ '_shipping_company', `${ addresses_guest_billing_company }` ], + [ '_shipping_country', `${ addresses_guest_billing_country }` ], + [ + '_shipping_first_name', + `${ addresses_guest_billing_first_name }`, + ], + [ '_shipping_last_name', `${ addresses_guest_billing_last_name }` ], + [ '_shipping_phone', `${ addresses_guest_billing_phone }` ], + [ '_shipping_postcode', `${ addresses_guest_billing_postcode }` ], + [ '_shipping_state', `${ addresses_guest_billing_state }` ], + [ '_payment_method', `${ payment_method }` ], + [ '_transaction_id', '' ], + [ '_wp_http_referer', '' ], + [ '_wpnonce', `${ wpnonce }` ], + [ 'action', 'edit_order' ], + [ 'customer_user', '' ], + [ 'excerpt', '' ], + [ 'metakeyinput', '' ], + [ 'metavalue', '' ], + [ 'order_date', `${ order_date }` ], + [ 'order_date_hour', '01' ], + [ 'order_date_minute', '01' ], + [ 'order_date_second', '01' ], + [ 'order_note', '' ], + [ 'order_note_type', '' ], + [ 'order_status', 'wc-completed' ], + [ 'original_order_status', 'pending' ], + [ 'post_status', 'pending' ], + [ 'post_title', 'Order' ], + [ 'referredby', '' ], + [ 'save', 'Save' ], + [ 'wc_order_action', '' ], + [ 'woocommerce_meta_nonce', `${ woocommerce_meta_nonce }` ], + ] ); + + if ( cot_status === true ) { + admin_update_order_id = `${ admin_update_order_base }&id=${ hpos_post_id }`; + admin_update_order_params = cotOrderParams.toString(); + } else { + admin_update_order_params = orderParams.toString(); + admin_update_order_id = `${ admin_open_order_base }`; + } + + response = http.post( + `${ base_url }/wp-admin/${ admin_update_order_id }`, + admin_update_order_params.toString(), + { + headers: requestHeaders, + tags: { name: 'Merchant - Update Existing Order Status' }, + } + ); + check( response, { + 'is status 200': ( r ) => r.status === 200, + "body contains: 'Edit order' header": ( response ) => + response.body.includes( `${ admin_open_order_assert }` ), + "body contains: 'Order updated' confirmation": ( response ) => + response.body.includes( `${ admin_update_order_assert }` ), + } ); + } ); +} + +export default function () { + addOrder(); +} diff --git a/plugins/woocommerce/tests/performance/requests/merchant/my-account-merchant.js b/plugins/woocommerce/tests/performance/requests/merchant/my-account-merchant.js index f6cb2d2174c..970905f27bf 100644 --- a/plugins/woocommerce/tests/performance/requests/merchant/my-account-merchant.js +++ b/plugins/woocommerce/tests/performance/requests/merchant/my-account-merchant.js @@ -46,9 +46,7 @@ export function myAccountMerchantLogin() { check( response, { 'is status 200': ( r ) => r.status === 200, "body contains: 'My account' title": ( response ) => - response.body.includes( - '

My account

' - ), + response.body.includes( '>My account' ), } ); // Correlate nonce value for use in subsequent requests. diff --git a/plugins/woocommerce/tests/performance/requests/merchant/orders-filter.js b/plugins/woocommerce/tests/performance/requests/merchant/orders-filter.js new file mode 100644 index 00000000000..c381e906c99 --- /dev/null +++ b/plugins/woocommerce/tests/performance/requests/merchant/orders-filter.js @@ -0,0 +1,93 @@ +/* eslint-disable import/no-unresolved */ +/* eslint-disable no-shadow */ +/** + * External dependencies + */ +import { sleep, check, group } from 'k6'; +import http from 'k6/http'; +import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.1.0/index.js'; + +/** + * Internal dependencies + */ +import { + base_url, + cot_status, + admin_orders_base_url, + cot_admin_orders_base_url, + think_time_min, + think_time_max, + customer_user_id, +} from '../../config.js'; +import { + htmlRequestHeader, + commonRequestHeaders, + commonGetRequestHeaders, + commonNonStandardHeaders, +} from '../../headers.js'; + +const date = new Date(); +const month = date.toJSON().slice( 5, 7 ); +const year = date.toJSON().slice( 0, 4 ); +const currentDate = `${ year }${ month }`; + +// Change URL if COT is enabled and being used +let admin_orders_base; +let admin_filter_month_assert; +if ( cot_status === true ) { + admin_orders_base = cot_admin_orders_base_url; + admin_filter_month_assert = `selected='selected' value="${ currentDate }">`; +} else { + admin_orders_base = `${ admin_orders_base_url }&post_status=all`; + admin_filter_month_assert = `selected='selected' value='${ currentDate }'>`; +} + +export function ordersFilter() { + let response; + + group( 'Orders Filter', function () { + const requestHeaders = Object.assign( + {}, + htmlRequestHeader, + commonRequestHeaders, + commonGetRequestHeaders, + commonNonStandardHeaders + ); + + response = http.get( + `${ base_url }/wp-admin/${ admin_orders_base }` + + `&s&action=-1&m=${ currentDate }&_customer_user&filter_action=Filter&paged=1&action2=-1`, + { + headers: requestHeaders, + tags: { name: 'Merchant - Filter Orders By Month' }, + } + ); + check( response, { + 'is status 200': ( r ) => r.status === 200, + 'body contains: filter set to selected month': ( response ) => + response.body.includes( `${ admin_filter_month_assert }` ), + } ); + + response = http.get( + `${ base_url }/wp-admin/${ admin_orders_base }` + + `&s&action=-1&m=0&_customer_user=${ customer_user_id }&filter_action=Filter&paged=1&action2=-1`, + { + headers: requestHeaders, + tags: { name: 'Merchant - Filter Orders By Customer' }, + } + ); + check( response, { + 'is status 200': ( r ) => r.status === 200, + 'body contains: filter set to selected customer': ( response ) => + response.body.includes( + `