From 8f64573f42af5958eb94caea66e8f97b2a3cbbd6 Mon Sep 17 00:00:00 2001 From: Adrian Moldovan <3854374+adimoldovan@users.noreply.github.com> Date: Mon, 16 Sep 2024 16:18:01 +0300 Subject: [PATCH] Create order during setup --- .../requests/shopper/my-account-orders.js | 15 +++- .../performance/setup/test-data-setup.js | 79 +++++++++++++++++++ .../tests/gh-action-pr-requests.js | 2 + 3 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 plugins/woocommerce/tests/performance/setup/test-data-setup.js 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..7d20bebfe79 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, @@ -77,11 +77,18 @@ export function myAccountOrders() { 'my-account/view-order/', '/"' ); + + check( my_account_order_id, { + 'order ID is not undefined': () => { + console.log( `order id: ${ my_account_order_id }` ); + return !! my_account_order_id; + }, + } ); } ); sleep( randomIntBetween( `${ think_time_min }`, `${ think_time_max }` ) ); - group( 'My Account Open Order', function () { + group( `My Account Open Order ${ my_account_order_id }`, function () { const requestHeaders = Object.assign( {}, htmlRequestHeader, @@ -99,8 +106,8 @@ export function myAccountOrders() { ); 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/setup/test-data-setup.js b/plugins/woocommerce/tests/performance/setup/test-data-setup.js new file mode 100644 index 00000000000..f680ff4ee1e --- /dev/null +++ b/plugins/woocommerce/tests/performance/setup/test-data-setup.js @@ -0,0 +1,79 @@ +/** + * External dependencies + */ +import encoding from 'k6/encoding'; +import http from 'k6/http'; +import { check } 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_customer_billing_first_name, + addresses_customer_billing_last_name, + addresses_customer_billing_country, + addresses_customer_billing_address_1, + addresses_customer_billing_address_2, + addresses_customer_billing_city, + addresses_customer_billing_state, + addresses_customer_billing_postcode, + addresses_customer_billing_phone, + addresses_customer_billing_email, +} from '../config.js'; + +export function createCustomerTestOrder() { + 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_customer_billing_first_name }`, + last_name: `${ addresses_customer_billing_last_name }`, + address_1: `${ addresses_customer_billing_address_1 }`, + address_2: `${ addresses_customer_billing_address_2 }`, + city: `${ addresses_customer_billing_city }`, + state: `${ addresses_customer_billing_state }`, + postcode: `${ addresses_customer_billing_postcode }`, + country: `${ addresses_customer_billing_country }`, + email: `${ addresses_customer_billing_email }`, + phone: `${ addresses_customer_billing_phone }`, + }, + shipping: { + first_name: `${ addresses_customer_billing_first_name }`, + last_name: `${ addresses_customer_billing_last_name }`, + address_1: `${ addresses_customer_billing_address_1 }`, + address_2: `${ addresses_customer_billing_address_2 }`, + city: `${ addresses_customer_billing_city }`, + state: `${ addresses_customer_billing_state }`, + postcode: `${ addresses_customer_billing_postcode }`, + country: `${ addresses_customer_billing_country }`, + }, + customer_id: 2, + }; + const 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": ( r ) => + r.body.includes( '"status":"pending"' ), + } ); + + const orderId = findBetween( response.body, '{"id":', ',' ); + + console.log( `Test order created: ${ orderId }` ); +} 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..3f8c3048f23 100644 --- a/plugins/woocommerce/tests/performance/tests/gh-action-pr-requests.js +++ b/plugins/woocommerce/tests/performance/tests/gh-action-pr-requests.js @@ -23,6 +23,7 @@ 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 { createCustomerTestOrder } from '../setup/test-data-setup.js'; const shopper_request_threshold = 'p(95)<10000'; const merchant_request_threshold = 'p(95)<10000'; @@ -251,6 +252,7 @@ export const options = { export function setup() { useCartCheckoutShortcodes(); + createCustomerTestOrder(); } export function shopperBrowseFlow() {