Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CC-34875: Phase 2 of Performance test infrastructure. SAPI Tests #40

Open
wants to merge 11 commits into
base: feature/cc-34875/dev-performance-phase-2
Choose a base branch
from
37 changes: 36 additions & 1 deletion dashboards/k6-load-testing-results.json
Original file line number Diff line number Diff line change
Expand Up @@ -1659,9 +1659,44 @@
"selected": false,
"text": "M8_get_mp_dashboard",
"value": "M8_get_mp_dashboard"
},
{
"selected": false,
"text": "SAPI2_get_catalog_search",
"value": "SAPI2_get_catalog_search"
},
{
"selected": false,
"text": "SAPI3_get_concrete_products",
"value": "SAPI3_get_concrete_products"
},
{
"selected": false,
"text": "SAPI4_get_carts",
"value": "SAPI4_get_carts"
},
{
"selected": false,
"text": "SAPI5_get_carts_include_items",
"value": "SAPI5_get_carts_include_items"
},
{
"selected": false,
"text": "SAPI6_get_carts_items",
"value": "SAPI6_get_carts_items"
},
{
"selected": false,
"text": "SAPI13_get_abstract_products_all_includes",
"value": "SAPI13_get_abstract_products_all_includes"
},
{
"selected": false,
"text": "SAPI32_get_carts_single_seventy_items",
"value": "SAPI32_get_carts_single_seventy_items"
}
],
"query": "http_req_duration,http_req_blocked,http_req_connecting,http_req_looking_up,http_req_receiving,http_req_sending,http_req_waiting,SAPI7_post_checkout,SAPI9_post_checkout,SAPI15_post_cart_reorder,SAPI19_post_cart_reorder,SAPI16_post_cart_reorder,SAPI17_delete_carts,SAPI18_post_checkout,SAPI20_post_cart_reorder,SAPI21_delete_carts,SAPI22_post_checkout,S2_get_search,M8_get_mp_dashboard",
"query": "http_req_duration,http_req_blocked,http_req_connecting,http_req_looking_up,http_req_receiving,http_req_sending,http_req_waiting,SAPI7_post_checkout,SAPI9_post_checkout,SAPI15_post_cart_reorder,SAPI19_post_cart_reorder,SAPI16_post_cart_reorder,SAPI17_delete_carts,SAPI18_post_checkout,SAPI20_post_cart_reorder,SAPI21_delete_carts,SAPI22_post_checkout,S2_get_search,M8_get_mp_dashboard,SAPI2_get_catalog_search,SAPI3_get_concrete_products,SAPI4_get_carts,SAPI5_get_carts_include_items,SAPI6_get_carts_items,SAPI13_get_abstract_products_all_includes,SAPI32_get_carts_single_seventy_items",
"type": "custom"
}
]
Expand Down
343 changes: 343 additions & 0 deletions src/fixtures/cart.fixture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,343 @@
import { AbstractFixture } from './abstract.fixture';
import exec from 'k6/execution';
import EnvironmentUtil from '../utils/environment.util';

const LOCALE_ID = 66;
const LOCALE_NAME = 'en_US';
const DEFAULT_IMAGE_SMALL = 'https://images.icecat.biz/img/gallery_mediums/30691822_1486.jpg';
const DEFAULT_IMAGE_LARGE = 'https://images.icecat.biz/img/gallery/30691822_1486.jpg';
const DEFAULT_PASSWORD = 'change123';
const DEFAULT_STOCK_ID = 1;
const DEFAULT_STOCK_NAME = 'Warehouse1';
const DEFAULT_MERCHANT_REFERENCE = 'MER000008';

