Skip to content

Commit

Permalink
(#137) corrige formatacao
Browse files Browse the repository at this point in the history
  • Loading branch information
HenriqueAmorim20 committed Oct 20, 2023
1 parent 1cad6cb commit 628f11f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
8 changes: 5 additions & 3 deletions e2e/usuario.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ describe('E2E - Usuario', () => {

expect(res.statusCode).toEqual(201);
expect(res.body.message).toEqual('Salvo com sucesso!');
expect(res.body.data).toMatchObject({ ...user, id: res.body.data.id, senha: res.body.data.senha });
expect(res.body.data).toMatchObject({
...user,
id: res.body.data.id,
senha: res.body.data.senha,
});

Object.assign(user, res.body.data);
delete user.senha;
Expand All @@ -70,8 +74,6 @@ describe('E2E - Usuario', () => {
expect(res.statusCode).toEqual(400);
expect(res.body.message).toEqual('Este email já está cadastrado!');
expect(res.body.data).toBeNull();


});

it('should not add a new "usuario" when validations are incorrect', async () => {
Expand Down
25 changes: 15 additions & 10 deletions src/usuario/usuario.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { BadRequestException } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { Test, TestingModule } from '@nestjs/testing';
import { getRepositoryToken } from '@nestjs/typeorm';
import bcrypt from 'bcrypt';
import { Repository } from 'typeorm';
import { OrderParams, Ordering } from '../shared/decorators/ordenate.decorator';
import {
Expand All @@ -8,10 +11,6 @@ import {
} from '../shared/decorators/paginate.decorator';
import { Usuario } from './entities/usuario.entity';
import { UsuarioService } from './usuario.service';
import { ConfigService } from '@nestjs/config';
import bcrypt from 'bcrypt';
import { BadRequestException } from '@nestjs/common';


describe('UsuarioService', () => {
let service: UsuarioService;
Expand All @@ -32,10 +31,9 @@ describe('UsuarioService', () => {
})),
};


const mockConfigService = {
get: jest.fn(),
}
};

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
Expand Down Expand Up @@ -66,18 +64,25 @@ describe('UsuarioService', () => {
jest.spyOn(repository, 'save').mockReturnValue({ id: 1 } as any);
jest.spyOn(repository, 'findOne').mockReturnValue(undefined as any);
jest.spyOn(configService, 'get').mockReturnValue(10 as any);
jest.spyOn(bcrypt, 'hash').mockImplementation((pass: string | Buffer, salt: string | number) => Promise.resolve('senha'));
jest
.spyOn(bcrypt, 'hash')
.mockImplementation((pass: string | Buffer, salt: string | number) =>
Promise.resolve('senha'),
);
const created = await service.create(user);
expect(created.id).toEqual(1);
});

it('should not create Usuario', async () => {
const user = { nome: 'Henrique' } as any;
jest.spyOn(repository, 'findOne').mockReturnValue({ email: '[email protected]' } as any);
expect(service.create(user)).rejects.toThrow(new BadRequestException('Este email já está cadastrado!'));
jest
.spyOn(repository, 'findOne')
.mockReturnValue({ email: '[email protected]' } as any);
expect(service.create(user)).rejects.toThrow(
new BadRequestException('Este email já está cadastrado!'),
);
});


it('should find Usuario', async () => {
jest.spyOn(repository, 'findOneOrFail').mockReturnValue({ id: 1 } as any);

Expand Down
2 changes: 1 addition & 1 deletion src/usuario/usuario.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class UsuarioService {
@InjectRepository(Usuario)
private readonly _repository: Repository<Usuario>,
private readonly _configService: ConfigService,
) { }
) {}

async create(body: CreateUsuarioDto): Promise<Usuario> {
const usuario = new Usuario(body);
Expand Down

0 comments on commit 628f11f

Please sign in to comment.