Skip to content

fix: add unit tests for bulk approval confirmation and submission ris…#356

Merged
Producdevity merged 2 commits into
stagingfrom
fix/risk-warning-severity
May 19, 2026
Merged

fix: add unit tests for bulk approval confirmation and submission ris…#356
Producdevity merged 2 commits into
stagingfrom
fix/risk-warning-severity

Conversation

@Producdevity

@Producdevity Producdevity commented May 19, 2026

Copy link
Copy Markdown
Owner

Description

add unit tests for bulk approval confirmation and submission risk service logic

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Refactor
  • Other (please describe):

How Has This Been Tested?

  • Local build
  • Lint
  • Typecheck
  • Unit tests
  • Manual testing

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have made corresponding changes to the documentation
  • I have checked that all checks (lint, typecheck, test) pass

Summary by CodeRabbit

  • New Features

    • Bulk approval confirmation now considers both author and submission risk profiles and surfaces the computed highest severity in warnings.
  • Bug Fixes

    • Adjusted submission risk logic so placeholder-version severity is treated as high when appropriate (no author profile, no approvals, or presence of new-author signals).
  • Tests

    • Added tests covering bulk approval warnings across risk combinations and submission risk computation for placeholder versions.

Review Change Stack

@vercel

vercel Bot commented May 19, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
emuready Ready Ready Preview, Comment May 19, 2026 8:07am

Request Review

@coderabbitai

coderabbitai Bot commented May 19, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8ceeef9c-9ff9-426e-a9d9-5b43f59a5399

📥 Commits

Reviewing files that changed from the base of the PR and between 2b8c93b and 4603982.

📒 Files selected for processing (2)
  • src/app/admin/utils/bulkApprovalConfirmation.test.ts
  • src/app/admin/utils/bulkApprovalConfirmation.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/app/admin/utils/bulkApprovalConfirmation.ts

Walkthrough

This PR adds submission risk profile evaluation to the bulk approval confirmation flow, centralizes a shared Severity type and SEVERITY_ORDER, implements getHighestRiskSeverity to pick the max severity across author and submission profiles, updates the confirmation warning to use that severity and risk count, and refines server-side new-author detection to flag any NEW_AUTHOR signal.

Changes

Risk Profile Evaluation for Bulk Approval

Layer / File(s) Summary
Risk type contract and severity ordering
src/app/admin/utils/bulkApprovalConfirmation.ts
Introduces RiskProfileSummary with Severity-typed highestSeverity, central SEVERITY_ORDER, updates ListingWithRiskProfile to include submissionRiskProfile, and defines ConfirmFn.
Client helper to compute highest risk
src/app/admin/utils/bulkApprovalConfirmation.ts
Adds getHighestRiskSeverity(listing) that returns the maximum Severity across submissionRiskProfile and authorRiskProfile.
Bulk approval warning logic
src/app/admin/utils/bulkApprovalConfirmation.ts
Updates confirmBulkApproval to mark listings risky when getHighestRiskSeverity is non-null, compute overall highest severity among risky selections, and interpolate the risk count and highest severity in the warning description.
Client-side confirmation tests
src/app/admin/utils/bulkApprovalConfirmation.test.ts
Adds Vitest cases covering: warning path when submission risk exists, severity selection between author/submission profiles, using selected listing count in the description, and normal confirmation title when severities are null or profiles are absent.
Server new-author risk detection
src/server/services/submission-risk.service.ts
Adds hasNewAuthorRisk helper that detects any NEW_AUTHOR signal in an author profile.
Placeholder version severity logic
src/server/services/submission-risk.service.ts
Updates getPlaceholderVersionSeverity to return 'high' when there is no author profile, approvedListings === 0, or hasNewAuthorRisk(authorRiskProfile) is true.
Server-side risk tests
src/server/services/submission-risk.service.test.ts
Adds a test ensuring placeholder-like emulator versions retain 'high' severity for new-author signals even with previously rejected listings and that highestSeverity is 'high'.

🎯 3 (Moderate) | ⏱️ ~20 minutes

🐰 A rabbit hops through the risk matrix,
Submission profiles dance with author metrics,
Severity sorted, warnings bright,
Approval confirmations get the insight! 🌟

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is partially related to the changeset—it mentions adding unit tests for bulk approval confirmation and submission risk, which are real components being tested, but it is truncated ('ris…') and doesn't capture the full scope of changes including logic updates to risk evaluation and helper functions. Complete the title to clarify the full scope: e.g., 'fix: add unit tests and improve risk severity evaluation for bulk approval' to better reflect both test additions and the underlying logic changes.
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The pull request description follows the template structure and provides all required sections including type of change (Bug fix), testing verification (all boxes checked), and checklist completion, though it lacks specific issue references and details about the fixes themselves.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/risk-warning-severity

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/app/admin/utils/bulkApprovalConfirmation.ts

Oops! 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:

npm install eslint-plugin-react-hooks@latest --save-dev

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.ts

Oops! 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:

npm install eslint-plugin-react-hooks@latest --save-dev

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/app/admin/utils/bulkApprovalConfirmation.ts (1)

38-39: ⚡ Quick win

Use a Set for selected ID lookups to avoid quadratic filtering.

selectedIds.includes(...) inside allListings.filter(...) scales poorly for larger bulk actions. Build a Set once 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

📥 Commits

Reviewing files that changed from the base of the PR and between fb5b9f0 and 2b8c93b.

📒 Files selected for processing (4)
  • src/app/admin/utils/bulkApprovalConfirmation.test.ts
  • src/app/admin/utils/bulkApprovalConfirmation.ts
  • src/server/services/submission-risk.service.test.ts
  • src/server/services/submission-risk.service.ts

Comment thread src/app/admin/utils/bulkApprovalConfirmation.ts Outdated
@Producdevity Producdevity merged commit 5852ab4 into staging May 19, 2026
8 checks passed
@Producdevity Producdevity deleted the fix/risk-warning-severity branch May 19, 2026 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant