|
1 | 1 | import { INestApplication } from '@nestjs/common';
|
2 | 2 | import { Test, TestingModule } from '@nestjs/testing';
|
3 | 3 | import { type OmitFunctionMembers } from '@spuxx/js-utils';
|
4 |
| -import { NextFunction, Request, Response } from 'express'; |
5 | 4 | import { AuthOptions, SessionResource } from '../../auth';
|
6 | 5 | import { AuthModule } from '../../auth/auth.module';
|
7 | 6 | import { Supertest } from '../supertest';
|
8 | 7 | import { createEndToEndNestApplication } from './private/end-to-end';
|
9 |
| -import { MockOidcModule } from './private/mock-oidc'; |
| 8 | +import { mockExpressOidcPackage, MockOidcModule } from './private/mock-oidc'; |
10 | 9 | import { TestContainerOptions } from './types';
|
11 | 10 |
|
12 |
| -vitest.mock('express-openid-connect', () => { |
13 |
| - return { |
14 |
| - auth: vitest.fn(() => (_req: Request, _res: Response, next: NextFunction) => next()), |
15 |
| - requiresAuth: vitest.fn(() => (_req: Request, _res: Response, next: NextFunction) => next()), |
16 |
| - }; |
17 |
| -}); |
18 |
| - |
19 | 11 | /**
|
20 | 12 | * `TestContainer` provides an abstraction of `Nest.createTestContainer()`, offering
|
21 | 13 | * a custom API for easier handling and use. For more information on testing in NestJS,
|
@@ -84,6 +76,8 @@ export class TestContainer {
|
84 | 76 | ...options,
|
85 | 77 | };
|
86 | 78 |
|
| 79 | + mockExpressOidcPackage(); |
| 80 | + |
87 | 81 | // Auto-add conditional components
|
88 | 82 | if (enableEndToEnd) {
|
89 | 83 | imports.push(AuthModule.forRoot(authOptions as AuthOptions), MockOidcModule);
|
@@ -111,7 +105,7 @@ export class TestContainer {
|
111 | 105 | if (enableEndToEnd) {
|
112 | 106 | app = await createEndToEndNestApplication(module);
|
113 | 107 | session = { ...options.session } ?? {};
|
114 |
| - AuthModule.bootstrap(app, authOptions as AuthOptions); |
| 108 | + await AuthModule.bootstrap(app, authOptions as AuthOptions); |
115 | 109 | supertest = new Supertest(app, session);
|
116 | 110 | }
|
117 | 111 | // Return the test container
|
|
0 commit comments