diff --git a/plugins/woocommerce/changelog/performance-merchant-view-coupons b/plugins/woocommerce/changelog/performance-merchant-view-coupons new file mode 100644 index 00000000000..d115ac6f252 --- /dev/null +++ b/plugins/woocommerce/changelog/performance-merchant-view-coupons @@ -0,0 +1,5 @@ +Significance: patch +Type: dev +Comment: No entry needed because this change only added a new performance test. + + diff --git a/plugins/woocommerce/tests/performance/requests/merchant/coupons.js b/plugins/woocommerce/tests/performance/requests/merchant/coupons.js new file mode 100644 index 00000000000..6ed3f0213c7 --- /dev/null +++ b/plugins/woocommerce/tests/performance/requests/merchant/coupons.js @@ -0,0 +1,153 @@ +import { sleep, check, group } from "k6"; +import http from "k6/http"; +import { Trend } from "k6/metrics"; +import { randomIntBetween } from "https://jslib.k6.io/k6-utils/1.1.0/index.js"; +import { findBetween } from "https://jslib.k6.io/k6-utils/1.1.0/index.js"; +import { base_url, think_time_min, think_time_max } from "../../config.js"; +import { + htmlRequestHeader, + jsonAPIRequestHeader, + jsonRequestHeader, + commonRequestHeaders, + commonGetRequestHeaders, + contentTypeRequestHeader, + commonPostRequestHeaders, + commonAPIGetRequestHeaders, + commonNonStandardHeaders, +} from "../../headers.js"; + +// Custom metrics to add to standard results output. +let postTypeCouponTrend = new Trend("wc_get_post_type_coupon"); +let wcAdminNotesMainTrend = new Trend("wc_get_admin_notes_main"); +let wcAdminNotesOtherTrend = new Trend("wc_get_admin_notes_other"); +let wcAdminCESOptionsTrend = new Trend("wc_get_admin_options_ces"); +let wpAdminHeartbeatTrend = new Trend("wc_post_wp_admin_heartbeat"); + +export function coupons() { + let response; + let api_x_wp_nonce; + let apiNonceHeader; + let heartbeat_nonce; + + group("Coupons Page", function () { + var requestHeaders = Object.assign({}, + htmlRequestHeader, + commonRequestHeaders, + commonGetRequestHeaders, + commonNonStandardHeaders + ); + + response = http.get(`${base_url}/wp-admin/edit.php?post_type=shop_coupon`, { + headers: requestHeaders, + }); + postTypeCouponTrend.add(response.timings.duration); + check(response, { + "is status 200": (r) => r.status === 200, + "body contains: 'Coupons' header": (response) => + response.body.includes("Coupons"), + }); + + // Correlate nonce values for use in subsequent requests. + 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("Inbox Notes", function () { + var requestHeaders = Object.assign({}, + jsonAPIRequestHeader, + commonRequestHeaders, + commonAPIGetRequestHeaders, + apiNonceHeader, + commonNonStandardHeaders + ); + + response = http.get( + `${base_url}/wp-json/wc-analytics/admin/notes?page=1&per_page=25&` + + `status=unactioned&type%5B0%5D=info&type%5B1%5D=marketing&type%5B2%5D=survey&type%5B3%5D=warning&` + + `orderby=date&order=desc&_locale=user`, + { + headers: requestHeaders, + } + ); + wcAdminNotesMainTrend.add(response.timings.duration); + 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, + } + ); + wcAdminNotesOtherTrend.add(response.timings.duration); + check(response, { + "is status 200": (r) => r.status === 200, + }); + }); + + group("CES Options", function () { + var requestHeaders = Object.assign({}, + jsonAPIRequestHeader, + commonRequestHeaders, + commonAPIGetRequestHeaders, + apiNonceHeader, + commonNonStandardHeaders + ); + + response = http.get( + `${base_url}/wp-json/wc-admin/options?options=woocommerce_ces_tracks_queue&_locale=user`, + { + headers: requestHeaders, + } + ); + wcAdminCESOptionsTrend.add(response.timings.duration); + check(response, { + "is status 200": (r) => r.status === 200, + }); + }); + + group("WP Admin Heartbeat", function () { + var 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_coupon`, + { + headers: requestHeaders, + } + ); + wpAdminHeartbeatTrend.add(response.timings.duration); + check(response, { + "is status 200": (r) => r.status === 200, + }); + }); + + sleep(randomIntBetween(`${think_time_min}`, `${think_time_max}`)); +} + +export default function () { + coupons(); +} diff --git a/plugins/woocommerce/tests/performance/tests/example-all-requests-arrival-rate.js b/plugins/woocommerce/tests/performance/tests/example-all-requests-arrival-rate.js index 9c86c11a363..cbac3ffa5f1 100644 --- a/plugins/woocommerce/tests/performance/tests/example-all-requests-arrival-rate.js +++ b/plugins/woocommerce/tests/performance/tests/example-all-requests-arrival-rate.js @@ -7,6 +7,7 @@ import { cartRemoveItem } from '../requests/shopper/cart-remove-item.js'; import { cartApplyCoupon } from '../requests/shopper/cart-apply-coupon.js'; import { checkoutGuest } from '../requests/shopper/checkout-guest.js'; import { checkoutCustomerLogin } from '../requests/shopper/checkout-customer-login.js'; +import { coupons } from '../requests/merchant/coupons.js'; import { myAccount } from '../requests/shopper/my-account.js'; import { wpLogin } from '../requests/merchant/wp-login.js'; import { products } from '../requests/merchant/products.js'; @@ -111,6 +112,7 @@ export function merchantAllFlows() { ordersSearch(); products(); addProduct(); + coupons(); } // Use myAccountMerchantLogin() instead of wpLogin() if having issues with login. export function merchantHeartbeatFlow() { diff --git a/plugins/woocommerce/tests/performance/tests/example-all-requests-ramping-vus.js b/plugins/woocommerce/tests/performance/tests/example-all-requests-ramping-vus.js index 5af05dbbde6..82e62294b0a 100644 --- a/plugins/woocommerce/tests/performance/tests/example-all-requests-ramping-vus.js +++ b/plugins/woocommerce/tests/performance/tests/example-all-requests-ramping-vus.js @@ -7,6 +7,7 @@ import { cartRemoveItem } from '../requests/shopper/cart-remove-item.js'; import { cartApplyCoupon } from '../requests/shopper/cart-apply-coupon.js'; import { checkoutGuest } from '../requests/shopper/checkout-guest.js'; import { checkoutCustomerLogin } from '../requests/shopper/checkout-customer-login.js'; +import { coupons } from '../requests/merchant/coupons.js'; import { myAccount } from '../requests/shopper/my-account.js'; import { wpLogin } from '../requests/merchant/wp-login.js'; import { products } from '../requests/merchant/products.js'; @@ -101,6 +102,7 @@ export function merchantAllFlows() { ordersSearch(); products(); addProduct(); + coupons(); } // Use myAccountMerchantLogin() instead of wpLogin() if having issues with login. export function merchantHeartbeatFlow() { 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 108f2330143..bd255a0e4cf 100644 --- a/plugins/woocommerce/tests/performance/tests/gh-action-pr-requests.js +++ b/plugins/woocommerce/tests/performance/tests/gh-action-pr-requests.js @@ -6,6 +6,7 @@ import { cart } from '../requests/shopper/cart.js'; import { cartRemoveItem } from '../requests/shopper/cart-remove-item.js'; import { checkoutGuest } from '../requests/shopper/checkout-guest.js'; import { checkoutCustomerLogin } from '../requests/shopper/checkout-customer-login.js'; +import { coupons } from '../requests/merchant/coupons.js'; import { myAccount } from '../requests/shopper/my-account.js'; import { categoryPage } from '../requests/shopper/category-page.js'; import { wpLogin } from '../requests/merchant/wp-login.js'; @@ -127,4 +128,5 @@ export function allMerchantFlow() { ordersSearch(); products(); addProduct(); + coupons(); } diff --git a/plugins/woocommerce/tests/performance/tests/simple-all-merchant-requests.js b/plugins/woocommerce/tests/performance/tests/simple-all-merchant-requests.js index 473387ab0fe..ee230fae733 100644 --- a/plugins/woocommerce/tests/performance/tests/simple-all-merchant-requests.js +++ b/plugins/woocommerce/tests/performance/tests/simple-all-merchant-requests.js @@ -1,6 +1,7 @@ import { wpLogin } from '../requests/merchant/wp-login.js'; import { products } from '../requests/merchant/products.js'; import { addProduct } from '../requests/merchant/add-product.js'; +import { coupons } from '../requests/merchant/coupons.js'; import { orders } from '../requests/merchant/orders.js'; import { ordersSearch } from '../requests/merchant/orders-search.js'; import { homeWCAdmin } from '../requests/merchant/home-wc-admin.js'; @@ -26,4 +27,5 @@ export function allMerchantFlow() { ordersSearch(); products(); addProduct(); + coupons(); }