fix: harden product service price filters#147
Conversation
|
Warning Review limit reached
Your plan currently allows 2 reviews/hour. Refill in 26 minutes and 31 seconds. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more review capacity refills, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
There was a problem hiding this comment.
Pull request overview
This PR hardens productService.fetchProducts client-side filtering by ensuring price bounds and product prices are finite numbers before performing comparisons, and updates the corresponding unit tests to use typed Vitest mocks.
Changes:
- Normalize
minPrice/maxPricevia finite-number checks and only apply filters when bounds are finite. - Avoid direct comparisons against non-finite mapped product prices by validating
p.pricebefore comparing. - Refactor category filtering to remove the non-null assertion and add a test asserting invalid price bounds don’t filter out products.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/services/productService.ts |
Adds getFiniteNumber and applies finite checks for category and price filtering logic. |
src/services/__tests__/productService.test.ts |
Switches to vi.mocked for typed mocks and adds coverage for invalid price bounds behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| it('should apply search filter', async () => { | ||
| await productService.fetchProducts({ search: 'caneca' }); | ||
| expect(externalDb.fetchPromobrindProducts).toHaveBeenCalledWith(expect.objectContaining({ | ||
| search: 'caneca' | ||
| })); | ||
| expect(externalDb.fetchPromobrindProducts).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| search: 'caneca', | ||
| }), | ||
| ); | ||
| }); |
Summary
Validation
npx.cmd eslint src/services/productService.ts src/services/__tests__/productService.test.tsnpx.cmd vitest run src/services/__tests__/productService.test.tsgit diff --checkVITE_SUPABASE_URL=... VITE_SUPABASE_PUBLISHABLE_KEY=... npm.cmd run buildNotes
npm.cmd run typecheck:full -- --pretty falsedid not complete locally after 5 minutes and produced no diagnostic output. The focused lint/test suite and production build passed.Summary by cubic
Fixes price filtering to ignore NaN/Infinity bounds and non-finite product prices so valid items aren’t dropped. Also normalizes category filtering and updates tests with typed
vitestmocks.vi.mockedand add coverage to ensure invalid price bounds are ignored.Written for commit a748857. Summary will update on new commits. Review in cubic