Skip to content

Commit

Permalink
Remove ignoreOpenApiExample option in testAuth function
Browse files Browse the repository at this point in the history
The `ignoreOpenApiExample` option in the `testAuth` function is no longer needed and has been removed. This option was used to ignore OpenAPI examples for classes without OpenAPI, but it is no longer necessary as the function now handles this case correctly.
BaseService defines by dafault empty object for openApi so if nothing is set we expect empty obj.
Warn devs about missing openApi as openApi is standard for services now.
  • Loading branch information
jNullj committed Jun 8, 2024
1 parent ee75674 commit 263aba7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
1 change: 0 additions & 1 deletion services/sonar/sonar-generic.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ describe('SonarGeneric', function () {
testAuthConfigOverride.public.services.sonar.authorizedOrigins[0],
sonarVersion: '4.2',
},
ignoreOpenApiExample: true,
},
)
})
Expand Down
20 changes: 6 additions & 14 deletions services/test-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ function getBadgeExampleCall(serviceClass, paramType) {
)
}

if (!serviceClass.openApi) {
throw new TypeError(
`Missing OpenAPI in service class ${serviceClass.name}.`,
if (Object.keys(serviceClass.openApi).length === 0) {
console.warn(
`Missing OpenAPI in service class ${serviceClass.name}. Make sure to use exampleOverride in testAuth.`,
)
return {}
}
if (!['path', 'query'].includes(paramType)) {
throw new TypeError('Invalid paramType: Must be path or query.')
Expand Down Expand Up @@ -227,7 +228,6 @@ 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
* @param {boolean} options.multipleRequests - For classes that require multiple requests to complete the test.
* @throws {TypeError} - Throws a TypeError if the input `serviceClass` is not an instance of BaseService,
* or if `serviceClass` is missing authorizedOrigins.
Expand All @@ -253,7 +253,6 @@ async function testAuth(serviceClass, authMethod, dummyResponse, options = {}) {
exampleOverride = {},
authOverride,
configOverride,
ignoreOpenApiExample = false,
multipleRequests = false,
} = options
if (contentType && typeof contentType !== 'string') {
Expand All @@ -275,9 +274,6 @@ 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.')
}
if (multipleRequests && typeof multipleRequests !== 'boolean') {
throw new TypeError('Invalid multipleRequests: Must be an Object.')
}
Expand Down Expand Up @@ -310,12 +306,8 @@ async function testAuth(serviceClass, authMethod, dummyResponse, options = {}) {
authOrigins,
authOverride,
)
const exampleInvokePathParams = ignoreOpenApiExample
? undefined
: getBadgeExampleCall(serviceClass, 'path')
const exampleInvokeQueryParams = ignoreOpenApiExample
? undefined
: getBadgeExampleCall(serviceClass, 'query')
const exampleInvokePathParams = getBadgeExampleCall(serviceClass, 'path')
const exampleInvokeQueryParams = getBadgeExampleCall(serviceClass, 'query')
if (options && typeof options !== 'object') {
throw new TypeError('Invalid options: Must be an object.')
}
Expand Down

0 comments on commit 263aba7

Please sign in to comment.