test: add vitest and unit tests for sortCrewPriority#2741
test: add vitest and unit tests for sortCrewPriority#2741dougrathbone wants to merge 2 commits intoseerr-team:developfrom
Conversation
The sort comparator used findIndex with a substring predicate (job.includes(a.job)) to locate each job's rank. Since the preceding filter already guarantees every crew member's job is an exact member of priorityJobs, indexOf is correct and simpler. The substring approach is fragile: if a shorter title were ever added earlier in the list (e.g. "Pro" before "Producer"), the substring match would silently return the wrong index and mis-rank those crew members.
This introduces vitest as a unit testing framework. The project currently has no unit tests, only Cypress e2e. Vitest is lightweight, TypeScript-native, and compatible with the existing Jest-style ESLint env already configured in .eslintrc.js -- adding it is an opinionated choice but keeps the barrier to entry low for future test coverage. vitest.config.ts wires up the @app and @server path aliases so tests can import with the same convention used across the rest of the codebase. The initial test suite covers sortCrewPriority: filtering non-priority crew, empty input, sort ordering across all priority jobs, multiple crew members sharing the same job, and the independent ranking of Producer, Co-Producer, and Executive Producer.
|
This pull request has merge conflicts. Please resolve the conflicts so the PR can be successfully reviewed and merged. |
📝 WalkthroughWalkthroughThe PR establishes a Vitest testing framework by adding configuration files, a test script to package.json, and a comprehensive test suite for the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Important Merge conflicts detected (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 Tip You can customize the high-level summary generated by CodeRabbit.Configure the |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/utils/__tests__/creditHelpers.test.ts (1)
64-76: Add one regression test for substring-like titles.Given the comparator fix, it’s worth explicitly asserting that partial titles like
"Associate Producer"are excluded.Proposed test addition
describe('sortCrewPriority', () => { @@ it('correctly ranks Producer, Co-Producer, and Executive Producer independently', () => { @@ expect(result.map((c) => c.job)).toEqual([ 'Producer', 'Co-Producer', 'Executive Producer', ]); }); + + it('does not match partial producer titles', () => { + const crew = [makeCrew('Associate Producer'), makeCrew('Producer')]; + const result = sortCrewPriority(crew); + expect(result.map((c) => c.job)).toEqual(['Producer']); + }); });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/utils/__tests__/creditHelpers.test.ts` around lines 64 - 76, Add a regression test in src/utils/__tests__/creditHelpers.test.ts that uses makeCrew and sortCrewPriority to assert that substring-like titles (e.g., "Associate Producer") do not get matched as "Producer": create a crew array including "Associate Producer" alongside "Producer", "Co-Producer", and "Executive Producer", call sortCrewPriority, and expect the ordering/outputs to treat "Associate Producer" separately (i.e., not rank it as "Producer"); reference the existing test patterns and functions sortCrewPriority and makeCrew to mirror style and assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/utils/__tests__/creditHelpers.test.ts`:
- Around line 64-76: Add a regression test in
src/utils/__tests__/creditHelpers.test.ts that uses makeCrew and
sortCrewPriority to assert that substring-like titles (e.g., "Associate
Producer") do not get matched as "Producer": create a crew array including
"Associate Producer" alongside "Producer", "Co-Producer", and "Executive
Producer", call sortCrewPriority, and expect the ordering/outputs to treat
"Associate Producer" separately (i.e., not rank it as "Producer"); reference the
existing test patterns and functions sortCrewPriority and makeCrew to mirror
style and assertions.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d8074fd7-876e-4011-bf1f-e7371ee1db97
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (4)
package.jsonsrc/utils/__tests__/creditHelpers.test.tssrc/utils/creditHelpers.tsvitest.config.ts
|
We already have server-side unit testing setup since a while ago though... |
|
Dropping this in favour of rewriting tests with node:test to align with the project test framework, added to the fix PR instead. @fallenbagel - thanks for the shout out. I missed the tests entirely somehow... thanks for your patience! |
Description
This PR introduces vitest as a unit testing framework and adds an initial test suite for
sortCrewPriority. The project currently has no unit tests -- only Cypress e2e. Vitest is lightweight, TypeScript-native, and compatible with the Jest-style ESLint env already configured in.eslintrc.js, keeping the barrier to entry low for future test coverage.vitest.config.tswires up the@appand@serverpath aliases so tests can import using the same convention used across the rest of the codebase.The test suite covers:
Producer,Co-Producer, andExecutive ProducerDepends on #2740.
How Has This Been Tested?
pnpm test-- all 6 tests pass. Lint and format checks pass.Screenshots / Logs (if applicable)
Checklist:
pnpm buildpnpm i18n:extractAI was used for code completion. All testing and interaction with the codebase was done manually.
Summary by CodeRabbit
Bug Fixes
Tests