@@ -228,6 +228,7 @@ function fakeJwtToken() {
228
228
* @param {object } options.authOverride - Override class auth params.
229
229
* @param {object } options.configOverride - Override the config for this test.
230
230
* @param {boolean } options.ignoreOpenApiExample - For classes without OpenApi example ignore for usage of override examples only
231
+ * @param {boolean } options.multipleRequests - For classes that require multiple requests to complete the test.
231
232
* @throws {TypeError } - Throws a TypeError if the input `serviceClass` is not an instance of BaseService,
232
233
* or if `serviceClass` is missing authorizedOrigins.
233
234
*
@@ -242,8 +243,6 @@ async function testAuth(serviceClass, authMethod, dummyResponse, options = {}) {
242
243
)
243
244
}
244
245
245
- cleanUpNockAfterEach ( )
246
-
247
246
const {
248
247
contentType,
249
248
apiHeaderKey = 'x-api-key' ,
@@ -255,6 +254,7 @@ async function testAuth(serviceClass, authMethod, dummyResponse, options = {}) {
255
254
authOverride,
256
255
configOverride,
257
256
ignoreOpenApiExample = false ,
257
+ multipleRequests = false ,
258
258
} = options
259
259
if ( contentType && typeof contentType !== 'string' ) {
260
260
throw new TypeError ( 'Invalid contentType: Must be a String.' )
@@ -278,6 +278,13 @@ async function testAuth(serviceClass, authMethod, dummyResponse, options = {}) {
278
278
if ( ignoreOpenApiExample && typeof ignoreOpenApiExample !== 'boolean' ) {
279
279
throw new TypeError ( 'Invalid ignoreOpenApiExample: Must be an Object.' )
280
280
}
281
+ if ( multipleRequests && typeof multipleRequests !== 'boolean' ) {
282
+ throw new TypeError ( 'Invalid multipleRequests: Must be an Object.' )
283
+ }
284
+
285
+ if ( ! multipleRequests ) {
286
+ cleanUpNockAfterEach ( )
287
+ }
281
288
282
289
const auth = { ...serviceClass . auth , ...authOverride }
283
290
const fakeUser = auth . userKey
@@ -321,6 +328,9 @@ async function testAuth(serviceClass, authMethod, dummyResponse, options = {}) {
321
328
const scopeArr = [ ]
322
329
authOrigins . forEach ( authOrigin => {
323
330
const scope = nock ( authOrigin )
331
+ if ( multipleRequests ) {
332
+ scope . persist ( )
333
+ }
324
334
scopeArr . push ( scope )
325
335
switch ( authMethod ) {
326
336
case 'BasicAuth' :
@@ -400,6 +410,15 @@ async function testAuth(serviceClass, authMethod, dummyResponse, options = {}) {
400
410
) ,
401
411
) . to . not . have . property ( 'isError' )
402
412
413
+ // cleapup persistance if we have multiple requests
414
+ if ( multipleRequests ) {
415
+ scopeArr . forEach ( scope => scope . persist ( false ) )
416
+ nock . restore ( )
417
+ nock . cleanAll ( )
418
+ nock . enableNetConnect ( )
419
+ nock . activate ( )
420
+ }
421
+
403
422
// if we get 'Mocks not yet satisfied' we have redundent authOrigins or we are missing a critical request
404
423
scopeArr . forEach ( scope => scope . done ( ) )
405
424
}
0 commit comments