Skip to content

Commit

Permalink
(#170) Realiza correcao nos testes unitarios e E2E
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro-cella committed Nov 15, 2023
1 parent 948de50 commit f7ea27c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
3 changes: 2 additions & 1 deletion e2e/idoso.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('E2E - Idoso', () => {
let client: ClientProxy;
let repository: Repository<Idoso>;
let token: string =
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5ceyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c';
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c';

const idoso: Partial<Idoso> = {
id: undefined,
Expand All @@ -40,6 +40,7 @@ describe('E2E - Idoso', () => {
tipoSanguineo: ETipoSanguineo.AB_Negativo,
telefoneResponsavel: '123456789',
descricao: 'desc',
dataHora: new Date().toISOString() as any,
};

beforeAll(async () => {
Expand Down
19 changes: 14 additions & 5 deletions src/idoso/idoso.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Test, TestingModule } from '@nestjs/testing';
import { getRepositoryToken } from '@nestjs/typeorm';
import { Filtering } from '../shared/decorators/filtrate.decorator';
import { OrderParams, Ordering } from '../shared/decorators/ordenate.decorator';
import { Ordering, OrderParams } from '../shared/decorators/ordenate.decorator';
import {
Pagination,
PaginationParams,
Expand All @@ -24,6 +24,7 @@ describe('IdosoController', () => {
tipoSanguineo: ETipoSanguineo.AB_Negativo,
telefoneResponsavel: '123456789',
descricao: 'desc',
dataHora: new Date().toISOString() as any,
};

const idoso = {
Expand Down Expand Up @@ -63,30 +64,38 @@ describe('IdosoController', () => {
});

it('should create Idoso', async () => {
jest.spyOn(service, 'create').mockReturnValue(Promise.resolve(idoso));
jest
.spyOn(service, 'create')
.mockReturnValue(Promise.resolve(idoso as Idoso));

const response = await controller.create(idosoDto);
expect(response.data).toEqual(idoso);
expect(response.message).toEqual('Salvo com sucesso!');
});

it('should find Idoso', async () => {
jest.spyOn(service, 'findOne').mockReturnValue(Promise.resolve(idoso));
jest
.spyOn(service, 'findOne')
.mockReturnValue(Promise.resolve(idoso as Idoso));

const response = await controller.findOne({ id: 1 });
expect(response).toEqual(idoso);
});

it('should remove Idoso', async () => {
jest.spyOn(service, 'remove').mockReturnValue(Promise.resolve(idoso));
jest
.spyOn(service, 'remove')
.mockReturnValue(Promise.resolve(idoso as Idoso));

const response = await controller.remove({ id: 1 });
expect(response.data).toEqual(idoso);
expect(response.message).toEqual('Excluído com sucesso!');
});

it('should update Idoso', async () => {
jest.spyOn(service, 'update').mockReturnValue(Promise.resolve(idoso));
jest
.spyOn(service, 'update')
.mockReturnValue(Promise.resolve(idoso as Idoso));

const response = await controller.update({ id: 1 }, { nome: 'Henrique' });
expect(response.data).toEqual(idoso);
Expand Down

0 comments on commit f7ea27c

Please sign in to comment.