-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
193 additions
and
174 deletions.
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,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
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
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
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
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
40 changes: 0 additions & 40 deletions
40
tests/suite/sapi/tests/cart-reorder/SUITE-TEST_ID-cart-reorder.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.