refactor: deduplicate AI feedback SQL queries (#188)#211
Conversation
…ctions - Route now calls getFeedbackStats / getFeedbackTrend / getRecentFeedback from the aiFeedback module; no inline SQL remains in the route handler - Add 503 guard (req.app.locals.dbPool) back to both /stats and /recent handlers so DB-unavailable responses are explicit - Update route tests to mock the aiFeedback module functions directly instead of mocking pool.query — decouples route tests from DB schema - All 24 ai-feedback tests (route + module) now pass Closes #188
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, 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 the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (2)
✨ Finishing Touches🧪 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.
Pull request overview
This PR refactors the AI feedback API route to rely exclusively on the aiFeedback module (removing duplicated SQL concerns from the route layer), restores the DB-unavailable (503) guard, and updates route tests to mock module functions instead of mocking pool.query directly.
Changes:
- Restored
503 Database unavailableguard to both/statsand/recentroute handlers. - Ensured the route delegates to
getFeedbackStats,getFeedbackTrend, andgetRecentFeedbackand usesnext(err)for error propagation. - Updated route tests to mock
src/modules/aiFeedback.jsand assert correct module call arguments.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/api/routes/ai-feedback.js | Adds back the 503 DB-unavailable guard for /stats and /recent while keeping handlers delegated to module functions. |
| tests/api/routes/ai-feedback.test.js | Refactors tests to mock aiFeedback module functions and validate handler-module integration (args, defaults, query params). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
| Filename | Overview |
|---|---|
| src/api/routes/ai-feedback.js | Restored 503 DB-unavailable guards to both endpoints; duplicate checks should be consolidated |
| tests/api/routes/ai-feedback.test.js | Refactored to mock module functions instead of pool.query; test assertions should verify pool parameter |
Last reviewed commit: 56a26ed
Summary
Fixes #188.
The AI feedback API route was implemented (in #190) calling module functions, but the route tests were never updated — they still mocked
pool.querydirectly, causing 10 test failures. The route also lost its 503 DB-unavailable guard during the refactor.Changes
src/api/routes/ai-feedback.jsreq.app.locals.dbPoolcheck) to both/statsand/recenthandlersgetFeedbackStats,getFeedbackTrend,getRecentFeedbackfromaiFeedback.jsnext(err)(Express error middleware)tests/api/routes/ai-feedback.test.jspool.querymocks withvi.mock('../../../src/modules/aiFeedback.js')getFeedbackTrend(guildId, 7)for?days=7)Test Results
redis.test.jsandtriage.coverage.test.jsare unrelated to this PR