chore: add unit tests for utils#183
Conversation
✅ Deploy Preview for agentscan ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (6)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughWalkthroughThree production utility files receive small targeted fixes: ChangesUtility Fixes, Exports, and Unit Test Additions
Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 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 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 |
✅ Organic activityNo automation signals detected in the analyzed events. This is an automated analysis by AgentScan |
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 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 `@server/utils/format-username.ts`:
- Line 2: The decodeURIComponent call in the return statement lacks error
handling and will crash when processing malformed URI input with invalid
percent-encoding sequences. Wrap the decodeURIComponent call in a try-catch
block to safely handle URIError exceptions, and provide a fallback that uses the
original username parameter when decoding fails, ensuring the function returns a
valid formatted username string even with invalid input.
In `@test/unit/server/utils/format-username.test.ts`:
- Around line 4-36: Add a new test case to the formatUsername test suite that
verifies the function handles malformed URL-encoded input without throwing an
error. Include a test case like "handles malformed percent-encoding" that calls
formatUsername with invalid percent-encoding (such as a string with incomplete
or invalid percent sequences) and asserts that it does not throw an exception,
ensuring the utility is resilient to malformed user input.
In `@test/unit/shared/utils/charts.test.ts`:
- Around line 58-67: The current test validation using arrayContaining with
mapped matchers does not reliably validate every element in the result array.
Replace this approach by using forEach to iterate through each element in the
result array and explicitly validate that each element contains the required
properties (name as String and value as Number). This ensures all elements meet
the validation criteria rather than just checking for the presence of matching
elements.
In `@test/unit/shared/utils/count-classification-by-date.test.ts`:
- Around line 15-30: The forEach callback iterates over Object.values(result)
but ignores the iterated value and creates unused expect.objectContaining
matchers that are never evaluated. Fix this by accepting the iterated value as a
parameter in the forEach callback and passing it to an expect assertion. Call
expect() on the iterated value and chain it with toMatchObject() or toEqual(),
using the objectContaining structure to validate that each result value matches
the expected schema with organic, mixed, and automation properties each
containing count and trend number fields.
In `@test/unit/shared/utils/health-stats.test.ts`:
- Around line 29-34: The forEach loop in the test is not asserting anything
against each item - the loop parameter is unused and expect.objectContaining is
called without being part of an expect assertion. Update the forEach loop to
capture each item as a parameter, then use that parameter to assert the item's
shape by calling expect on it with .toEqual(expect.objectContaining({...})) to
properly enforce the contract that each value contains count as a Number and
percentage as a String.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: 13e5cebf-bcad-4366-a575-3ce86186a814
📒 Files selected for processing (10)
server/utils/format-username.tsshared/utils/charts.tsshared/utils/health-stats.tstest/unit/app/utils/colors.test.tstest/unit/mocks/ecosystemHealthItems.tstest/unit/server/utils/format-username.test.tstest/unit/shared/utils/calc-linear-progression.test.tstest/unit/shared/utils/charts.test.tstest/unit/shared/utils/count-classification-by-date.test.tstest/unit/shared/utils/health-stats.test.ts

This adds unit tests for utils (#166)
Adding tests revealed a few small bugs for the
server/utils/format-usernameutil:Summary by CodeRabbit
Summary by CodeRabbit
Bug Fixes
Improvements
Tests