Skip to content

Commit aedbfe5

Browse files
authored
Merge pull request #34 from muke78/staging
deploy: Mejoras de codigo, refresh token, estandarizacion de archivos, mejoras en shells de husky, testing completado correctamente
2 parents a997ee9 + 85dd8ff commit aedbfe5

76 files changed

Lines changed: 643 additions & 369 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.husky/commit-msg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ echo "🔍 Validando mensaje de commit..."
33

44
# Expresión regular mejorada:
55
# tipo(scope opcional): descripción mínima de 10 caracteres
6+
# git commit -m "feat(funcionalidad): "Nueva funcionalidad para el sistema"
67
commit_regex="^(feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert)(\([a-zA-Z0-9_-]+\))?: ?.{10,}$"
78
commit_msg=$(cat "$1")
89

.husky/pre-commit

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,20 @@
11
#!/bin/sh
22

3+
# Cargar NVM (necesario en entornos donde Husky no hereda el PATH completo)
4+
export NVM_DIR="$HOME/.nvm"
5+
# Esto carga nvm
6+
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
7+
# Esto carga nvm para bash >=0.4.0
8+
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
9+
310
echo "🔍 Verificando archivos antes del commit..."
11+
echo "📦 Formateando código con Prettier..."
412

5-
# Ejecutar pruebas con yarn
6-
# echo "🧪 Ejecutando tests..."
7-
# if ! yarn test; then
8-
# echo "❌ Tests fallaron. Corrige los errores antes de hacer commit."
9-
# exit 1
10-
# fi
13+
yarn prettier 'src/**/*.{js,ts,jsx,tsx,json}' server.js package.json --write || exit 1
1114

12-
# Formatear código con Prettier
13-
echo "🚀 Ejecutando Prettier..."
14-
if ! yarn prettier . --write; then
15-
echo "❌ Error al ejecutar Prettier."
16-
exit 1
17-
fi
1815

1916
# Agregar los archivos modificados después del formateo
2017
git add .
2118

22-
# Verificar que el código esté actualizado antes del push
23-
echo "🔄 Verificando que tu código esté actualizado..."
24-
if ! git pull; then
25-
echo "❌ Error al actualizar el código. Revisa los conflictos."
26-
exit 1
27-
fi
2819

29-
echo "✅ Todo listo para el commit. 🎉"
20+
echo "✅ Todo listo para el commit. 🎉"

.husky/pre-push

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
#!/bin/sh
3+
4+
BRANCH=$(git symbolic-ref --short HEAD)
5+
6+
if [ "$BRANCH" = "staging" ]; then
7+
echo "📍 Estás en la rama 'staging'. Ejecutando pruebas..."
8+
echo "🧪 Ejecutando tests con servidor..."
9+
10+
if ! yarn test:with-server; then
11+
echo "❌ Tests fallaron. Corrige los errores antes de hacer commit."
12+
exit 1
13+
fi
14+
else
15+
echo "🚫 No estás en la rama 'staging'. No se ejecutan los tests."
16+
fi

package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
"description": "Backend API for the project, using Node.js, Express, and MySQL.",
55
"main": "server.js",
66
"scripts": {
7-
"start": "node server.js",
8-
"dev": "node --watch server.js",
9-
"format": "prettier . --write",
7+
"start": "nodemon server.js",
8+
"dev": "nodemon server.js",
9+
"format": "prettier 'src/**/*.{js,ts,jsx,tsx,json}' server.js package.json --write",
1010
"prepare": "husky",
1111
"test": "jest",
12-
"test:watch": "jest --watchAll"
12+
"test:watch": "jest --watchAll",
13+
"test:with-server": "concurrently --kill-others --success first \"yarn dev\" \"yarn test\""
1314
},
1415
"license": "MIT",
1516
"type": "module",
@@ -51,11 +52,13 @@
5152
"devDependencies": {
5253
"@eslint/js": "^9.26.0",
5354
"@faker-js/faker": "^9.7.0",
55+
"concurrently": "^9.2.0",
5456
"dotenv": "^16.5.0",
5557
"eslint": "^9.26.0",
5658
"frisby": "^2.1.3",
5759
"globals": "^16.1.0",
5860
"jest": "^29.7.0",
61+
"nodemon": "^3.1.10",
5962
"prettier": "^3.5.3"
6063
}
6164
}

server.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import morgan from "morgan";
55
import { createServer } from "node:http";
66

77
import { setupSwagger } from "./src/config/swaggerConfig.js";
8-
import { corsOptions } from "./src/middleware/cors.js";
9-
import { errorHandler } from "./src/middleware/errorHandler.js";
10-
import { router } from "./src/router/index.js";
8+
import { corsOptions } from "./src/middleware/cors.middleware.js";
9+
import { errorHandler } from "./src/middleware/errorHandler.middleware.js";
10+
import { router } from "./src/routes/index.js";
1111

