mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 11:16:31 -05:00
test: allow disabling mocked authentication
This adds a (default true) parameter `withMockAuth` to the TestSetup class. If it is false, the TokenAuthGuard is not overridden with a mock implementation, allowing to test with the real authentication. Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
bcb75a1d04
commit
ff500f1be0
1 changed files with 9 additions and 6 deletions
|
@ -55,7 +55,7 @@ export class TestSetup {
|
|||
|
||||
users: User[] = [];
|
||||
|
||||
public static async create(): Promise<TestSetup> {
|
||||
public static async create(withMockAuth = true): Promise<TestSetup> {
|
||||
const testSetup = new TestSetup();
|
||||
const routes: Routes = [
|
||||
{
|
||||
|
@ -68,7 +68,7 @@ export class TestSetup {
|
|||
},
|
||||
];
|
||||
|
||||
testSetup.moduleRef = await Test.createTestingModule({
|
||||
const testingModule = await Test.createTestingModule({
|
||||
imports: [
|
||||
RouterModule.forRoutes(routes),
|
||||
TypeOrmModule.forRoot({
|
||||
|
@ -104,10 +104,13 @@ export class TestSetup {
|
|||
FrontendConfigModule,
|
||||
IdentityModule,
|
||||
],
|
||||
})
|
||||
.overrideGuard(TokenAuthGuard)
|
||||
.useClass(MockAuthGuard)
|
||||
.compile();
|
||||
});
|
||||
|
||||
if (withMockAuth) {
|
||||
testingModule.overrideGuard(TokenAuthGuard).useClass(MockAuthGuard);
|
||||
}
|
||||
|
||||
testSetup.moduleRef = await testingModule.compile();
|
||||
|
||||
testSetup.userService = testSetup.moduleRef.get<UsersService>(UsersService);
|
||||
testSetup.configService =
|
||||
|
|
Loading…
Reference in a new issue