Skip to content

Commit

Permalink
Merged master.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmiseev committed Jan 23, 2025
1 parent 79cf1f5 commit fd3bdfa
Show file tree
Hide file tree
Showing 15 changed files with 539 additions and 543 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,44 @@ import { AbstractScenario } from '../../../../abstract-scenario.js';
import { group } from 'k6';

export class SharedCartReorderScenario extends AbstractScenario {
execute(customerEmail, orderId, thresholdTag = null) {
let self = this;
group('Cart Reorder', function () {
self.haveReorder(customerEmail, orderId, thresholdTag);
});
}
execute(customerEmail, orderId, thresholdTag = null) {
let self = this;
group('Cart Reorder', function () {
self.haveReorder(customerEmail, orderId, thresholdTag);
});
}

haveReorder(customerEmail, orderId, thresholdTag = null) {
const requestParams = this.cartHelper.getParamsWithAuthorization(customerEmail);
if (thresholdTag) {
requestParams.tags = { name: thresholdTag };
}
haveReorder(customerEmail, orderId, thresholdTag = null) {
const requestParams = this.cartHelper.getParamsWithAuthorization(customerEmail);
if (thresholdTag) {
requestParams.tags = { name: thresholdTag };
}

const cartReorderResponse = this.http.sendPostRequest(
this.http.url`${this.getStorefrontApiBaseUrl()}/cart-reorder`,
JSON.stringify(this._getCartReorderAttributes(orderId)),
requestParams,
false
);
const cartReorderResponse = this.http.sendPostRequest(
this.http.url`${this.getStorefrontApiBaseUrl()}/cart-reorder`,
JSON.stringify(this._getCartReorderAttributes(orderId)),
requestParams,
false
);

this.assertionsHelper.assertResponseStatus(cartReorderResponse, 201);
this.assertionsHelper.assertResponseStatus(cartReorderResponse, 201);

try {
return JSON.parse(cartReorderResponse.body);
} catch (e) {
console.log(cartReorderResponse.body);
throw Error('Failed to parse response during SharedCartReorderScenario::haveReorder()');
}
try {
return JSON.parse(cartReorderResponse.body);
} catch (e) {
console.log(cartReorderResponse.body);
throw Error('Failed to parse response during SharedCartReorderScenario::haveReorder()');
}
}

_getCartReorderAttributes(orderId) {
return {
data: {
type: 'cart-reorder',
attributes: {
orderReference: orderId
}
}
}
}
_getCartReorderAttributes(orderId) {
return {
data: {
type: 'cart-reorder',
attributes: {
orderReference: orderId,
},
},
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,92 +2,96 @@ import { AbstractScenario } from '../../../../abstract-scenario.js';
import { group } from 'k6';

export class SharedCheckoutScenario extends AbstractScenario {
execute(numberOfItems, isMpPaymentProvider = true) {
let self = this;
execute(numberOfItems, isMpPaymentProvider = true) {
let self = this;

group('Checkout', function () {
const requestParams = self.cartHelper.getParamsWithAuthorization();
const cartId = self.cartHelper.haveCartWithProducts(numberOfItems, '100429');
group('Checkout', function () {
const requestParams = self.cartHelper.getParamsWithAuthorization();
const cartId = self.cartHelper.haveCartWithProducts(numberOfItems, '100429');

const checkoutResponse = self.http.sendPostRequest(
self.http.url`${self.getStorefrontApiBaseUrl()}/checkout?include=orders`,
JSON.stringify(self._getCheckoutData(cartId, isMpPaymentProvider)),
requestParams,
false
);
const checkoutResponse = self.http.sendPostRequest(
self.http.url`${self.getStorefrontApiBaseUrl()}/checkout?include=orders`,
JSON.stringify(self._getCheckoutData(cartId, isMpPaymentProvider)),
requestParams,
false
);

self.assertionsHelper.assertResponseStatus(checkoutResponse, 201);
});
}
self.assertionsHelper.assertResponseStatus(checkoutResponse, 201);
});
}

haveOrder(customerEmail, cartId, isMpPaymentProvider = true, thresholdTag = null) {
const requestParams = this.cartHelper.getParamsWithAuthorization(customerEmail);
if (thresholdTag) {
requestParams.tags = { name: thresholdTag };
}
haveOrder(customerEmail, cartId, isMpPaymentProvider = true, thresholdTag = null) {
const requestParams = this.cartHelper.getParamsWithAuthorization(customerEmail);
if (thresholdTag) {
requestParams.tags = { name: thresholdTag };
}

const checkoutResponse = this.http.sendPostRequest(
this.http.url`${this.getStorefrontApiBaseUrl()}/checkout`,
JSON.stringify(this._getCheckoutData(cartId, customerEmail, isMpPaymentProvider)),
requestParams,
false
);
const checkoutResponse = this.http.sendPostRequest(
this.http.url`${this.getStorefrontApiBaseUrl()}/checkout`,
JSON.stringify(this._getCheckoutData(cartId, customerEmail, isMpPaymentProvider)),
requestParams,
false
);

this.assertionsHelper.assertResponseStatus(checkoutResponse, 201);
this.assertionsHelper.assertResponseStatus(checkoutResponse, 201);

try {
return JSON.parse(checkoutResponse.body);
} catch (e) {
throw Error('Failed to parse response during SharedCheckoutScenario::placeOrder()');
}
try {
return JSON.parse(checkoutResponse.body);
} catch (e) {
throw Error('Failed to parse response during SharedCheckoutScenario::placeOrder()');
}
}

_getCheckoutData(
cartId,
defaultCustomerEmail = this.customerHelper.getDefaultCustomerEmail(),
isMpPaymentProvider = true
) {
const address = {
salutation: 'Ms',
email: defaultCustomerEmail,
firstName: 'sonia',
lastName: 'wagner',
address1: 'West road',
address2: '212',
address3: '',
zipCode: '61000',
city: 'Berlin',
iso2Code: 'DE',
company: 'Spryker',
phone: '+380669455897',
isDefaultShipping: true,
isDefaultBilling: true,
};

_getCheckoutData(cartId, defaultCustomerEmail = this.customerHelper.getDefaultCustomerEmail(), isMpPaymentProvider = true) {
const address = {
return {
data: {
type: 'checkout',
attributes: {
customer: {
salutation: 'Ms',
email: defaultCustomerEmail,
firstName: 'sonia',
lastName: 'wagner',
address1: 'West road',
address2: '212',
address3: '',
zipCode: '61000',
city: 'Berlin',
iso2Code: 'DE',
company: 'Spryker',
phone: '+380669455897',
isDefaultShipping: true,
isDefaultBilling: true
};
firstName: 'Sonia',
lastName: 'Wagner',
},
idCart: cartId,
billingAddress: address,
shippingAddress: address,
payments: [
{
paymentMethodName: 'Invoice',
paymentProviderName: this._getPaymentProviderName(isMpPaymentProvider),
},
],
shipment: {
idShipmentMethod: 2,
},
},
},
};
}

return {
data: {
type: 'checkout',
attributes: {
customer: {
salutation: 'Ms',
email: defaultCustomerEmail,
firstName: 'Sonia',
lastName: 'Wagner'
},
idCart: cartId,
billingAddress: address,
shippingAddress: address,
payments: [
{
paymentMethodName: 'Invoice',
paymentProviderName: this._getPaymentProviderName(isMpPaymentProvider)
}
],
shipment: {
idShipmentMethod: 2
}
}
}
}
}

_getPaymentProviderName(isMpPaymentProvider = true) {
return isMpPaymentProvider ? 'DummyMarketplacePayment' : 'DummyPayment';
}
_getPaymentProviderName(isMpPaymentProvider = true) {
return isMpPaymentProvider ? 'DummyMarketplacePayment' : 'DummyPayment';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,81 +2,81 @@ import { AbstractScenario } from '../../../../abstract-scenario.js';
import { group } from 'k6';

export class SharedOrderAmendmentScenario extends AbstractScenario {
execute(customerEmail, orderId, thresholdTag = null) {
let self = this;
group('Order Amendment', function () {
self.haveOrderAmendment(customerEmail, orderId, thresholdTag);
});
}
execute(customerEmail, orderId, thresholdTag = null) {
let self = this;
group('Order Amendment', function () {
self.haveOrderAmendment(customerEmail, orderId, thresholdTag);
});
}

haveOrderAmendment(customerEmail, orderId, thresholdTag = null) {
this._ensureOrderState(customerEmail, orderId, 'payment pending');
haveOrderAmendment(customerEmail, orderId, thresholdTag = null) {
this._ensureOrderState(customerEmail, orderId, 'payment pending');

const requestParams = this.cartHelper.getParamsWithAuthorization(customerEmail);
if (thresholdTag) {
requestParams.tags = { name: thresholdTag };
}
const requestParams = this.cartHelper.getParamsWithAuthorization(customerEmail);
if (thresholdTag) {
requestParams.tags = { name: thresholdTag };
}

const cartReorderResponse = this.http.sendPostRequest(
this.http.url`${this.getStorefrontApiBaseUrl()}/cart-reorder`,
JSON.stringify(this._getCartReorderAttributes(orderId)),
requestParams,
false
);
const cartReorderResponse = this.http.sendPostRequest(
this.http.url`${this.getStorefrontApiBaseUrl()}/cart-reorder`,
JSON.stringify(this._getCartReorderAttributes(orderId)),
requestParams,
false
);

this.assertionsHelper.assertResponseStatus(cartReorderResponse, 201);
this.assertionsHelper.assertResponseStatus(cartReorderResponse, 201);

try {
return JSON.parse(cartReorderResponse.body);
} catch (e) {
console.log(cartReorderResponse.body);
throw Error('Failed to parse response during SharedOrderAmendmentScenario::haveOrderAmendment()');
}
try {
return JSON.parse(cartReorderResponse.body);
} catch (e) {
console.log(cartReorderResponse.body);
throw Error('Failed to parse response during SharedOrderAmendmentScenario::haveOrderAmendment()');
}
}

_ensureOrderState(customerEmail, orderId, state, maxRetries = 5) {
let retries = 0;
let order;
_ensureOrderState(customerEmail, orderId, state, maxRetries = 5) {
let retries = 0;
let order;

do {
order = this._getOrder(customerEmail, orderId);
if (order.data.attributes.itemStates[0] !== state) {
this.dynamicFixturesHelper.haveConsoleCommands(['console oms:check-condition', 'console oms:check-timeout']);
}
retries++;
} while (order.data.attributes.itemStates[0] !== state && retries < maxRetries);
do {
order = this._getOrder(customerEmail, orderId);
if (order.data.attributes.itemStates[0] !== state) {
this.dynamicFixturesHelper.haveConsoleCommands(['console oms:check-condition', 'console oms:check-timeout']);
}
retries++;
} while (order.data.attributes.itemStates[0] !== state && retries < maxRetries);

if (retries === maxRetries) {
throw new Error(`Order state is not ${state} after ${maxRetries} retries`);
}
if (retries === maxRetries) {
throw new Error(`Order state is not ${state} after ${maxRetries} retries`);
}
}

_getOrder(customerEmail, orderId) {
let self = this;
const orderResponse = self.http.sendGetRequest(
self.http.url`${self.getStorefrontApiBaseUrl()}/orders/${orderId}`,
self.cartHelper.getParamsWithAuthorization(customerEmail),
false
);
self.assertionsHelper.assertResponseStatus(orderResponse, 200);
_getOrder(customerEmail, orderId) {
let self = this;
const orderResponse = self.http.sendGetRequest(
self.http.url`${self.getStorefrontApiBaseUrl()}/orders/${orderId}`,
self.cartHelper.getParamsWithAuthorization(customerEmail),
false
);
self.assertionsHelper.assertResponseStatus(orderResponse, 200);

try {
return JSON.parse(orderResponse.body);
} catch (e) {
console.log(orderResponse.body);
throw Error('Failed to parse response during SharedOrderAmendmentScenario::_getOrder()');
}
try {
return JSON.parse(orderResponse.body);
} catch (e) {
console.log(orderResponse.body);
throw Error('Failed to parse response during SharedOrderAmendmentScenario::_getOrder()');
}
}

_getCartReorderAttributes(orderId) {
return {
data: {
type: 'cart-reorder',
attributes: {
orderReference: orderId,
isAmendment: true
}
}
}
}
_getCartReorderAttributes(orderId) {
return {
data: {
type: 'cart-reorder',
attributes: {
orderReference: orderId,
isAmendment: true,
},
},
};
}
}
Loading

0 comments on commit fd3bdfa

Please sign in to comment.