1212
// Datos del proyecto
1313
const projectInfo = {
14-
name: "CRM Kinder Garden",
14+
name: "CRM Kinder Garden Backend",
1515
description: "CRM para Gestión y Administración de una escuela",
1616
version: "1.0.0",
1717
authorName: "Erick Gonzalez",
@@ -72,6 +72,6 @@ server.on("error", (error) => {
7272

7373
server.listen(currentPort, () => {
7474
console.log(
75-
`🟢 Server is listening on port localhost:${server.address().port}`,
75+
`🟢 API funcionando correctamente, servidor corriendo en el puerto localhost:${server.address().port}`,
7676
);
7777
});

src/__tests__/users/apiCreateUser.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require("dotenv").config();
22
const frisby = require("frisby");
3-
const { createTokenTesting } = require("../../helpers/apiCreateToken");
3+
const { createTokenTesting } = require("../../helpers/apiCreateToken.helpers");
44

55
const BASE_URL = process.env.BASE_URL;
66

@@ -16,7 +16,7 @@ describe("✅ Prueba para crear a un nuevo usuario", () => {
1616
},
1717
},
1818
})
19-
.post(`${BASE_URL}/crear-usuario`, {
19+
.post(`${BASE_URL}/users`, {
2020
nameUser: "apiTESTCreate",
2121
email: uniqueEmail,
2222
password: "123456788u02kljfLK",

src/__tests__/users/apiDeleteUser.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require("dotenv").config();
22
const frisby = require("frisby");
3-
const { createTokenTesting } = require("../../helpers/apiCreateToken");
3+
const { createTokenTesting } = require("../../helpers/apiCreateToken.helpers");
44
const { randomUUID } = require("node:crypto");
55

66
const BASE_URL = process.env.BASE_URL;
@@ -17,7 +17,7 @@ describe("✅ Prueba para eliminar un usuario por su id", () => {
1717
},
1818
},
1919
})
20-
.del(`${BASE_URL}/eliminar-usuario/${id}`)
20+
.del(`${BASE_URL}/users/${id}`)
2121
.then((res) => {
2222
// console.log("🔎 STATUS:", res.status);
2323
// console.log("🔎 RESPONSE:", res.json);

src/__tests__/users/apiListUsers.test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require("dotenv").config();
22
const frisby = require("frisby");
3-
const { createTokenTesting } = require("../../helpers/apiCreateToken");
3+
const { createTokenTesting } = require("../../helpers/apiCreateToken.helpers");
44
const Joi = frisby.Joi;
55

66
const BASE_URL = process.env.BASE_URL;
@@ -16,13 +16,12 @@ describe("✅ Prueba para la lista de usuarios", () => {
1616
},
1717
},
1818
})
19-
.get(`${BASE_URL}/lista-de-usuarios/Activo?correo=normal&rol=admin`)
19+
.get(`${BASE_URL}/users?status=Activo&correo=normal&rol=admin`)
2020
.then((res) => {
2121
// console.log("🔎 STATUS:", res.status);
2222
// console.log("🔎 RESPONSE:", res.json);
2323
expect([200, 400, 429, 500]).toContain(res.status);
2424
})
25-
.expect("header", "Content-Type", /application\/json/)
2625
.expect("jsonTypes", {
2726
success: Joi.boolean().required(),
2827
data: Joi.array().items(

src/__tests__/users/apiRegisterUser.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require("dotenv").config();
22
const frisby = require("frisby");
3-
const { createTokenTesting } = require("../../helpers/apiCreateToken");
3+
const { createTokenTesting } = require("../../helpers/apiCreateToken.helpers");
44

55
const BASE_URL = process.env.BASE_URL;
66

@@ -16,7 +16,7 @@ describe("✅ Prueba para registrar un usuario", () => {
1616
},
1717
},
1818
})
19-
.post(`${BASE_URL}/registrar-usuario`, {
19+
.post(`${BASE_URL}/users/auth/register`, {
2020
nameUser: "apiTESTRegister",
2121
email: uniqueEmail,
2222
password: "123456788u02kljfLK",

src/__tests__/users/apiSearchUser.test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require("dotenv").config();
22
const frisby = require("frisby");
3-
const { createTokenTesting } = require("../../helpers/apiCreateToken");
3+
const { createTokenTesting } = require("../../helpers/apiCreateToken.helpers");
44
const Joi = frisby.Joi;
55

66
const BASE_URL = process.env.BASE_URL;
@@ -16,13 +16,12 @@ describe("✅ Prueba para buscar un usuario", () => {
1616
},
1717
},
1818
})
19-
.get(`${BASE_URL}/busqueda-usuario/muke`)
19+
.get(`${BASE_URL}/users/search?email=muke7881@gmail.com`)
2020
.then((res) => {
2121
// console.log("🔎 STATUS:", res.status);
2222
// console.log("🔎 RESPONSE:", res.json);
2323
expect([200, 400, 429, 500]).toContain(res.status);
2424
})
25-
.expect("header", "Content-Type", /application\/json/)
2625
.expect("jsonTypes", {
2726
success: Joi.boolean().required(),
2827
data: Joi.array().items(

0 commit comments

Comments
 (0)