Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ echo "🔍 Validando mensaje de commit..."

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

Expand Down
29 changes: 10 additions & 19 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
#!/bin/sh

# Cargar NVM (necesario en entornos donde Husky no hereda el PATH completo)
export NVM_DIR="$HOME/.nvm"
# Esto carga nvm
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# Esto carga nvm para bash >=0.4.0
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"

echo "🔍 Verificando archivos antes del commit..."
echo "📦 Formateando código con Prettier..."

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

# Formatear código con Prettier
echo "🚀 Ejecutando Prettier..."
if ! yarn prettier . --write; then
echo "❌ Error al ejecutar Prettier."
exit 1
fi

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

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

echo "✅ Todo listo para el commit. 🎉"
echo "✅ Todo listo para el commit. 🎉"
16 changes: 16 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

#!/bin/sh

BRANCH=$(git symbolic-ref --short HEAD)

if [ "$BRANCH" = "staging" ]; then
echo "📍 Estás en la rama 'staging'. Ejecutando pruebas..."
echo "🧪 Ejecutando tests con servidor..."

if ! yarn test:with-server; then
echo "❌ Tests fallaron. Corrige los errores antes de hacer commit."
exit 1
fi
else
echo "🚫 No estás en la rama 'staging'. No se ejecutan los tests."
fi
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
"description": "Backend API for the project, using Node.js, Express, and MySQL.",
"main": "server.js",
"scripts": {
"start": "node server.js",
"dev": "node --watch server.js",
"format": "prettier . --write",
"start": "nodemon server.js",
"dev": "nodemon server.js",
"format": "prettier 'src/**/*.{js,ts,jsx,tsx,json}' server.js package.json --write",
"prepare": "husky",
"test": "jest",
"test:watch": "jest --watchAll"
"test:watch": "jest --watchAll",
"test:with-server": "concurrently --kill-others --success first \"yarn dev\" \"yarn test\""
},
"license": "MIT",
"type": "module",
Expand Down Expand Up @@ -51,11 +52,13 @@
"devDependencies": {
"@eslint/js": "^9.26.0",
"@faker-js/faker": "^9.7.0",
"concurrently": "^9.2.0",
"dotenv": "^16.5.0",
"eslint": "^9.26.0",
"frisby": "^2.1.3",
"globals": "^16.1.0",
"jest": "^29.7.0",
"nodemon": "^3.1.10",
"prettier": "^3.5.3"
}
}
10 changes: 5 additions & 5 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import morgan from "morgan";
import { createServer } from "node:http";

import { setupSwagger } from "./src/config/swaggerConfig.js";
import { corsOptions } from "./src/middleware/cors.js";
import { errorHandler } from "./src/middleware/errorHandler.js";
import { router } from "./src/router/index.js";
import { corsOptions } from "./src/middleware/cors.middleware.js";
import { errorHandler } from "./src/middleware/errorHandler.middleware.js";
import { router } from "./src/routes/index.js";

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

server.listen(currentPort, () => {
console.log(
`🟢 Server is listening on port localhost:${server.address().port}`,
`🟢 API funcionando correctamente, servidor corriendo en el puerto localhost:${server.address().port}`,
);
});
4 changes: 2 additions & 2 deletions src/__tests__/users/apiCreateUser.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require("dotenv").config();
const frisby = require("frisby");
const { createTokenTesting } = require("../../helpers/apiCreateToken");
const { createTokenTesting } = require("../../helpers/apiCreateToken.helpers");

const BASE_URL = process.env.BASE_URL;

