From 74554d74a731a6431903d8e970de607f09ea1453 Mon Sep 17 00:00:00 2001 From: jNullj <15849761+jNullj@users.noreply.github.com> Date: Sat, 9 Mar 2024 17:20:04 +0200 Subject: [PATCH] Add option to not import openApi example in testAuth Added for services without openApi examples. Dev can use example override to add example inputs in those cases. --- services/test-helpers.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/services/test-helpers.js b/services/test-helpers.js index d9677e1b46e42..a8944e5dc1556 100644 --- a/services/test-helpers.js +++ b/services/test-helpers.js @@ -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. * @@ -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.') @@ -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 @@ -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.') }