-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(projects): remove findAll projects and replace for findAllByRole
- Loading branch information
Showing
8 changed files
with
98 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,12 @@ import chai, { expect } from 'chai'; | |
import chaiAsPromised from 'chai-as-promised'; | ||
import { randomUUID } from 'crypto'; | ||
import sinon from 'sinon'; | ||
import { SupportedRoles } from '../../../../utils/enums'; | ||
import { CompanyRepository } from '../../../infra/repositories/company.repository'; | ||
import { EmployeeTaskRepository } from '../../../infra/repositories/employee-task.repository'; | ||
import { EmployeeRepository } from '../../../infra/repositories/employee.repository'; | ||
import { ProjectRepository } from '../../../infra/repositories/project.repository'; | ||
import { RoleRepository } from '../../../infra/repositories/role.repository'; | ||
import { TaskRepository } from '../../../infra/repositories/tasks.repository'; | ||
import { HomeService } from '../home.service'; | ||
|
||
|
@@ -16,22 +19,45 @@ describe('HomeService', () => { | |
let findTaskByEmployeeIdStub: sinon.SinonStub; | ||
let findAllTasksStub: sinon.SinonStub; | ||
let findAllCompaniesStub: sinon.SinonStub; | ||
let findEmployeeByEmail: sinon.SinonStub; | ||
let findEmployeeById: sinon.SinonStub; | ||
let findRoleById: sinon.SinonStub; | ||
|
||
beforeEach(() => { | ||
findAllProjectsStub = sinon.stub(ProjectRepository, 'findAll'); | ||
findAllProjectsStub = sinon.stub(ProjectRepository, 'findAllByRole'); | ||
findTaskByEmployeeIdStub = sinon.stub(EmployeeTaskRepository, 'findByEmployeeId'); | ||
findAllTasksStub = sinon.stub(TaskRepository, 'findAll'); | ||
findAllCompaniesStub = sinon.stub(CompanyRepository, 'findAll'); | ||
findEmployeeByEmail = sinon.stub(EmployeeRepository, 'findByEmail'); | ||
findEmployeeById = sinon.stub(EmployeeRepository, 'findById'); | ||
findRoleById = sinon.stub(RoleRepository, 'findById'); | ||
}); | ||
|
||
afterEach(() => { | ||
sinon.restore(); | ||
}); | ||
|
||
describe('getHomeInfo', () => { | ||
it('should return the projects an employee has assigned and teh companies of those projects', async () => { | ||
it('should return the projects an employee has assigned and the companies of those projects', async () => { | ||
const employeeId = randomUUID(); | ||
|
||
const accountingRole = randomUUID(); | ||
|
||
const role = { | ||
title: SupportedRoles.ACCOUNTING, | ||
createdAr: new Date(), | ||
}; | ||
|
||
const employee = { | ||
id: employeeId, | ||
firstName: 'John', | ||
lastName: 'Doe', | ||
email: '[email protected]', | ||
imageUrl: 'http://example.com/john.jpg', | ||
createdAt: new Date(), | ||
idRole: accountingRole, | ||
}; | ||
|
||
const companyId = randomUUID(); | ||
const companyId2 = randomUUID(); | ||
const existingCompanies = [ | ||
|
@@ -122,6 +148,10 @@ describe('HomeService', () => { | |
}, | ||
]; | ||
|
||
findEmployeeByEmail.resolves(employee); | ||
findEmployeeById.resolves(employee); | ||
findRoleById.resolves(role); | ||
|
||
findAllProjectsStub.resolves(existingProjects); | ||
findAllCompaniesStub.resolves(existingCompanies); | ||
findAllTasksStub.resolves(existingTasks); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,28 +2,40 @@ import { faker } from '@faker-js/faker'; | |
import { expect } from 'chai'; | ||
import { randomUUID } from 'crypto'; | ||
import { default as Sinon, default as sinon } from 'sinon'; | ||
import { ProjectCategory, ProjectPeriodicity, ProjectStatus, SupportedDepartments } from '../../../../utils/enums'; | ||
import { | ||
ProjectCategory, | ||
ProjectPeriodicity, | ||
ProjectStatus, | ||
SupportedDepartments, | ||
SupportedRoles, | ||
} from '../../../../utils/enums'; | ||
import { ProjectEntity } from '../../../domain/entities/project.entity'; | ||
import { CompanyRepository } from '../../../infra/repositories/company.repository'; | ||
import { EmployeeRepository } from '../../../infra/repositories/employee.repository'; | ||
import { ProjectRepository } from '../../../infra/repositories/project.repository'; | ||
import { RoleRepository } from '../../../infra/repositories/role.repository'; | ||
import { CompanyService } from '../company.service'; | ||
import { ProjectService } from '../project.service'; | ||
|
||
describe('ProjectService', () => { | ||
let findProjectByIdStub: Sinon.SinonStub; | ||
let createProject: sinon.SinonStub; | ||
let findAllStub: sinon.SinonStub; | ||
let findAllByRoleStub: sinon.SinonStub; | ||
let findCompanyByIdStub: Sinon.SinonStub; | ||
let findProjectsByClientId: Sinon.SinonStub; | ||
let updateProjectStub: sinon.SinonStub; | ||
let updateProjectStatusStub: sinon.SinonStub; | ||
let findEmployeeByEmail: sinon.SinonStub; | ||
let findRoleById: sinon.SinonStub; | ||
|
||
beforeEach(() => { | ||
createProject = sinon.stub(ProjectRepository, 'createProject'); | ||
findAllStub = sinon.stub(ProjectRepository, 'findAll'); | ||
findAllByRoleStub = sinon.stub(ProjectRepository, 'findAllByRole'); | ||
findProjectByIdStub = sinon.stub(ProjectRepository, 'findById'); | ||
findProjectsByClientId = sinon.stub(ProjectRepository, 'findProjetsByClientId'); | ||
findCompanyByIdStub = sinon.stub(CompanyRepository, 'findById'); | ||
findEmployeeByEmail = sinon.stub(EmployeeRepository, 'findByEmail'); | ||
findRoleById = sinon.stub(RoleRepository, 'findById'); | ||
}); | ||
|
||
afterEach(() => { | ||
|
@@ -97,6 +109,23 @@ describe('ProjectService', () => { | |
|
||
describe('getAllProjects', () => { | ||
it('should return all projects', async () => { | ||
const accountingRole = randomUUID(); | ||
|
||
const role = { | ||
title: SupportedRoles.ACCOUNTING, | ||
createdAr: new Date(), | ||
}; | ||
|
||
const employee = { | ||
id: randomUUID(), | ||
firstName: 'John', | ||
lastName: 'Doe', | ||
email: '[email protected]', | ||
imageUrl: 'http://example.com/john.jpg', | ||
createdAt: new Date(), | ||
idRole: accountingRole, | ||
}; | ||
|
||
const projects = [ | ||
{ | ||
id: randomUUID(), | ||
|
@@ -110,7 +139,7 @@ describe('ProjectService', () => { | |
endDate: new Date('2023-12-01T00:00:00.000Z'), | ||
periodicity: '1 week', | ||
isChargeable: true, | ||
area: 'Client', | ||
area: SupportedDepartments.ACCOUNTING, | ||
createdAt: new Date('2024-04-19T01:23:49.555Z'), | ||
idCompany: randomUUID(), | ||
}, | ||
|
@@ -126,15 +155,17 @@ describe('ProjectService', () => { | |
endDate: new Date('2023-12-01T00:00:00.000Z'), | ||
periodicity: '1 week', | ||
isChargeable: true, | ||
area: 'Client', | ||
area: SupportedDepartments.ACCOUNTING, | ||
createdAt: new Date('2024-04-19T01:23:49.555Z'), | ||
idCompany: randomUUID(), | ||
}, | ||
]; | ||
|
||
findAllStub.resolves(projects); | ||
findEmployeeByEmail.resolves(employee); | ||
findRoleById.resolves(role); | ||
findAllByRoleStub.resolves(projects); | ||
|
||
const getProjects = await ProjectService.getAllProjects(); | ||
const getProjects = await ProjectService.getDepartmentProjects(employee.email); | ||
|
||
expect(getProjects).eql(projects); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.