Expand All @@ -16,7 +16,7 @@ describe("✅ Prueba para crear a un nuevo usuario", () => {
},
},
})
.post(`${BASE_URL}/crear-usuario`, {
.post(`${BASE_URL}/users`, {
nameUser: "apiTESTCreate",
email: uniqueEmail,
password: "123456788u02kljfLK",
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/users/apiDeleteUser.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require("dotenv").config();
const frisby = require("frisby");
const { createTokenTesting } = require("../../helpers/apiCreateToken");
const { createTokenTesting } = require("../../helpers/apiCreateToken.helpers");
const { randomUUID } = require("node:crypto");

const BASE_URL = process.env.BASE_URL;
Expand All @@ -17,7 +17,7 @@ describe("✅ Prueba para eliminar un usuario por su id", () => {
},
},
})
.del(`${BASE_URL}/eliminar-usuario/${id}`)
.del(`${BASE_URL}/users/${id}`)
.then((res) => {
// console.log("🔎 STATUS:", res.status);
// console.log("🔎 RESPONSE:", res.json);
Expand Down
5 changes: 2 additions & 3 deletions src/__tests__/users/apiListUsers.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require("dotenv").config();
const frisby = require("frisby");
const { createTokenTesting } = require("../../helpers/apiCreateToken");
const { createTokenTesting } = require("../../helpers/apiCreateToken.helpers");
const Joi = frisby.Joi;

const BASE_URL = process.env.BASE_URL;
Expand All @@ -16,13 +16,12 @@ describe("✅ Prueba para la lista de usuarios", () => {
},
},
})
.get(`${BASE_URL}/lista-de-usuarios/Activo?correo=normal&rol=admin`)
.get(`${BASE_URL}/users?status=Activo&correo=normal&rol=admin`)
.then((res) => {
// console.log("🔎 STATUS:", res.status);
// console.log("🔎 RESPONSE:", res.json);
expect([200, 400, 429, 500]).toContain(res.status);
})
.expect("header", "Content-Type", /application\/json/)
.expect("jsonTypes", {
success: Joi.boolean().required(),
data: Joi.array().items(
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/users/apiRegisterUser.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require("dotenv").config();
const frisby = require("frisby");
const { createTokenTesting } = require("../../helpers/apiCreateToken");
const { createTokenTesting } = require("../../helpers/apiCreateToken.helpers");

const BASE_URL = process.env.BASE_URL;

Expand All @@ -16,7 +16,7 @@ describe("✅ Prueba para registrar un usuario", () => {
},
},
})
.post(`${BASE_URL}/registrar-usuario`, {
.post(`${BASE_URL}/users/auth/register`, {
nameUser: "apiTESTRegister",
email: uniqueEmail,
password: "123456788u02kljfLK",
Expand Down
5 changes: 2 additions & 3 deletions src/__tests__/users/apiSearchUser.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require("dotenv").config();
const frisby = require("frisby");
const { createTokenTesting } = require("../../helpers/apiCreateToken");
const { createTokenTesting } = require("../../helpers/apiCreateToken.helpers");
const Joi = frisby.Joi;

const BASE_URL = process.env.BASE_URL;
Expand All @@ -16,13 +16,12 @@ describe("✅ Prueba para buscar un usuario", () => {
},
},
})
.get(`${BASE_URL}/busqueda-usuario/muke`)
.get(`${BASE_URL}/users/[email protected]`)
.then((res) => {
// console.log("🔎 STATUS:", res.status);
// console.log("🔎 RESPONSE:", res.json);
expect([200, 400, 429, 500]).toContain(res.status);
})
.expect("header", "Content-Type", /application\/json/)
.expect("jsonTypes", {
success: Joi.boolean().required(),
data: Joi.array().items(
Expand Down
5 changes: 2 additions & 3 deletions src/__tests__/users/apiUpdateUser.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require("dotenv").config();
const frisby = require("frisby");
const { createTokenTesting } = require("../../helpers/apiCreateToken");
const { createTokenTesting } = require("../../helpers/apiCreateToken.helpers");

const BASE_URL = process.env.BASE_URL;

Expand All @@ -16,13 +16,12 @@ describe("✅ Prueba para actualizar un usuario", () => {
},
},
})
.put(`${BASE_URL}/actualizar-usuario`, {
.put(`${BASE_URL}/users/4901398e-2672-11f0-b8d7-d843ae0db894`, {
nameUser: "Roberta_Rath-Hoppe-Furth",
email: uniqueEmail,
password: "129sdnKLMF@asfd11",
role: "user",
accountStatus: "Inactivo",
id: "1aa52951-2f05-11f0-9a7d-d843ae0db894",
})
.then((res) => {
// console.log("🔎 STATUS:", res.status);
Expand Down
2 changes: 1 addition & 1 deletion src/config/swaggerConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const swaggerDefinition = {

const options = {
swaggerDefinition,
apis: [resolve(__dirname, "../router/*.js")],
apis: [resolve(__dirname, "../routes/*.js")],
};

export const swaggerDocument = swaggerJsdoc(options);
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/catAssetsControllers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { connectionQuery } from "../helpers/connection.helper.js";
import { connectionQuery } from "../helpers/connection.helpers.js";
import {
methodCreated,
methodError,
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/catInventarioControllers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { connectionQuery } from "../helpers/connection.helper.js";
import { connectionQuery } from "../helpers/connection.helpers.js";
import {
methodCreated,
methodError,
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/catSuppliesControllers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { connectionQuery } from "../helpers/connection.helper.js";
import { connectionQuery } from "../helpers/connection.helpers.js";
import {
methodCreated,
methodError,
Expand Down
Loading
Loading