Fix tests and cleanup api responses

This commit is contained in:
2023-03-23 17:45:45 +09:00
committed by Bluub
parent a9574cb75a
commit f788872f9b
4 changed files with 54 additions and 46 deletions
+5 -3
View File
@@ -9,6 +9,7 @@ import {
BadRequestException, BadRequestException,
HttpCode, HttpCode,
Put, Put,
InternalServerErrorException,
} from '@nestjs/common'; } from '@nestjs/common';
import { AuthService } from './auth.service'; import { AuthService } from './auth.service';
import { JwtAuthGuard } from './jwt-auth.guard'; import { JwtAuthGuard } from './jwt-auth.guard';
@@ -54,7 +55,6 @@ export class AuthController {
} }
@HttpCode(200) @HttpCode(200)
@UseGuards(LocalAuthGuard)
@Post('guest') @Post('guest')
async guest(): Promise<JwtToken> { async guest(): Promise<JwtToken> {
try { try {
@@ -70,8 +70,10 @@ export class AuthController {
@ApiOkResponse({ description: 'Successfully logged in', type: User }) @ApiOkResponse({ description: 'Successfully logged in', type: User })
@ApiUnauthorizedResponse({ description: 'Invalid token' }) @ApiUnauthorizedResponse({ description: 'Invalid token' })
@Get('me') @Get('me')
getProfile(@Request() req: any): User { async getProfile(@Request() req: any): Promise<User> {
return req.user; const user = await this.usersService.user({ id: req.user.id });
if (!user) throw new InternalServerErrorException();
return user;
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard)
+4 -2
View File
@@ -6,7 +6,9 @@ export class User {
@ApiProperty() @ApiProperty()
username: string; username: string;
@ApiProperty() @ApiProperty()
password: string;
@ApiProperty()
email: string; email: string;
@ApiProperty()
isGuest: boolean;
@ApiProperty()
partyPlayed: number;
} }
-41
View File
@@ -59,44 +59,3 @@ Login
Should Be Equal As Strings ${res["body"]} ${me["body"]} Should Be Equal As Strings ${res["body"]} ${me["body"]}
[Teardown] DELETE /auth/me [Teardown] DELETE /auth/me
LoginAsGuest
[Documentation] Login as a guest
&{res}= POST /auth/guest
Output
Integer response status 200
String response body access_token
Set Headers {"Authorization": "Bearer ${res.body.access_token}"}
${res}= GET /auth/me
Output
Integer response status 200
Boolean response body isGuest true
[Teardown] DELETE /auth/me
GuestToNormal
[Documentation] Login as a guest and convert to a normal account
&{res}= POST /auth/guest
Output
Integer response status 200
String response body access_token
Set Headers {"Authorization": "Bearer ${res.body.access_token}"}
${res}= GET /auth/me
Output
Integer response status 200
Boolean response body isGuest true
${res}= PUT /auth/me { "username": "toto", "passord": "toto", "email": "a@b.c"}
Output
Integer response status 200
Boolean response body isGuest true
${res}= GET /auth/me
Output
Integer response status 200
String response body username "toto"
Boolean response body isGuest false
[Teardown] DELETE /auth/me
+45
View File
@@ -0,0 +1,45 @@
*** Settings ***
Documentation Tests of the /auth route.
... Ensures that the user can authenticate on kyoo.
Resource ../rest.resource
Resource ./auth.resource
*** Test Cases ***
LoginAsGuest
[Documentation] Login as a guest
&{res}= POST /auth/guest
Output
Integer response status 200
String response body access_token
Set Headers {"Authorization": "Bearer ${res.body.access_token}"}
${res}= GET /auth/me
Output
Integer response status 200
Boolean response body isGuest true
Integer response body partyPlayed 0
[Teardown] DELETE /auth/me
GuestToNormal
[Documentation] Login as a guest and convert to a normal account
&{res}= POST /auth/guest
Output
Integer response status 200
String response body access_token
Set Headers {"Authorization": "Bearer ${res.body.access_token}"}
${res}= GET /auth/me
Output
Integer response status 200
Boolean response body isGuest true
${res}= PUT /auth/me { "username": "toto", "password": "toto", "email": "a@b.c"}
Output
Integer response status 200
String response body username "toto"
Boolean response body isGuest false
[Teardown] DELETE /auth/me