Skip to content

Commit 3500b12

Browse files
author
fo057145
committed
adiciona funcionalidade de atualização e exclusão de autores, além de novos testes para essas operações
1 parent ffcb340 commit 3500b12

File tree

3 files changed

+45
-11
lines changed

3 files changed

+45
-11
lines changed

integration/data/author-data.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,9 @@ export const validaRetornoAutorInvalido = {
3939
type: 'https://tools.ietf.org/html/rfc7231#section-6.5.1',
4040
title: 'One or more validation errors occurred.',
4141
status: 400,
42+
}
43+
44+
export const atualizaAutor = {
45+
firstName: "Han",
46+
lastName: "Solo"
4247
}

integration/entity/entities.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ export class EntityService {
5757
return response
5858
};
5959

60-
public async update(route: string, data: object, statusCode: number, content?: any, checkResponseMessage?: string) {
60+
public async update(route: string, id: number, data: object, statusCode: number, content?: any, checkResponseMessage?: string) {
6161
const response = await request(BASE_URL)
62-
.put(route)
62+
.put(`${route}` + `${id}`)
6363
.send(data)
6464

6565
expect(response.statusCode).toBe(statusCode)

integration/tests/exemplo-usando-entities.test.ts

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,26 @@ import {
55
dadoEsperadoGetById,
66
getByIdNaoEncontrado,
77
dadoEsperadoGetList,
8-
tentaCriarUmAutorComDadosInvalidos
8+
tentaCriarUmAutorComDadosInvalidos,
9+
atualizaAutor
910
} from '../data/author-data';
1011
import { EntityService } from '../entity/entities';
1112
import { authorsRoute } from '../routes/author-route';
1213

1314

14-
const getList = authorsRoute.getListAuthors
15-
const getById = authorsRoute.getAuthorsById
16-
const create = authorsRoute.criaAutors
15+
const getListRoute = authorsRoute.getListAuthors;
16+
const getByIdRoute = authorsRoute.getAuthorsById;
17+
const createRoute = authorsRoute.criaAutors;
18+
const updateRoute = authorsRoute.updateAuthors;
19+
const deleteRoute = authorsRoute.deleteAuthors;
1720

1821
const entity = new EntityService();
1922

2023
describe('Exemplos de teste usando o Get list', () => {
2124

2225
it('Deve encontrar o registro e retornar o código de status 200', async () => {
2326
await entity.getList(
24-
getList, // Rota para listar autores
27+
getListRoute, // Rota para listar autores
2528
200, // Código de status esperado
2629
dadoEsperadoGetList // Dados esperados na resposta
2730
)
@@ -33,7 +36,7 @@ describe('Exemplos de teste usando o Get by id', () => {
3336

3437
it('Deve encontrar o registro pelo id e retornar o código de status 200', async () => {
3538
await entity.getById(
36-
getById,
39+
getByIdRoute,
3740
2, // ID do autor a ser buscado
3841
200,
3942
dadoEsperadoGetById // Dados esperados na resposta
@@ -42,7 +45,7 @@ describe('Exemplos de teste usando o Get by id', () => {
4245

4346
it('Deve tentar encontrar o registro pelo id, mas não encontrado e retornar o código de status 404', async () => {
4447
await entity.getById(
45-
getById,
48+
getByIdRoute,
4649
1000,
4750
404,
4851
getByIdNaoEncontrado
@@ -54,7 +57,7 @@ describe('Exemplos de teste usando o Create', () => {
5457

5558
it('Deve criar um autor e verificar os dados da resposta e o código de status 200', async () => {
5659
await entity.create(
57-
create, // Rota para criar autor
60+
createRoute, // Rota para criar autor
5861
criaAutor, // Dados do autor a ser criado
5962
200,
6063
criaAutor
@@ -63,10 +66,36 @@ describe('Exemplos de teste usando o Create', () => {
6366

6467
it('Deve tentar criar um autor com dados inválidos e verificar a resposta e o código de status 400', async () => {
6568
await entity.create(
66-
create, // Rota para criar autor
69+
createRoute, // Rota para criar autor
6770
tentaCriarUmAutorComDadosInvalidos, // Dados do autor a ser criado
6871
400, // Código de status esperado
6972
validaRetornoAutorInvalido
7073
)
7174
})
75+
76+
});
77+
78+
describe('Exemplos de teste usando o Update', () => {
79+
80+
it('Deve criar um autor e verificar os dados da resposta e o código de status 200', async () => {
81+
await entity.update(
82+
updateRoute, // Rota para atualizar autor
83+
1, // ID do autor a ser atualizado
84+
atualizaAutor, // Dados do autor a ser atualizado
85+
200,
86+
atualizaAutor // Dados esperados na resposta
87+
)
88+
})
89+
});
90+
91+
92+
describe('Exemplos de teste usando o delete', () => {
93+
94+
it('Deve deletar o registro pelo id e retornar o código de status 200', async () => {
95+
await entity.delete(
96+
deleteRoute,
97+
1, // ID do autor a ser deletado
98+
200
99+
)
100+
})
72101
});

0 commit comments

Comments
 (0)