From 4d57607763f6eadba4f7d52ed167d757c3ae74b2 Mon Sep 17 00:00:00 2001 From: jNullj <15849761+jNullj@users.noreply.github.com> Date: Thu, 22 Feb 2024 23:07:24 +0200 Subject: [PATCH] Add exampleOverride to testAuth 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. --- services/test-helpers.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/services/test-helpers.js b/services/test-helpers.js index b1368389c33c5..71a76549afd97 100644 --- a/services/test-helpers.js +++ b/services/test-helpers.js @@ -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. * @@ -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.') @@ -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}.`) @@ -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