Skip to content

Commit 85dd8ff

Browse files
committed
test(users): Creacion y prueba de testeo en api de usuarios
1 parent e4f289c commit 85dd8ff

10 files changed

Lines changed: 158 additions & 24 deletions

.husky/pre-commit

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,10 @@ echo "🔍 Verificando archivos antes del commit..."
1111
echo "📦 Formateando código con Prettier..."
1212

1313
yarn prettier 'src/**/*.{js,ts,jsx,tsx,json}' server.js package.json --write || exit 1
14+
15+
16+
# Agregar los archivos modificados después del formateo
17+
git add .
18+
19+
20+
echo "✅ Todo listo para el commit. 🎉"

.husky/pre_push renamed to .husky/pre-push

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
12
#!/bin/sh
23

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

56
if [ "$BRANCH" = "staging" ]; then
67
echo "📍 Estás en la rama 'staging'. Ejecutando pruebas..."
7-
echo "🧪 Ejecutando tests..."
8+
echo "🧪 Ejecutando tests con servidor..."
89

9-
if ! npm test; then
10+
if ! yarn test:with-server; then
1011
echo "❌ Tests fallaron. Corrige los errores antes de hacer commit."
1112
exit 1
1213
fi

package.json

Lines changed: 6 additions & 3 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",
7+
"start": "nodemon server.js",
8+
"dev": "nodemon server.js",
99
"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
}

src/__tests__/users/apiCreateUser.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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(

src/__tests__/users/apiUpdateUser.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@ describe("✅ Prueba para actualizar un usuario", () => {
1616
},
1717
},
1818
})
19-
.put(`${BASE_URL}/actualizar-usuario`, {
19+
.put(`${BASE_URL}/users/4901398e-2672-11f0-b8d7-d843ae0db894`, {
2020
nameUser: "Roberta_Rath-Hoppe-Furth",
2121
email: uniqueEmail,
2222
password: "129sdnKLMF@asfd11",
2323
role: "user",
2424
accountStatus: "Inactivo",
25-
id: "1aa52951-2f05-11f0-9a7d-d843ae0db894",
2625
})
2726
.then((res) => {
2827
// console.log("🔎 STATUS:", res.status);

0 commit comments

Comments
 (0)