Skip to content
Snippets Groups Projects
Commit 06559912 authored by Bastien DUMONT's avatar Bastien DUMONT :angel:
Browse files

tests: add tests for users.controller

parent 1a4c86c1
No related branches found
No related tags found
2 merge requests!404V3.1.0 (sans impression),!386tests: add tests for users.controller
This diff is collapsed.
......@@ -53,7 +53,7 @@ export class UsersController {
@UseGuards(JwtAuthGuard)
@ApiBearerAuth('JWT')
@ApiOperation({ description: 'Get user profile' })
@ApiResponse({ status: HttpStatus.OK, description: 'Return user profil' })
@ApiResponse({ status: HttpStatus.OK, description: 'Return user profile' })
@ApiResponse({ status: HttpStatus.UNAUTHORIZED, description: 'User does not have sufficient rights' })
@Get('profile')
public getProfile(@Request() req) {
......@@ -63,7 +63,8 @@ export class UsersController {
@UseGuards(JwtAuthGuard)
@ApiBearerAuth('JWT')
@ApiOperation({ description: 'Set user profile with employer and job' })
@ApiResponse({ status: HttpStatus.OK, description: 'Return user profil' })
@ApiBody({ type: ProfileDto })
@ApiResponse({ status: HttpStatus.OK, description: 'Return user profile' })
@ApiResponse({ status: HttpStatus.BAD_REQUEST, description: 'Job does not exist' })
@ApiResponse({ status: HttpStatus.BAD_REQUEST, description: 'Employer does not exist' })
@Post('profile')
......@@ -79,17 +80,22 @@ export class UsersController {
this.logger.warn(`Job does not exist: ${profile.jobName}`);
throw new HttpException('Job does not exist', HttpStatus.BAD_REQUEST);
}
await this.usersService.updateUserProfile(req.user._id, employerDocument, jobDocument, profile.withAppointment);
return this.usersService.findOne(req.user.email);
const user = await this.usersService.updateUserProfile(
req.user._id,
employerDocument,
jobDocument,
profile.withAppointment
);
return user;
}
@UseGuards(JwtAuthGuard)
@ApiBearerAuth('JWT')
@ApiOperation({ description: 'Updates name, surname and phone number of a user' })
@ApiBody({ type: UpdateDetailsDto })
@ApiResponse({ status: HttpStatus.CREATED, description: 'Return user profil' })
@ApiResponse({ status: HttpStatus.CREATED, description: 'Return user profile' })
@ApiResponse({ status: HttpStatus.NOT_FOUND, description: 'User not found' })
@ApiResponse({ status: HttpStatus.BAD_REQUEST, description: 'Missing parametter' })
@ApiResponse({ status: HttpStatus.BAD_REQUEST, description: 'Missing parameter' })
@Post('details')
public async updateDetails(@Request() req, @Body() details: UpdateDetailsDto): Promise<User | HttpException> {
this.logger.debug('updateProfile details');
......@@ -239,7 +245,7 @@ export class UsersController {
this.structureService.sendStructureJoinRequest(userFromDb, structure, token[0]);
}
//add token in route + add infos in token
/** add token in route + add infos in token */
@Get('join-validate/:token/:status')
@ApiParam({ name: 'token', type: String, required: true })
@ApiParam({ name: 'status', type: String, required: true })
......@@ -250,7 +256,7 @@ export class UsersController {
id: string;
name: string;
}> {
const decoded: IPendingStructureToken = this.jwtService.decode(token) as IPendingStructureToken;
const decoded = this.jwtService.decode(token) as IPendingStructureToken;
const today = DateTime.local().setZone('utc', { keepLocalTime: true });
if (!token || !status) {
......@@ -272,7 +278,7 @@ export class UsersController {
if (
!userFromDb.pendingStructuresLink
.map((pending) => pending.id)
.filter((id) => id.equals(new Types.ObjectId(decoded.idStructure)))
.some((id) => id.equals(new Types.ObjectId(decoded.idStructure)))
) {
throw new HttpException('User not linked to structure', HttpStatus.NOT_FOUND);
}
......@@ -289,7 +295,7 @@ export class UsersController {
return { id: decoded.idStructure, name: structure.structureName };
}
// Cancel a user's join request
/** Cancel a user's join request */
@Get('join-cancel/:idStructure/:idUser')
@ApiParam({ name: 'idStructure', type: String, required: true })
@ApiParam({ name: 'idUser', type: String, required: true })
......@@ -307,7 +313,7 @@ export class UsersController {
if (
!userFromDb.pendingStructuresLink
.map((pending) => pending.id)
.filter((id) => id.equals(new Types.ObjectId(idStructure)))
.some((id) => id.equals(new Types.ObjectId(idStructure)))
) {
throw new HttpException('This structure is in pending state', HttpStatus.NOT_FOUND);
}
......
import { Types } from 'mongoose';
import { IUser } from '../../../src/users/interfaces/user.interface';
import { IUserRegistry } from '../../../src/users/interfaces/userRegistry.interface';
import { User } from '../../../src/users/schemas/user.schema';
export const usersMockData: IUser[] = [
{
......@@ -222,8 +223,8 @@ export const userRegistryMockData: IUserRegistry = {
save: jest.fn(),
} as any;
export const mockUser = {
_id: 'id',
export const mockUser: User = {
// _id: 'id',
validationToken:
'cf1c74c22cedb6b575945098db42d2f493fb759c9142c6aff7980f252886f36ee086574ee99a06bc99119079257116c959c8ec870949cebdef2b293666dbca42',
emailVerified: true,
......@@ -234,4 +235,13 @@ export const mockUser = {
surname: 'Pauline',
personalOffers: [],
structuresLink: [new Types.ObjectId('6093ba0e2ab5775cfc01ed3e')],
createdAt: new Date(2024, 1, 1),
phone: '',
resetPasswordToken: '',
changeEmailToken: '',
newEmail: '',
pendingStructuresLink: [],
structureOutdatedMailSent: [],
unattachedSince: new Date(2024, 1, 1),
lastLoginDate: new Date(2024, 1, 1),
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment