Repository navigation
Agregando unit test para filter-store-product y cambio en pagination.middleware - #71
Conversation
📝 WalkthroughWalkthroughLa PR centraliza constantes de paginación en un nuevo módulo y fortalece el middleware de paginación con validación más rigurosa. Ahora retorna errores HTTP 400 para parámetros inválidos en lugar de aplicar valores por defecto silenciosamente. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/unit/commerce/filter-store-product.test.js (1)
430-433: Evitá hardcodear100en el test de límite.Conviene leer
MAX_LIMITdesdesrc/utils/contants/pagination.contant.jspara no duplicar reglas y evitar drift cuando cambie la constante.♻️ Refactor sugerido
+import paginationConstants from "../../../src/utils/contants/pagination.contant.js"; +const { MAX_LIMIT } = paginationConstants; - it("devuelve 400 cuando limit supera 100", async () => { + it(`devuelve 400 cuando limit supera ${MAX_LIMIT}`, async () => { const res = await request(app).get( - "/api/commerces/products/filter/1?limit=200" + `/api/commerces/products/filter/1?limit=${MAX_LIMIT + 1}` );🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/unit/commerce/filter-store-product.test.js` around lines 430 - 433, Replace the hardcoded 100 in the test "devuelve 400 cuando limit supera 100" by importing MAX_LIMIT from src/utils/contants/pagination.contant.js and use it to build the request (e.g., request(...`?limit=${MAX_LIMIT + 1}`)). Update the assertion/description text if needed to avoid embedding the literal 100 and ensure the test still expects a 400 when limit > MAX_LIMIT; reference the constant name MAX_LIMIT and the test case name to locate where to change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tests/unit/commerce/filter-store-product.test.js`:
- Around line 258-263: Las aserciones actuales buscan b.AND arrays pero el
servicio construye objetos planos en where.OR; actualiza las comprobaciones en
tests/unit/commerce/filter-store-product.test.js para inspeccionar las
propiedades directas de cada rama en where.OR (p. ej. comprobar b.is_offer ===
false && b.price?.gte === 10 en lugar de b.AND?.some(...)) usando la misma
variable where y la extracción prisma.products.findMany.mock.calls[0][0].where;
aplica el mismo cambio a los bloques mencionados (las otras ubicaciones 275-280,
309-317, 329-334, 345-350) ajustando las condiciones para offer_price/price y
los valores esperados según cada caso.
---
Nitpick comments:
In `@tests/unit/commerce/filter-store-product.test.js`:
- Around line 430-433: Replace the hardcoded 100 in the test "devuelve 400
cuando limit supera 100" by importing MAX_LIMIT from
src/utils/contants/pagination.contant.js and use it to build the request (e.g.,
request(...`?limit=${MAX_LIMIT + 1}`)). Update the assertion/description text if
needed to avoid embedding the literal 100 and ensure the test still expects a
400 when limit > MAX_LIMIT; reference the constant name MAX_LIMIT and the test
case name to locate where to change.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ed17e32c-3658-4731-af15-0ab9b7031f84
📒 Files selected for processing (3)
src/middlewares/pagination.middleware.jssrc/utils/contants/pagination.contant.jstests/unit/commerce/filter-store-product.test.js
Summary by CodeRabbit
Notas de Lanzamiento
Bug Fixes
Tests