fix: align auth success status contract
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import { HTTP_CODE_METADATA } from '@nestjs/common/constants';
|
||||
|
||||
jest.mock('./auth.service', () => ({
|
||||
AuthService: class AuthService {},
|
||||
}));
|
||||
|
||||
import { AuthController } from './auth.controller';
|
||||
|
||||
describe('AuthController response statuses', () => {
|
||||
it.each(['register', 'login', 'refresh'] as const)(
|
||||
'%s explicitly returns HTTP 200',
|
||||
(handler) => {
|
||||
// Nest stores @HttpCode metadata on the unbound handler function.
|
||||
const handlerTarget = Object.getOwnPropertyDescriptor(
|
||||
AuthController.prototype,
|
||||
handler,
|
||||
)?.value as object;
|
||||
expect(Reflect.getMetadata(HTTP_CODE_METADATA, handlerTarget)).toBe(200);
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -49,6 +49,7 @@ export class AuthController {
|
||||
constructor(private readonly auth: AuthService) {}
|
||||
|
||||
@Post('register')
|
||||
@HttpCode(200)
|
||||
@ApiOkResponse({ type: AuthenticationDto })
|
||||
async register(
|
||||
@Body() credentials: CredentialsDto,
|
||||
@@ -61,6 +62,7 @@ export class AuthController {
|
||||
}
|
||||
|
||||
@Post('login')
|
||||
@HttpCode(200)
|
||||
@ApiOkResponse({ type: AuthenticationDto })
|
||||
async login(
|
||||
@Body() credentials: CredentialsDto,
|
||||
@@ -73,6 +75,7 @@ export class AuthController {
|
||||
}
|
||||
|
||||
@Post('refresh')
|
||||
@HttpCode(200)
|
||||
@ApiOkResponse({ type: AuthenticationDto })
|
||||
async refresh(
|
||||
@Req() request: Request,
|
||||
|
||||
Reference in New Issue
Block a user