Skip to content

Commit

Permalink
Merge pull request #35 from fga-eps-mds/hotfix/34-paginacao-contratos
Browse files Browse the repository at this point in the history
[HOTFIX] Remove paginação de contratos
  • Loading branch information
eliseukadesh67 authored Sep 4, 2024
2 parents bda5e12 + c039e29 commit dde4bc7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 17 deletions.
13 changes: 1 addition & 12 deletions src/controllers/contractController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,11 @@ import {
export default {
async list(request: Request, response: Response) {
try {
const numero = request.query.numero as string;

const page = parseInt(request.query.page as string) || 1;
const pageSize = parseInt(request.query.pageSize as string) || 5;

const skip = (page - 1) * pageSize;
const take = pageSize;
const contracts = await prisma.contrato.findMany({ skip, take });
const totalContracts = await prisma.contrato.count();
const contracts = await prisma.contrato.findMany();

return response.status(200).json({
data: contracts,
page: page,
pageSize: pageSize,
total: totalContracts,
totalPages: Math.ceil(totalContracts / pageSize),
});
} catch (error) {
return response.status(500).json({
Expand Down
7 changes: 2 additions & 5 deletions tests/contracts.specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,18 @@ describe('Contract Controller', () => {
];

const findManySpy = jest.spyOn(prisma.contrato, 'findMany').mockResolvedValue(contracts);
const countSpy = jest.spyOn(prisma.contrato, 'count').mockResolvedValue(1);

const response = await request(server).get('/').query({ page: 1, pageSize: 5 });
const response = await request(server).get('/');

expect(response.status).toBe(200);
expect(response.body.data).toHaveLength(1);
expect(response.body.total).toBe(1);
expect(findManySpy).toHaveBeenCalled();
expect(countSpy).toHaveBeenCalled();
});

it('should handle errors', async () => {
jest.spyOn(prisma.contrato, 'findMany').mockRejectedValue(new Error('Database error'));

const response = await request(server).get('/').query({ page: 1, pageSize: 5 });
const response = await request(server).get('/');

expect(response.status).toBe(500);
expect(response.body.message).toBe('Erro: Ocorreu um erro ao buscar contratos.');
Expand Down

0 comments on commit dde4bc7

Please sign in to comment.