-
Notifications
You must be signed in to change notification settings - Fork 2
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-34716: Cart Reorder + Order Amendment features. #27
Merged
dmiseev
merged 9 commits into
master
from
feature/cc-34716-cart-reorder-and-order-amendment
Dec 4, 2024
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c5118c8
CC-34716: Added tests for cart-reorder.
dmiseev e4b4bd9
CC-34716: Added tests for order-amendment.
dmiseev ac814ee
CC-34716: Added diff executors.
dmiseev 4ada73d
CC-34716: Adjusted tests.
dmiseev dfbf220
CC-34716: Adjusted tests.
dmiseev 2146719
CC-34716: Adjusted tests.
dmiseev 13f70b3
CC-34716: Adjusted tests.
dmiseev 371aa9a
CC-34716: Fixes before CR.
dmiseev 498ce4c
CC-34716: Fixes after CR.
dmiseev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.idea/ | ||
settings.json | ||
result.html | ||
/node_modules/ | ||
/.env | ||
/results/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
version: '3.4' | ||
|
||
services: | ||
k6: | ||
container_name: "loadtesting_environment" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"local": { | ||
"storefrontUrl": "http://yves.%store%.spryker.local", | ||
"storefrontApiUrl": "http://glue.%store%.spryker.local", | ||
"backendApiUrl": "http://glue-backend.%store%.spryker.local", | ||
"backofficeUrl": "http://backoffice.%store%.spryker.local", | ||
"backofficeApiUrl": "http://backend-api.%store%.spryker.local", | ||
"stores": ["eu", "us"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
export class AuthTokenManager { | ||
constructor(http, urlHelper, assertionsHelper) { | ||
if (AuthTokenManager.instance) { | ||
return AuthTokenManager.instance; | ||
} | ||
|
||
if (!http || !urlHelper || !assertionsHelper) { | ||
throw new Error('Http, UrlHelper, and AssertionsHelper must be provided.'); | ||
} | ||
|
||
this.http = http; | ||
this.urlHelper = urlHelper; | ||
this.assertionsHelper = assertionsHelper; | ||
|
||
// Token cache: { '<email>:<password>': 'Bearer <token>' } | ||
this.tokenCache = {}; | ||
|
||
AuthTokenManager.instance = this; | ||
} | ||
|
||
static getInstance(http, urlHelper, assertionsHelper) { | ||
if (!AuthTokenManager.instance) { | ||
AuthTokenManager.instance = new AuthTokenManager(http, urlHelper, assertionsHelper); | ||
} | ||
return AuthTokenManager.instance; | ||
} | ||
|
||
getAuthToken(email, password) { | ||
const cacheKey = `${email}:${password}`; | ||
|
||
// Return cached token if exists | ||
if (this.tokenCache[cacheKey]) { | ||
return this.tokenCache[cacheKey]; | ||
} | ||
|
||
// Fetch new token from the API | ||
const urlAccessTokens = `${this.urlHelper.getStorefrontApiBaseUrl()}/access-tokens`; | ||
const response = this.http.sendPostRequest( | ||
this.http.url`${urlAccessTokens}`, | ||
JSON.stringify({ | ||
data: { | ||
type: 'access-tokens', | ||
attributes: { | ||
username: email, | ||
password: password, | ||
}, | ||
}, | ||
}), | ||
{ headers: { Accept: 'application/json' } }, | ||
false | ||
); | ||
|
||
this.assertionsHelper.assertResponseStatus(response, 201, 'Auth Token'); | ||
|
||
const responseJson = JSON.parse(response.body); | ||
this.assertionsHelper.assertSingleResourceResponseBodyStructure(responseJson, 'Auth Token'); | ||
|
||
const token = `${responseJson.data.attributes.tokenType} ${responseJson.data.attributes.accessToken}`; | ||
this.tokenCache[cacheKey] = token; | ||
|
||
return token; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
export class DynamicFixturesHelper { | ||
constructor(backendApiUrl, http) { | ||
this.backendApiUrl = backendApiUrl; | ||
this.http = http; | ||
} | ||
|
||
haveCustomersWithQuotes(customerCount, quoteCount = 1, itemCount = 10, defaultItemPrice = 1000) { | ||
const defaultParams = { | ||
headers: { | ||
'Content-Type': 'application/vnd.api+json', | ||
}, | ||
}; | ||
|
||
const dynamicFixturesResponse = this.http.sendPostRequest( | ||
this.http.url`${this.backendApiUrl}/dynamic-fixtures`, | ||
JSON.stringify(this._getCustomersWithQuotesAttributes(customerCount, quoteCount, itemCount, defaultItemPrice)), | ||
defaultParams, | ||
false | ||
); | ||
|
||
const dynamicFixturesResponseJson = JSON.parse(dynamicFixturesResponse.body); | ||
const customerData = dynamicFixturesResponseJson.data.filter(item => /^customer\d+$/.test(item.attributes.key)); | ||
|
||
return customerData.map(customer => { | ||
const associatedCustomerQuotes = dynamicFixturesResponseJson.data | ||
.filter(item => item.attributes.key.startsWith(`${customer.attributes.key}Quote`)) | ||
.map(quote => quote.attributes.data.uuid); | ||
|
||
return { | ||
customerEmail: customer.attributes.data.email, | ||
quoteIds: associatedCustomerQuotes | ||
}; | ||
}); | ||
} | ||
|
||
haveConsoleCommands(commands) { | ||
const params = { | ||
headers: { | ||
'Content-Type': 'application/vnd.api+json', | ||
}, | ||
timeout: 600000, | ||
}; | ||
|
||
this.http.sendPostRequest( | ||
this.http.url`${this.backendApiUrl}/dynamic-fixtures`, | ||
JSON.stringify(this._getConsoleCommandsAttributes(commands)), | ||
params, | ||
false | ||
); | ||
} | ||
|
||
_getConsoleCommandsAttributes(commands) { | ||
const operations = commands.map((command) => { | ||
return { | ||
type: 'cli-command', | ||
name: command, | ||
}; | ||
}); | ||
|
||
return { | ||
data: { | ||
type: 'dynamic-fixtures', | ||
attributes: { | ||
operations: operations, | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
_getCustomersWithQuotesAttributes(customerCount = 1, quoteCount = 1, itemCount = 10, defaultItemPrice = 100) { | ||
const baseOperations = [ | ||
{ | ||
type: 'transfer', | ||
name: 'LocaleTransfer', | ||
key: 'locale', | ||
arguments: { id_locale: 66, locale_name: 'en_US' } | ||
}, | ||
{ | ||
type: 'transfer', | ||
name: 'ProductImageTransfer', | ||
key: 'productImage', | ||
arguments: { | ||
externalUrlSmall: 'https://images.icecat.biz/img/gallery_mediums/30691822_1486.jpg', | ||
externalUrlLarge: 'https://images.icecat.biz/img/gallery/30691822_1486.jpg' | ||
} | ||
} | ||
]; | ||
|
||
// Generate products dynamically | ||
const products = Array.from({ length: itemCount }, (_, i) => { | ||
const productKey = `product${i + 1}`; | ||
return [ | ||
{ | ||
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: defaultItemPrice, grossAmount: defaultItemPrice } | ||
} | ||
] | ||
}, | ||
{ | ||
type: 'helper', | ||
name: 'haveProductInStock', | ||
arguments: [{ sku: `#${productKey}.sku`, isNeverOutOfStock: '1', fkStock: 1, stockType: 'Warehouse1' }] | ||
} | ||
]; | ||
}).flat(); | ||
|
||
// Generate items dynamically for quotes | ||
const generateItems = () => { | ||
return Array.from({ length: itemCount }, (_, i) => ({ | ||
sku: `#product${i + 1}.sku`, | ||
abstractSku: `#product${i + 1}.abstract_sku`, | ||
quantity: 1, | ||
unitPrice: defaultItemPrice | ||
})); | ||
}; | ||
|
||
// Generate customers dynamically | ||
const customers = Array.from({ length: customerCount }, (_, customerIndex) => { | ||
const customerKey = `customer${customerIndex + 1}`; | ||
return [ | ||
{ | ||
type: 'helper', | ||
name: 'haveCustomer', | ||
key: customerKey, | ||
arguments: [{ locale: '#locale', password: 'change123' }] | ||
}, | ||
{ | ||
type: 'helper', | ||
name: 'confirmCustomer', | ||
key: `confirmed${customerKey}`, | ||
arguments: [`#${customerKey}`] | ||
}, | ||
// Generate quotes for each customer | ||
...Array.from({ length: quoteCount }, (_, quoteIndex) => ({ | ||
type: 'helper', | ||
name: 'havePersistentQuote', | ||
key: `${customerKey}Quote${quoteIndex + 1}`, | ||
arguments: [ | ||
{ | ||
customer: `#${customerKey}`, | ||
items: generateItems() | ||
} | ||
] | ||
})) | ||
]; | ||
}).flat(); | ||
|
||
return { | ||
data: { | ||
type: 'dynamic-fixtures', | ||
attributes: { | ||
synchronize: true, | ||
operations: [...baseOperations, ...products, ...customers] | ||
} | ||
} | ||
}; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,6 +1,18 @@ | ||||||
import { textSummary } from '../lib/external/k6-summary.js'; | ||||||
import { htmlReport } from '../lib/external/k6-html-report.js'; | ||||||
|
||||||
export function handleSummary(data) { | ||||||
if (__ENV.K6_HOSTENV === 'local') { | ||||||
return { | ||||||
'result.html': htmlReport(data), | ||||||
stdout: textSummary(data, { indent: ' ', enableColors: true }), | ||||||
}; | ||||||
} else { | ||||||
return handleSummaryTesting(data); | ||||||
} | ||||||
} | ||||||
|
||||||
function handleSummaryTesting(data) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor:
Suggested change
As I understand it is used in this class only |
||||||
const failedMetrics = getFailedMetrics(data); | ||||||
|
||||||
const summary = { | ||||||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: generate products, customers, etc would be better to move to a separate methods just for readability
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be reworked in next phase. For now I would keep it as it is.