export class CartFixture extends AbstractFixture {
constructor({ customerCount, cartCount = 1, itemCount = 1, emptyCartCount = 0 }) {
super();
this.customerCount = customerCount;
this.cartCount = cartCount;
this.itemCount = itemCount;
this.emptyCartCount = emptyCartCount;
this.repositoryId = EnvironmentUtil.getRepositoryId();
}

getData(customerCount = this.customerCount, cartCount = this.cartCount) {
this.customerCount = customerCount;
this.cartCount = cartCount;

const response = this.runDynamicFixture(this._getCustomersWithQuotesPayload());

const responseData = JSON.parse(response.body).data;
const customers = responseData.filter((item) => /^customer\d+$/.test(item.attributes.key));

return customers.map((customer) => {
const carts = responseData
.filter((item) => item.attributes.key.startsWith(`${customer.attributes.key}Quote`))
.map((cart) => cart.attributes.data.uuid);

const emptyCarts = responseData
.filter((item) => item.attributes.key.startsWith(`${customer.attributes.key}EmptyQuote`))
.map((cart) => cart.attributes.data.uuid);

const product = responseData
.filter((item) => item.attributes.key.startsWith('productKey'))
.map((product) => product.attributes.data.sku);

return {
customerEmail: customer.attributes.data.email,
cartIds: carts,
emptyCartIds: emptyCarts,
productSkus: product,
};
});
}

static iterateData(data, vus = exec.vu.idInTest, iterations = exec.vu.iterationInScenario) {
const customerIndex = (vus - 1) % data.length;
const { customerEmail, cartIds, emptyCartIds, productSkus } = data[customerIndex];
const cartIndex = iterations % cartIds.length;
const emptyCartIndex = iterations % emptyCartIds.length;
const product = productSkus[0];

return {
customerEmail,
idCart: cartIds[cartIndex],
idEmptyCart: emptyCartIds[emptyCartIndex],
productSku: product,
};
}

_getCustomersWithQuotesPayload() {
let companyPermissions = [];
let baseOperations = [
{
type: 'transfer',
name: 'LocaleTransfer',
key: 'locale',
arguments: { id_locale: LOCALE_ID, locale_name: LOCALE_NAME },
},
{
type: 'transfer',
name: 'StoreTransfer',
key: 'store',
arguments: { id_store: 1, name: 'DE' },
},
{
type: 'array-object',
key: 'stores',
arguments: ['#store'],
},
{
type: 'transfer',
name: 'ProductImageTransfer',
key: 'productImage',
arguments: {
externalUrlSmall: DEFAULT_IMAGE_SMALL,
externalUrlLarge: DEFAULT_IMAGE_LARGE,
},
},
];

if (this.repositoryId === 'b2b-mp' || this.repositoryId === 'b2b') {
companyPermissions = [
{
type: 'helper',
name: 'haveCompany',
key: 'company',
arguments: [{ isActive: true, status: 'approved' }],
},
{
type: 'helper',
name: 'haveCompanyBusinessUnit',
key: 'businessUnit',
arguments: [{ fkCompany: '#company.id_company' }],
},
{
type: 'helper',
name: 'havePermissionByKey',
key: 'permission1',
arguments: ['AddCartItemPermissionPlugin'],
},
{
type: 'helper',
name: 'havePermissionByKey',
key: 'permission2',
arguments: ['ChangeCartItemPermissionPlugin'],
},
{
type: 'helper',
name: 'havePermissionByKey',
key: 'permission3',
arguments: ['RemoveCartItemPermissionPlugin'],
},
{
type: 'helper',
name: 'havePermissionByKey',
key: 'permission4',
arguments: ['PlaceOrderWithAmountUpToPermissionPlugin'],
},
{
type: 'helper',
name: 'havePermissionByKey',
key: 'permission5',
arguments: ['PlaceOrderPermissionPlugin'],
},
{
type: 'helper',
name: 'havePermissionByKey',
key: 'permission6',
arguments: ['SeeBusinessUnitOrdersPermissionPlugin'],
},
{
type: 'helper',
name: 'haveCompanyRoleWithPermissions',
arguments: [
{ isDefault: true, fkCompany: '#company.id_company' },
['#permission1', '#permission2', '#permission3', '#permission4', '#permission5', '#permission6'],
],
},
];
}

baseOperations.push(...companyPermissions);
const products = Array.from({ length: this.itemCount }, (_, i) => this._createProductPayload(i)).flat();
const customers = Array.from({ length: this.customerCount }, (_, i) => this._createCustomerPayload(i)).flat();

return JSON.stringify({
data: {
type: 'dynamic-fixtures',
attributes: {
synchronize: true,
operations: [...baseOperations, ...products, ...customers],
},
},
});
}

_createProductPayload(index) {
const productKey = `productKey${index + 1}`;
let productOffer = [];
let product = [
{
type: 'helper',
name: 'haveFullProduct',
key: productKey,
arguments: [{}, { idTaxSet: 1 }],
},
{
type: 'helper',
name: 'haveProductImageSet',
arguments: [
{
name: 'default',
idProduct: `#${productKey}.id_product_concrete`,
idProductAbstract: `#${productKey}.fk_product_abstract`,
productImages: ['#productImage'],
},
],
},
{
type: 'helper',
name: 'havePriceProduct',
arguments: [
{
skuProductAbstract: `#${productKey}.abstract_sku`,
skuProduct: `#${productKey}.sku`,
moneyValue: { netAmount: this.defaultItemPrice, grossAmount: this.defaultItemPrice },
},
],
},
{
type: 'helper',
name: 'haveProductInStock',
arguments: [
{
sku: `#${productKey}.sku`,
isNeverOutOfStock: '1',
fkStock: DEFAULT_STOCK_ID,
stockType: DEFAULT_STOCK_NAME,
},
],
},
];

if (this.repositoryId === 'b2b-mp') {
const productOfferKey = `productOffer${index + 1}`;
productOffer = [
{
type: 'helper',
name: 'haveProductOffer',
key: productOfferKey,
arguments: [
{
isActive: true,
status: 'approved',
idProductConcrete: `#${productKey}.id_product_concrete`,
concreteSku: `#${productKey}.sku`,
merchantReference: DEFAULT_MERCHANT_REFERENCE,
stores: '#stores',
},
],
},
{
type: 'helper',
name: 'haveProductOfferStock',
arguments: [
{
idProductOffer: `#${productOfferKey}.id_product_offer`,
productOfferReference: `#${productOfferKey}.product_offer_reference`,
isNeverOutOfStock: true,
},
[{ idStock: DEFAULT_STOCK_ID }],
],
},
];
}

product.push(...productOffer);

return product;
}

_createCustomerPayload(index) {
const customerKey = `customer${index + 1}`;
let emptyQuotes = [];
let companyUser = [];
let quotes = Array.from({ length: this.cartCount }, (_, quoteIndex) => ({
type: 'helper',
name: 'havePersistentQuote',
key: `${customerKey}Quote${quoteIndex + 1}`,
arguments: [
{
customer: `#${customerKey}`,
items: this._generateItems(),
},
],
}));

if (this.emptyCartCount) {
emptyQuotes = Array.from({ length: this.emptyCartCount }, (_, emptyQuoteIndex) => ({
type: 'helper',
name: 'havePersistentQuote',
key: `${customerKey}EmptyQuote${emptyQuoteIndex + 1}`,
arguments: [
{
customer: `#${customerKey}`,
items: [],
},
],
}));
}

quotes.push(...emptyQuotes);

const customer = [
{
type: 'helper',
name: 'haveCustomer',
key: customerKey,
arguments: [{ locale: '#locale', password: DEFAULT_PASSWORD }],
},
{
type: 'helper',
name: 'confirmCustomer',
key: `confirmed${customerKey}`,
arguments: [`#${customerKey}`],
},
];

if (this.repositoryId === 'b2b-mp' || this.repositoryId === 'b2b') {
companyUser = [
{
type: 'helper',
name: 'haveCompanyUser',
key: `companyUser${customerKey}`,
arguments: [
{
customer: `#${customerKey}`,
fkCustomer: `#${customerKey}.id_customer`,
fkCompany: '#company.id_company',
fkCompanyBusinessUnit: '#businessUnit.id_company_business_unit',
},
],
},
];
}

customer.push(...companyUser);
customer.push(...(quotes || []));

return customer;
}

_generateItems() {
return Array.from({ length: this.itemCount }, (_, i) => ({
sku: `#productKey${i + 1}.sku`,
abstractSku: `#productKey${i + 1}.abstract_sku`,
quantity: 1,
unitPrice: this.defaultItemPrice,
productOfferReference: this.repositoryId === 'b2b-mp' ? `#productOffer${i + 1}.product_offer_reference` : null,
merchantReference: this.repositoryId === 'b2b-mp' ? `#productOffer${i + 1}.merchant_reference` : null,
}));
}
}
Loading