Skip to content

Commit

Permalink
Add option to not import openApi example in testAuth
Browse files Browse the repository at this point in the history
Added for services without openApi examples.
Dev can use example override to add example inputs in those cases.
  • Loading branch information
jNullj committed Mar 9, 2024
1 parent 99a01e1 commit 74554d7
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions services/test-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ function fakeJwtToken() {
* @param {object} options.exampleOverride - Override example params in test.
* @param {object} options.authOverride - Override class auth params.
* @param {object} options.configOverride - Override the config for this test.
* @param {boolean} options.ignoreOpenApiExample - For classes without OpenApi example ignore for usage of override examples only
* @throws {TypeError} - Throws a TypeError if the input `serviceClass` is not an instance of BaseService,
* or if `serviceClass` is missing authorizedOrigins.
*
Expand All @@ -253,6 +254,7 @@ async function testAuth(serviceClass, authMethod, dummyResponse, options = {}) {
exampleOverride = {},
authOverride,
configOverride,
ignoreOpenApiExample = false,
} = options
if (contentType && typeof contentType !== 'string') {
throw new TypeError('Invalid contentType: Must be a String.')
Expand All @@ -273,6 +275,9 @@ async function testAuth(serviceClass, authMethod, dummyResponse, options = {}) {
if (configOverride && typeof configOverride !== 'object') {
throw new TypeError('Invalid configOverride: Must be an Object.')
}
if (ignoreOpenApiExample && typeof ignoreOpenApiExample !== 'boolean') {
throw new TypeError('Invalid ignoreOpenApiExample: Must be an Object.')
}

const auth = { ...serviceClass.auth, ...authOverride }
const fakeUser = auth.userKey ? 'fake-user' : undefined
Expand All @@ -294,8 +299,12 @@ async function testAuth(serviceClass, authMethod, dummyResponse, options = {}) {
authOrigins,
authOverride,
)
const exampleInvokePathParams = getBadgeExampleCall(serviceClass, 'path')
const exampleInvokeQueryParams = getBadgeExampleCall(serviceClass, 'query')
const exampleInvokePathParams = ignoreOpenApiExample
? undefined
: getBadgeExampleCall(serviceClass, 'path')
const exampleInvokeQueryParams = ignoreOpenApiExample
? undefined
: getBadgeExampleCall(serviceClass, 'query')
if (options && typeof options !== 'object') {
throw new TypeError('Invalid options: Must be an object.')
}
Expand Down

0 comments on commit 74554d7

Please sign in to comment.