mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-12-01 18:02:47 -05:00
Tests: Fix Mock Auth
This makes it possible to create the user before the mock auth guard does it's magic. This is necessary for some test, where we need the user object before the api is called. Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
36f041f0e0
commit
d457729ab7
1 changed files with 7 additions and 1 deletions
|
@ -16,8 +16,14 @@ export class MockAuthGuard {
|
||||||
async canActivate(context: ExecutionContext) {
|
async canActivate(context: ExecutionContext) {
|
||||||
const req = context.switchToHttp().getRequest();
|
const req = context.switchToHttp().getRequest();
|
||||||
if (!this.user) {
|
if (!this.user) {
|
||||||
|
// this assures that we can create the user 'hardcoded', if we need them before any calls are made or
|
||||||
|
// create them on the fly when the first call to the api is made
|
||||||
|
try {
|
||||||
|
this.user = await this.usersService.getUserByUsername('hardcoded');
|
||||||
|
} catch (e) {
|
||||||
this.user = await this.usersService.createUser('hardcoded', 'Testy');
|
this.user = await this.usersService.createUser('hardcoded', 'Testy');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
req.user = this.user;
|
req.user = this.user;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue