Create order during setup
This commit is contained in:
parent
77a17e48b7
commit
8f64573f42
|
@ -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 #<mark class="order-number">${ my_account_order_id }</mark> was placed`,
|
||||
footer: FOOTER_TEXT,
|
||||
} );
|
||||
} );
|
||||
|
|
|
@ -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 }` );
|
||||
}
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue