mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-19 01:35:18 -04:00
auth: Add tests for AuthService
Move AuthTokens to auth folder Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
599fe57ec6
commit
84ec528d14
30 changed files with 329 additions and 186 deletions
|
@ -7,11 +7,11 @@
|
|||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { TokensController } from './tokens.controller';
|
||||
import { LoggerModule } from '../../../logger/logger.module';
|
||||
import { UsersModule } from '../../../users/users.module';
|
||||
import { getRepositoryToken } from '@nestjs/typeorm';
|
||||
import { Identity } from '../../../users/identity.entity';
|
||||
import { User } from '../../../users/user.entity';
|
||||
import { AuthToken } from '../../../users/auth-token.entity';
|
||||
import { AuthToken } from '../../../auth/auth-token.entity';
|
||||
import { AuthModule } from '../../../auth/auth.module';
|
||||
|
||||
describe('TokensController', () => {
|
||||
let controller: TokensController;
|
||||
|
@ -19,7 +19,7 @@ describe('TokensController', () => {
|
|||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [TokensController],
|
||||
imports: [LoggerModule, UsersModule],
|
||||
imports: [LoggerModule, AuthModule],
|
||||
})
|
||||
.overrideProvider(getRepositoryToken(User))
|
||||
.useValue({})
|
||||
|
|
|
@ -14,15 +14,15 @@ import {
|
|||
Post,
|
||||
} from '@nestjs/common';
|
||||
import { ConsoleLoggerService } from '../../../logger/console-logger.service';
|
||||
import { UsersService } from '../../../users/users.service';
|
||||
import { AuthTokenDto } from '../../../users/auth-token.dto';
|
||||
import { AuthTokenWithSecretDto } from '../../../users/auth-token-with-secret.dto';
|
||||
import { AuthTokenDto } from '../../../auth/auth-token.dto';
|
||||
import { AuthTokenWithSecretDto } from '../../../auth/auth-token-with-secret.dto';
|
||||
import { AuthService } from '../../../auth/auth.service';
|
||||
|
||||
@Controller('tokens')
|
||||
export class TokensController {
|
||||
constructor(
|
||||
private readonly logger: ConsoleLoggerService,
|
||||
private usersService: UsersService,
|
||||
private authService: AuthService,
|
||||
) {
|
||||
this.logger.setContext(TokensController.name);
|
||||
}
|
||||
|
@ -31,8 +31,8 @@ export class TokensController {
|
|||
async getUserTokens(): Promise<AuthTokenDto[]> {
|
||||
// ToDo: Get real userName
|
||||
return (
|
||||
await this.usersService.getTokensByUsername('hardcoded')
|
||||
).map((token) => this.usersService.toAuthTokenDto(token));
|
||||
await this.authService.getTokensByUsername('hardcoded')
|
||||
).map((token) => this.authService.toAuthTokenDto(token));
|
||||
}
|
||||
|
||||
@Post()
|
||||
|
@ -41,18 +41,13 @@ export class TokensController {
|
|||
@Body('until') until: number,
|
||||
): Promise<AuthTokenWithSecretDto> {
|
||||
// ToDo: Get real userName
|
||||
const authToken = await this.usersService.createTokenForUser(
|
||||
'hardcoded',
|
||||
label,
|
||||
until,
|
||||
);
|
||||
return this.usersService.toAuthTokenWithSecretDto(authToken);
|
||||
return this.authService.createTokenForUser('hardcoded', label, until);
|
||||
}
|
||||
|
||||
@Delete('/:keyId')
|
||||
@HttpCode(204)
|
||||
async deleteToken(@Param('keyId') keyId: string) {
|
||||
// ToDo: Get real userName
|
||||
return this.usersService.removeToken('hardcoded', keyId);
|
||||
return this.authService.removeToken('hardcoded', keyId);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue