Skip to content

Commit

Permalink
CI implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoCL311 committed May 21, 2024
1 parent d194667 commit c2d5bd5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: rootpassword
MYSQL_DATABASE: testdb
MYSQL_DATABASE: test
ports:
- 3307:3306
options: >-
Expand All @@ -63,14 +63,15 @@ jobs:
- name: Initialize database
run: |
docker exec -i $(docker ps -q --filter "ancestor=mysql:8.0") mysql -uroot -prootpassword testdb < ./dbscripts/mysql.sql
docker exec -i $(docker ps -q --filter "ancestor=mysql:8.0") mysql -uroot -prootpassword test < ./dbscripts/mysql.sql
- name: Run tests
env:
MYSQL_DATABASE: testdb
MYSQL_DATABASE: test
MYSQL_USER: root
MYSQL_HOST: 127.0.0.1
MYSQL_PASSWORD: rootpassword
MYSQL_URL: mysql://root:[email protected]:3307/testdb
MYSQL_URL: mysql://root:[email protected]:3307/test
MYSQL_PORT: 3307
NODE_ENV: test
run: npm test
4 changes: 2 additions & 2 deletions dbscripts/mysql.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

CREATE DATABASE `template` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */ /*!80016 DEFAULT ENCRYPTION='N' */;
CREATE DATABASE IF NOT EXISTS `template` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */ /*!80016 DEFAULT ENCRYPTION='N' */;

USE template;

Expand All @@ -16,7 +16,7 @@ CREATE TABLE `usuarios` (



CREATE DATABASE `test` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */ /*!80016 DEFAULT ENCRYPTION='N' */;
CREATE DATABASE IF NOT EXISTS `test` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */ /*!80016 DEFAULT ENCRYPTION='N' */;

USE test;

Expand Down
6 changes: 5 additions & 1 deletion src/middlewares/errorMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ export function errorMiddleware(
break;

default:
new InternalError("Error interno.").send(res);
if (process.env.NODE_ENV !== "production") {
new InternalError(error.message).send(res);
} else {
new InternalError("Error interno.").send(res);
}
break;
}

Expand Down
11 changes: 11 additions & 0 deletions tests/unit/controllers/authController.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ describe('Auth Controller', () => {
.post('/api/auth/login')
.send({});

console.log(response.body);

expect(response.status).toBe(400);
expect(response.body).toHaveProperty('message', "email is required, contrasena is required");

Expand All @@ -26,6 +28,7 @@ describe('Auth Controller', () => {
const email = faker.internet.email();
const contrasena = faker.internet.password();


user = {
nombre: 'testuser',
email: email,
Expand All @@ -36,6 +39,8 @@ describe('Auth Controller', () => {
.post('/api/auth/register')
.send(user);

console.log(response.body);

expect(response.status).toBe(200);
expect(response.body).toHaveProperty('message', 'Registro exitoso');
});
Expand All @@ -46,6 +51,8 @@ describe('Auth Controller', () => {
.post('/api/auth/login')
.send({ email: user.email, contrasena: user.contrasena });

console.log(response.body);

expect(response.status).toBe(200);
expect(response.body).toHaveProperty('message', 'Inicio de sesion exitoso');
expect(response.body).toHaveProperty('data');
Expand All @@ -61,6 +68,8 @@ describe('Auth Controller', () => {
contrasena: '22222222222275f6tuyibinj',
});

console.log(response.body);

expect(response.status).toBe(400);
expect(response).toHaveProperty('error');
expect(response.body).toHaveProperty('message', 'Credenciales inválidas');
Expand Down Expand Up @@ -90,6 +99,8 @@ describe('Auth Controller', () => {
contrasena: 'testpassword',
});

console.log(response.body);

expect(response.status).toBe(400);
expect(response).toHaveProperty('error');
expect(response.body).toHaveProperty('message', 'email must be a valid email');
Expand Down

0 comments on commit c2d5bd5

Please sign in to comment.