Skip to content

Commit

Permalink
Add exampleOverride to testAuth
Browse files Browse the repository at this point in the history
Introduce `exampleOverride` to test authentication scenarios.
Allows providing custom examples for testAuth via an object.
Simulates service requests that trigger desiered condition paths in tests.
  • Loading branch information
jNullj committed Feb 22, 2024
1 parent 2590482 commit 4d57607
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion services/test-helpers.js
Expand Up @@ -207,6 +207,7 @@ function fakeJwtToken() {
* @param {string} options.queryUserKey - QueryStringAuth user key.
* @param {string} options.queryPassKey - QueryStringAuth pass key.
* @param {string} options.jwtLoginEndpoint - jwtAuth Login endpoint.
* @param {object} options.exampleOverride - Override example params in test.
* @throws {TypeError} - Throws a TypeError if the input `serviceClass` is not an instance of BaseService,
* or if `serviceClass` is missing authorizedOrigins.
*
Expand Down Expand Up @@ -243,6 +244,7 @@ async function testAuth(serviceClass, authMethod, dummyResponse, options = {}) {
queryUserKey,
queryPassKey,
jwtLoginEndpoint,
exampleOverride = {},
} = options
if (contentType && typeof contentType !== 'string') {
throw new TypeError('Invalid contentType: Must be a String.')
Expand All @@ -254,6 +256,9 @@ async function testAuth(serviceClass, authMethod, dummyResponse, options = {}) {
if (!bearerHeaderKey || typeof bearerHeaderKey !== 'string') {
throw new TypeError('Invalid bearerHeaderKey: Must be a String.')
}
if (!exampleOverride || typeof exampleOverride !== 'object') {
throw new TypeError('Invalid exampleOverride: Must be an Object.')
}

if (!authOrigins) {
throw new TypeError(`Missing authorizedOrigins for ${serviceClass.name}.`)
Expand Down Expand Up @@ -328,7 +333,10 @@ async function testAuth(serviceClass, authMethod, dummyResponse, options = {}) {
})

expect(
await serviceClass.invoke(defaultContext, config, exampleInvokeParams),
await serviceClass.invoke(defaultContext, config, {
...exampleInvokeParams,
...exampleOverride,
}),
).to.not.have.property('isError')

// if we get 'Mocks not yet satisfied' we have redundent authOrigins or we are missing a critical request
Expand Down

0 comments on commit 4d57607

Please sign in to comment.