Skip to content

test: add vitest and unit tests for sortCrewPriority#2741

Closed
dougrathbone wants to merge 2 commits intoseerr-team:developfrom
dougrathbone:dougrathbone/test/credit-helpers-sort
Closed

test: add vitest and unit tests for sortCrewPriority#2741
dougrathbone wants to merge 2 commits intoseerr-team:developfrom
dougrathbone:dougrathbone/test/credit-helpers-sort

Conversation

@dougrathbone
Copy link
Copy Markdown
Contributor

@dougrathbone dougrathbone commented Mar 22, 2026

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.ts wires up the @app and @server path aliases so tests can import using the same convention used across the rest of the codebase.

The test suite covers:

  • Filtering out crew members whose jobs are not in the priority list
  • Empty input
  • Correct sort ordering across all priority jobs
  • Multiple crew members sharing the same job
  • Independent ranking of Producer, Co-Producer, and Executive Producer

Depends on #2740.

How Has This Been Tested?

pnpm test -- all 6 tests pass. Lint and format checks pass.

Screenshots / Logs (if applicable)

 PASS  src/utils/__tests__/creditHelpers.test.ts (6 tests) 2ms
 Test Files  1 passed (1)
      Tests  6 passed (6)

Checklist:

  • I have read and followed the contribution guidelines.
  • Disclosed any use of AI (see our policy)
  • I have updated the documentation accordingly.
  • All new and existing tests passed.
  • Successful build pnpm build
  • Translation keys pnpm i18n:extract
  • Database migration (if required)

AI was used for code completion. All testing and interaction with the codebase was done manually.

Summary by CodeRabbit

  • Bug Fixes

    • Improved crew member sorting accuracy by using exact job matching instead of substring-based matching.
  • Tests

    • Added comprehensive test suite for crew sorting functionality with multiple test cases covering filtering, priority ordering, and edge cases.

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.
@dougrathbone dougrathbone requested a review from a team as a code owner March 22, 2026 00:55
@github-actions github-actions bot added the merge conflict Cannot merge due to merge conflicts label Mar 22, 2026
@github-actions
Copy link
Copy Markdown

This pull request has merge conflicts. Please resolve the conflicts so the PR can be successfully reviewed and merged.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 22, 2026

📝 Walkthrough

Walkthrough

The PR establishes a Vitest testing framework by adding configuration files, a test script to package.json, and a comprehensive test suite for the sortCrewPriority function. The function logic was updated to use exact job matching instead of substring matching for priority calculations.

Changes

Cohort / File(s) Summary
Test Configuration Setup
package.json, vitest.config.ts
Added test script running vitest run and vitest@^2.1.0 to devDependencies. New Vitest config establishes module aliases (@appsrc, @serverserver), sets test environment to node, and enables global APIs.
Test Suite
src/utils/__tests__/creditHelpers.test.ts
New test suite for sortCrewPriority verifying filter behavior (removes unmatched jobs, handles empty inputs), sort ordering across priority levels (Director, Writer, Composer, Producer, Executive Producer), and grouped handling of same-job crew members.
Function Enhancement
src/utils/creditHelpers.ts
Updated sortCrewPriority to use indexOf() for exact job matching instead of findIndex() with substring-based lookup via includes() for score calculation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A testing warren, freshly dug deep,
Vitest guards where code does sleep,
Crew priority sorted, precise and right,
No substrings sneaking in the night! ✨

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding Vitest testing infrastructure and unit tests for the sortCrewPriority function, which directly aligns with the changeset.

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

Important

Merge conflicts detected (Beta)

  • Resolve merge conflict in branch dougrathbone/test/credit-helpers-sort

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.

Tip

You can customize the high-level summary generated by CodeRabbit.

Configure the reviews.high_level_summary_instructions setting to provide custom instructions for generating the high-level summary.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 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

📥 Commits

Reviewing files that changed from the base of the PR and between dbe1fca and d824976.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (4)
  • package.json
  • src/utils/__tests__/creditHelpers.test.ts
  • src/utils/creditHelpers.ts
  • vitest.config.ts

@fallenbagel
Copy link
Copy Markdown
Collaborator

fallenbagel commented Mar 22, 2026

#2485

We already have server-side unit testing setup since a while ago though...

@dougrathbone
Copy link
Copy Markdown
Contributor Author

dougrathbone commented Mar 22, 2026

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge conflict Cannot merge due to merge conflicts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants