fix: add unit tests for bulk approval confirmation and submission ris…#356
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThis PR adds submission risk profile evaluation to the bulk approval confirmation flow, centralizes a shared ChangesRisk Profile Evaluation for Bulk Approval
🎯 3 (Moderate) | ⏱️ ~20 minutes
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ 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)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
src/app/admin/utils/bulkApprovalConfirmation.tsOops! Something went wrong! :( ESLint: 9.29.0 ESLint couldn't find the plugin "eslint-plugin-react-hooks". (The package "eslint-plugin-react-hooks" was not found when loaded as a Node module from the directory "".) It's likely that the plugin isn't installed correctly. Try reinstalling by running the following: The plugin "eslint-plugin-react-hooks" was referenced from the config file in " » eslint-config-next/core-web-vitals » /node_modules/.pnpm/eslint-config-next@15.5.18_eslint@9.29.0_jiti@2.4.2__typescript@5.8.3/node_modules/eslint-config-next/index.js". If you still can't figure out the problem, please see https://eslint.org/docs/latest/use/troubleshooting. src/app/admin/utils/bulkApprovalConfirmation.test.tsOops! Something went wrong! :( ESLint: 9.29.0 ESLint couldn't find the plugin "eslint-plugin-react-hooks". (The package "eslint-plugin-react-hooks" was not found when loaded as a Node module from the directory "".) It's likely that the plugin isn't installed correctly. Try reinstalling by running the following: The plugin "eslint-plugin-react-hooks" was referenced from the config file in " » eslint-config-next/core-web-vitals » /node_modules/.pnpm/eslint-config-next@15.5.18_eslint@9.29.0_jiti@2.4.2__typescript@5.8.3/node_modules/eslint-config-next/index.js". If you still can't figure out the problem, please see https://eslint.org/docs/latest/use/troubleshooting. 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)
src/app/admin/utils/bulkApprovalConfirmation.ts (1)
38-39: ⚡ Quick winUse a
Setfor selected ID lookups to avoid quadratic filtering.
selectedIds.includes(...)insideallListings.filter(...)scales poorly for larger bulk actions. Build aSetonce and use.has(...).♻️ Proposed change
- const selectedListings = allListings.filter((listing) => selectedIds.includes(listing.id)) + const selectedIdSet = new Set(selectedIds) + const selectedListings = allListings.filter((listing) => selectedIdSet.has(listing.id))🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/app/admin/utils/bulkApprovalConfirmation.ts` around lines 38 - 39, The current filtering uses selectedIds.includes(...) causing O(n*m) behavior; create a Set from selectedIds once (e.g., const selectedIdSet = new Set(selectedIds)) and then replace the filters that reference selectedIds to use selectedIdSet.has(listing.id) when creating selectedListings and any subsequent filters (such as the riskyListings computation which derives from selectedListings and getHighestRiskSeverity) to make lookups O(1).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/app/admin/utils/bulkApprovalConfirmation.ts`:
- Line 52: The confirmation message uses selectedIds.length which can overstate
approvals when some IDs are stale; update the template in
bulkApprovalConfirmation (the description string that references entityLabel,
riskyListings, highestRisk, riskyAuthors) to use selectedListings.length instead
of selectedIds.length so the user-facing warning reflects the filtered/actual
selection count.
---
Nitpick comments:
In `@src/app/admin/utils/bulkApprovalConfirmation.ts`:
- Around line 38-39: The current filtering uses selectedIds.includes(...)
causing O(n*m) behavior; create a Set from selectedIds once (e.g., const
selectedIdSet = new Set(selectedIds)) and then replace the filters that
reference selectedIds to use selectedIdSet.has(listing.id) when creating
selectedListings and any subsequent filters (such as the riskyListings
computation which derives from selectedListings and getHighestRiskSeverity) to
make lookups O(1).
🪄 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: 083af835-5d95-461e-9603-60ca795fcbe9
📒 Files selected for processing (4)
src/app/admin/utils/bulkApprovalConfirmation.test.tssrc/app/admin/utils/bulkApprovalConfirmation.tssrc/server/services/submission-risk.service.test.tssrc/server/services/submission-risk.service.ts
… add test coverage
Description
add unit tests for bulk approval confirmation and submission risk service logic
Type of change
How Has This Been Tested?
Checklist
Summary by CodeRabbit
New Features
Bug Fixes
Tests