refactor(persons): simplify Person
model by consolidating fields and updating related tests
This commit is contained in:
parent
a1abde36e6
commit
ea6684b7fa
@ -1,7 +1,7 @@
|
|||||||
import { Test, TestingModule } from '@nestjs/testing';
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
import { PersonsController } from './persons.controller';
|
import { PersonsController } from './persons.controller';
|
||||||
import { PersonsService } from '../services/persons.service';
|
import { PersonsService } from '../services/persons.service';
|
||||||
import { CreatePersonDto, Gender, OralEaseLevel } from '../dto/create-person.dto';
|
import { CreatePersonDto } from '../dto/create-person.dto';
|
||||||
import { UpdatePersonDto } from '../dto/update-person.dto';
|
import { UpdatePersonDto } from '../dto/update-person.dto';
|
||||||
import { JwtAuthGuard } from '../../auth/guards/jwt-auth.guard';
|
import { JwtAuthGuard } from '../../auth/guards/jwt-auth.guard';
|
||||||
|
|
||||||
@ -12,16 +12,10 @@ describe('PersonsController', () => {
|
|||||||
// Mock data
|
// Mock data
|
||||||
const mockPerson = {
|
const mockPerson = {
|
||||||
id: 'person1',
|
id: 'person1',
|
||||||
firstName: 'John',
|
name: 'John Doe',
|
||||||
lastName: 'Doe',
|
|
||||||
gender: Gender.MALE,
|
|
||||||
technicalLevel: 3,
|
|
||||||
hasTechnicalTraining: true,
|
|
||||||
frenchSpeakingLevel: 4,
|
|
||||||
oralEaseLevel: OralEaseLevel.COMFORTABLE,
|
|
||||||
age: 30,
|
|
||||||
projectId: 'project1',
|
projectId: 'project1',
|
||||||
attributes: {},
|
skills: ['JavaScript', 'TypeScript'],
|
||||||
|
metadata: {},
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
};
|
};
|
||||||
@ -66,14 +60,10 @@ describe('PersonsController', () => {
|
|||||||
describe('create', () => {
|
describe('create', () => {
|
||||||
it('should create a new person', async () => {
|
it('should create a new person', async () => {
|
||||||
const createPersonDto: CreatePersonDto = {
|
const createPersonDto: CreatePersonDto = {
|
||||||
firstName: 'John',
|
name: 'John Doe',
|
||||||
lastName: 'Doe',
|
|
||||||
gender: Gender.MALE,
|
|
||||||
technicalLevel: 3,
|
|
||||||
hasTechnicalTraining: true,
|
|
||||||
frenchSpeakingLevel: 4,
|
|
||||||
oralEaseLevel: OralEaseLevel.COMFORTABLE,
|
|
||||||
projectId: 'project1',
|
projectId: 'project1',
|
||||||
|
skills: ['JavaScript', 'TypeScript'],
|
||||||
|
metadata: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(await controller.create(createPersonDto)).toBe(mockPerson);
|
expect(await controller.create(createPersonDto)).toBe(mockPerson);
|
||||||
@ -106,7 +96,7 @@ describe('PersonsController', () => {
|
|||||||
it('should update a person', async () => {
|
it('should update a person', async () => {
|
||||||
const id = 'person1';
|
const id = 'person1';
|
||||||
const updatePersonDto: UpdatePersonDto = {
|
const updatePersonDto: UpdatePersonDto = {
|
||||||
firstName: 'Jane',
|
name: 'Jane Doe',
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(await controller.update(id, updatePersonDto)).toBe(mockPerson);
|
expect(await controller.update(id, updatePersonDto)).toBe(mockPerson);
|
||||||
@ -151,4 +141,4 @@ describe('PersonsController', () => {
|
|||||||
expect(service.removeFromGroup).toHaveBeenCalledWith(id, groupId);
|
expect(service.removeFromGroup).toHaveBeenCalledWith(id, groupId);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -2,7 +2,6 @@ import { Test, TestingModule } from '@nestjs/testing';
|
|||||||
import { PersonsService } from './persons.service';
|
import { PersonsService } from './persons.service';
|
||||||
import { NotFoundException } from '@nestjs/common';
|
import { NotFoundException } from '@nestjs/common';
|
||||||
import { DRIZZLE } from '../../../database/database.module';
|
import { DRIZZLE } from '../../../database/database.module';
|
||||||
import { Gender, OralEaseLevel } from '../dto/create-person.dto';
|
|
||||||
|
|
||||||
describe('PersonsService', () => {
|
describe('PersonsService', () => {
|
||||||
let service: PersonsService;
|
let service: PersonsService;
|
||||||
@ -11,16 +10,10 @@ describe('PersonsService', () => {
|
|||||||
// Mock data
|
// Mock data
|
||||||
const mockPerson = {
|
const mockPerson = {
|
||||||
id: 'person1',
|
id: 'person1',
|
||||||
firstName: 'John',
|
name: 'John Doe',
|
||||||
lastName: 'Doe',
|
|
||||||
gender: Gender.MALE,
|
|
||||||
technicalLevel: 3,
|
|
||||||
hasTechnicalTraining: true,
|
|
||||||
frenchSpeakingLevel: 4,
|
|
||||||
oralEaseLevel: OralEaseLevel.COMFORTABLE,
|
|
||||||
age: 30,
|
|
||||||
projectId: 'project1',
|
projectId: 'project1',
|
||||||
attributes: {},
|
skills: ['JavaScript', 'TypeScript'],
|
||||||
|
metadata: {},
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
};
|
};
|
||||||
@ -83,14 +76,10 @@ describe('PersonsService', () => {
|
|||||||
describe('create', () => {
|
describe('create', () => {
|
||||||
it('should create a new person', async () => {
|
it('should create a new person', async () => {
|
||||||
const createPersonDto = {
|
const createPersonDto = {
|
||||||
firstName: 'John',
|
name: 'John Doe',
|
||||||
lastName: 'Doe',
|
|
||||||
gender: Gender.MALE,
|
|
||||||
technicalLevel: 3,
|
|
||||||
hasTechnicalTraining: true,
|
|
||||||
frenchSpeakingLevel: 4,
|
|
||||||
oralEaseLevel: OralEaseLevel.COMFORTABLE,
|
|
||||||
projectId: 'project1',
|
projectId: 'project1',
|
||||||
|
skills: ['JavaScript', 'TypeScript'],
|
||||||
|
metadata: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = await service.create(createPersonDto);
|
const result = await service.create(createPersonDto);
|
||||||
@ -159,7 +148,7 @@ describe('PersonsService', () => {
|
|||||||
it('should update a person', async () => {
|
it('should update a person', async () => {
|
||||||
const id = 'person1';
|
const id = 'person1';
|
||||||
const updatePersonDto = {
|
const updatePersonDto = {
|
||||||
firstName: 'Jane',
|
name: 'Jane Doe',
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = await service.update(id, updatePersonDto);
|
const result = await service.update(id, updatePersonDto);
|
||||||
@ -173,7 +162,7 @@ describe('PersonsService', () => {
|
|||||||
it('should throw NotFoundException if person not found', async () => {
|
it('should throw NotFoundException if person not found', async () => {
|
||||||
const id = 'nonexistent';
|
const id = 'nonexistent';
|
||||||
const updatePersonDto = {
|
const updatePersonDto = {
|
||||||
firstName: 'Jane',
|
name: 'Jane Doe',
|
||||||
};
|
};
|
||||||
|
|
||||||
mockDb.update.mockImplementationOnce(() => mockDbOperations);
|
mockDb.update.mockImplementationOnce(() => mockDbOperations);
|
||||||
@ -274,4 +263,4 @@ describe('PersonsService', () => {
|
|||||||
await expect(service.removeFromGroup(personId, groupId)).rejects.toThrow(NotFoundException);
|
await expect(service.removeFromGroup(personId, groupId)).rejects.toThrow(NotFoundException);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -126,9 +126,13 @@ describe('ProjectsController', () => {
|
|||||||
it('should check if a user has access to a project', async () => {
|
it('should check if a user has access to a project', async () => {
|
||||||
const projectId = 'project1';
|
const projectId = 'project1';
|
||||||
const userId = 'user1';
|
const userId = 'user1';
|
||||||
|
const mockRes = {
|
||||||
|
json: jest.fn().mockReturnValue(true)
|
||||||
|
};
|
||||||
|
|
||||||
expect(await controller.checkUserAccess(projectId, userId)).toBe(true);
|
await controller.checkUserAccess(projectId, userId, mockRes);
|
||||||
expect(service.checkUserAccess).toHaveBeenCalledWith(projectId, userId);
|
expect(service.checkUserAccess).toHaveBeenCalledWith(projectId, userId);
|
||||||
|
expect(mockRes.json).toHaveBeenCalledWith(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user