mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-13 14:44:43 -04: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[] = [];
|
users: User[] = [];
|
||||||
|
|
||||||
public static async create(): Promise<TestSetup> {
|
public static async create(withMockAuth = true): Promise<TestSetup> {
|
||||||
const testSetup = new TestSetup();
|
const testSetup = new TestSetup();
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{
|
{
|
||||||
|
@ -68,7 +68,7 @@ export class TestSetup {
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
testSetup.moduleRef = await Test.createTestingModule({
|
const testingModule = await Test.createTestingModule({
|
||||||
imports: [
|
imports: [
|
||||||
RouterModule.forRoutes(routes),
|
RouterModule.forRoutes(routes),
|
||||||
TypeOrmModule.forRoot({
|
TypeOrmModule.forRoot({
|
||||||
|
@ -104,10 +104,13 @@ export class TestSetup {
|
||||||
FrontendConfigModule,
|
FrontendConfigModule,
|
||||||
IdentityModule,
|
IdentityModule,
|
||||||
],
|
],
|
||||||
})
|
});
|
||||||
.overrideGuard(TokenAuthGuard)
|
|
||||||
.useClass(MockAuthGuard)
|
if (withMockAuth) {
|
||||||
.compile();
|
testingModule.overrideGuard(TokenAuthGuard).useClass(MockAuthGuard);
|
||||||
|
}
|
||||||
|
|
||||||
|
testSetup.moduleRef = await testingModule.compile();
|
||||||
|
|
||||||
testSetup.userService = testSetup.moduleRef.get<UsersService>(UsersService);
|
testSetup.userService = testSetup.moduleRef.get<UsersService>(UsersService);
|
||||||
testSetup.configService =
|
testSetup.configService =
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue