Skip to content

Commit cd41972

Browse files
author
fo057145
committed
adiciona testes de integração para operações CRUD de autores e ajusta rotas
1 parent b445608 commit cd41972

File tree

10 files changed

+24
-19
lines changed

10 files changed

+24
-19
lines changed

custom-sequencer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const Sequencer = require('@jest/test-sequencer').default;
22

3+
// Ajusta a sequencia de execução por ordem alfabética na suíte
4+
35
class CustomSequencer extends Sequencer {
46
shard(tests, {shardIndex, shardCount}) {
57
const shardSize = Math.ceil(tests.length / shardCount);

jest.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const config: Config = {
44
preset: 'ts-jest', // Define o preset do jest
55
testEnvironment: 'node', // Define o ambiente de teste
66
testSequencer: './custom-sequencer.js', // Define o sequenciador de testes
7-
maxWorkers: 1, // Define a quantidade de workers simultâneos
7+
maxWorkers: 1, // Define a quantidade de workers simultâneos, se mais de 1 habilita o paralelismo
88
// testPathPattern: '.*.spec.ts', // Define o padrão de busca dos arquivos de teste
99
// globalSetup: Define o setup global de configuração
1010
// modulePathIgnorePatterns: [] Ignora os arquivos que estão no caminho
@@ -18,7 +18,7 @@ const config: Config = {
1818
reporters: [
1919
"default",
2020
["./node_modules/jest-html-reporter", {
21-
"pageTitle": "Test Report"
21+
"pageTitle": "Relatório da Suíte de Testes"
2222
}]
2323
],
2424
testLocationInResults: true

test/integration/mssql-db-connection.test.ts renamed to test/integration/exemplos-conexao-db/mssql-db-connection.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { getMSSQLConnection } from '../../db-connection/mssql-connection';
1+
import { getMSSQLConnection } from '../../../db-connection/mssql-connection';
22

33

44
afterAll(async () => {
5-
const pool = await getMSSQLConnection();
5+
const pool = await getMSSQLConnection(); // fecha a conexão ao fim dos testes
66
await pool.close();
77
});
88

Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
import { mysqlPool } from '../../db-connection/mysql-connection';
1+
import { mysqlPool } from '../../../db-connection/mysql-connection';
22

33
describe('MySQL connection', () => {
4+
5+
afterAll(async () => {
6+
await mysqlPool.end(); // fecha a conexão ao fim dos testes
7+
});
8+
49
it('should fetch user with id = 1', async () => {
510
const [rows] = await mysqlPool.query('SELECT name FROM users WHERE id = ?', [1]);
611
const user = (rows as any[])[0];
7-
expect(user.name).toBe('Ana Paula');
12+
expect(user.name).toBe('Ana Paula'); // Busca na base de dados teste criada via docker
813
});
914

10-
afterAll(async () => {
11-
await mysqlPool.end();
12-
});
15+
1316
});

test/integration/postgres-db-connection.test.ts renamed to test/integration/exemplos-conexao-db/postgres-db-connection.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { testConnection, pool } from '../../db-connection/postgres-connection';
1+
import { testConnection, pool } from '../../../db-connection/postgres-connection';
22

33
afterAll(async () => {
44
await pool.end(); // fecha a conexão ao fim dos testes

test/integration/post-request-using-csv.test.ts renamed to test/integration/exemplos-usando-data-driven/post-request-using-csv.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { expect } from '@jest/globals';
22
import * as request from 'supertest';
3-
import { BASE_URL } from '../../constants/constants';
3+
import { BASE_URL } from '../../../constants/constants';
44
import * as path from 'path';
5-
import generics from '../utils/generics';
5+
import generics from '../../utils/generics';
66

77
const randomId = Math.floor(Math.random() * 1000) + 1;
88

test/integration/post-request-using-json.test.ts renamed to test/integration/exemplos-usando-data-driven/post-request-using-json.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { expect } from '@jest/globals';
22
import * as request from 'supertest';
3-
import { BASE_URL } from '../../constants/constants';
3+
import { BASE_URL } from '../../../constants/constants';
44
import * as path from 'path';
5-
import generics from '../utils/generics'
5+
import generics from '../../utils/generics'
66

77
const randomId = Math.floor(Math.random() * 1000) + 1;
88

test/routes/author-route.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export const authors = {
2-
getListAuthors: '/api/v1/Authors',
3-
createAuthors: '/api/v1/Authors',
4-
getAuthorsById: '/api/v1/Authors/',
5-
updateAuthors: '/api/v1/Authors/',
6-
deleteAuthors:'/api/v1/Authors/'
2+
getListAuthors: 'api/v1/Authors',
3+
createAuthors: 'api/v1/Authors',
4+
getAuthorsById: 'api/v1/Authors/',
5+
updateAuthors: 'api/v1/Authors/',
6+
deleteAuthors:'api/v1/Authors/'
77
}

0 commit comments

Comments
 (0)