brackt/app/routes/leagues/__tests__
Chris Parsons 4bffa40606
Fix oxlint warnings: no-shadow, consistent-function-scoping, no-non-null-assertion, and others (#196)
* Fix no-shadow and consistent-function-scoping lint violations

Resolves all 11 no-shadow and 16 consistent-function-scoping oxlint
warnings and promotes both rules to errors in .oxlintrc.json.

no-shadow: renamed Drizzle callback params (sports→s, matches→m,
seasons→s) to avoid shadowing outer imports; removed shadowed
destructures (eq, inArray) from where callbacks; renamed inner
template→bracketTemplate, prev→currentTimers, season→ss, name→teamName
(with name: teamName fix to preserve semantics).

consistent-function-scoping: moved formatDate, getRankBadge,
getMovementIndicator, getPositionBadge, getStatusBadge, toDateStr,
elo (×2), weightedPick, sortByMatchNumber (×2) to module scope;
moved formatTime (×2), isValidLeagueName, getDraftTimes,
makeSeasonQueues to file scope in test files.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Fix no-non-null-assertion lint violations and promote to error

Eliminates all 208 no-non-null-assertion warnings across 38 files.
Promotes typescript/no-non-null-assertion from warn to error in
.oxlintrc.json.

Fix patterns applied:
- Map.get(key)! after .has() check → extract with get() + null guard
- Map.get(key)! on pre-populated count maps → ?? 0 default
- .set(id, map.get(id)! + 1) increment → ?? 0 before adding
- participant1Id!/participant2Id! on DB matches → ?? "" fallback
- array.find()! in tests → guard + throw or expect().toBeDefined()
- bracketTemplateCache.get(id)! → null guard extract
- Various nullable field accesses → optional chain or ?? default

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Fix prefer-add-event-listener, no-unassigned-import, require-module-specifiers

Resolves all 9 remaining non-console lint warnings and promotes all
three rules to errors in .oxlintrc.json.

- prefer-add-event-listener: converted onchange/onclick/onload
  assignments to addEventListener in useDraftNotifications.ts and
  admin.data-sync.tsx; stored changeHandler ref for proper cleanup
  with removeEventListener
- no-unassigned-import: configured rule with allow list for legitimate
  side-effect imports (*.css, @testing-library/jest-dom,
  @testing-library/cypress/add-commands)
- require-module-specifiers: removed redundant `export {}` from
  cypress/support/e2e.ts (file already has an import)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Fix TypeScript errors from no-non-null-assertion fixes

Two fixes introduced by the non-null assertion cleanup produced type
errors:

- scoring-event.ts: `?? ""` was wrong type for a participant object map;
  restructured to explicit null guards so TypeScript can narrow correctly
- standings-sync/index.ts: `?? null` after name-match lookup lost the
  truthy guarantee, causing TS18047 on the write-back block; added
  `participant &&` guard before accessing its properties

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Add npm run typecheck as Stop hook in Claude settings

Runs a full project typecheck at the end of each Claude turn so type
errors surface as feedback before the next message.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-21 10:59:51 -07:00
..
autodraft.test.ts feat: enhance autodraft functionality with detailed settings and commissioner controls (#61) 2026-03-03 20:14:38 -08:00
draft-board-access.test.ts Add oxlint linting setup with zero errors (#194) 2026-03-21 09:44:05 -07:00
draft-order-visibility.test.ts User/chris/bracket UI redesign (#95) 2026-03-09 22:44:33 -07:00
draft-reconnection-sync.test.ts Fix oxlint warnings: no-shadow, consistent-function-scoping, no-non-null-assertion, and others (#196) 2026-03-21 10:59:51 -07:00
draft-reset.test.ts Add standard draft clock mode (#67) (#189) 2026-03-20 21:36:39 -07:00
README.md feat: add admin draft reset functionality with queue and pick deletion 2025-10-21 22:34:26 -07:00
settings-update.test.ts Add oxlint linting setup with zero errors (#194) 2026-03-21 09:44:05 -07:00
team-management.test.ts feat: prevent users from owning multiple teams in same league 2025-10-21 22:27:14 -07:00

League Settings Integration Tests

Overview

This directory contains integration tests for league settings features. The tests are written using Vitest and cover the following functionality:

Team Management

  • Remove Team Owner: Commissioners can remove owners from teams
  • Assign Team Owner: Admins can assign users to teams via dropdown
  • Authorization: Proper access control for commissioners vs admins
  • Edge Cases: Handling invalid inputs and error scenarios
  • Integration Scenarios: Complete workflows and multi-team operations

Draft Reset

  • Admin-Only Access: Only admins can reset drafts
  • Delete Operations: Clearing picks and queues
  • Status Updates: Resetting season to pre_draft
  • Draft Order Preservation: Ensuring draft slots remain intact
  • Data Integrity: Maintaining referential integrity during reset

Test Structure

Test Files

  • team-management.test.ts - Team management feature tests
  • draft-reset.test.ts - Draft reset feature tests

Fixtures

  • app/test/fixtures/user.ts - Mock user data including admin and regular users
  • app/test/fixtures/team.ts - Mock team data
  • app/test/fixtures/league.ts - Mock league data

Running Tests

Run all tests

npm test

Run tests in watch mode

npm run dev:test

Run tests with UI

npm run test:ui

Run tests with coverage

npm run test:coverage

Run only team management tests

npm test team-management

Test Coverage

The test suite covers:

1. Remove Owner Functionality (4 tests)

  • Successfully remove an owner from a team
  • Handle errors when removal fails
  • Allow commissioners to remove owners
  • Verify proper database calls

2. Assign Owner Functionality (5 tests)

  • Successfully assign an owner to a team
  • Handle errors when assignment fails
  • Only allow admins to assign owners
  • Prevent non-admins from assigning owners
  • Replace existing owner when assigning new owner

3. Admin User List (3 tests)

  • Fetch all users for admin dropdown
  • Only fetch users when user is admin
  • Return empty array for non-admin users

4. Authorization (3 tests)

  • Verify admin status before allowing assignment
  • Reject assignment for non-admin users
  • Allow commissioners to remove owners regardless of admin status

5. Edge Cases (6 tests)

  • Prevent assigning user who already owns a team in the league
  • Handle removing owner from team with no owner
  • Handle assigning owner to team that already has owner
  • Handle invalid team ID gracefully
  • Handle invalid user clerk ID gracefully
  • Proper error messages

6. Integration Scenarios (3 tests)

  • Complete workflow: assign then remove owner
  • Reassigning owner from one user to another
  • Handle multiple teams with different ownership states

Total: 24 tests

Draft Reset Test Coverage

1. Authorization (3 tests)

  • Only allow admins to reset draft
  • Reject non-admin users from resetting draft
  • Reject commissioners who are not admins

2. Delete Operations (4 tests)

  • Delete all draft picks for a season
  • Clear all draft queues for a season
  • Handle errors when deleting draft picks fails
  • Handle errors when clearing queues fails

3. Season Status Update (2 tests)

  • Update season status to pre_draft
  • Handle errors when updating season status fails

4. Status Validation (4 tests)

  • Allow reset when season status is draft
  • Allow reset when season status is completed
  • Allow reset when season status is active
  • Not allow reset when season status is pre_draft

5. Complete Workflow (3 tests)

  • Execute complete reset workflow in correct order
  • Not proceed with reset if admin check fails
  • Handle partial failure gracefully

6. Draft Order Preservation (2 tests)

  • Not delete or modify draft slots during reset
  • Preserve draft order after reset

7. Edge Cases (4 tests)

  • Handle reset when no draft picks exist
  • Handle reset when no draft queues exist
  • Handle invalid season ID gracefully
  • Handle concurrent reset attempts

8. Data Integrity (2 tests)

  • Ensure all picks are deleted before updating status
  • Maintain referential integrity after reset

Total: 24 tests

Key Features Tested

Commissioner Capabilities

  • Remove owners from any team in their league
  • No ability to assign owners (admin-only)

Admin Capabilities

  • Remove owners from any team
  • Assign any user to any team via dropdown
  • Access to full user list for assignment
  • Reset draft (admin-only, not commissioners)
    • Delete all draft picks
    • Clear all draft queues
    • Reset season to pre_draft status
    • Preserve draft order

Security

  • Admin-only check enforced for assignments and draft resets
  • Commissioner access verified for removals
  • Proper error handling for unauthorized access
  • Status validation for draft reset operations

Mocking Strategy

The tests use Vitest's mocking capabilities to:

  • Mock database operations (removeTeamOwner, assignTeamOwner)
  • Mock user authentication (isUserAdminByClerkId)
  • Mock user data fetching (findAllUsers)
  • Simulate various success and error scenarios

Future Enhancements

Potential additions to the test suite:

  • Test UI component rendering
  • Test form validation
  • Test loading states
  • Test success/error toast messages
  • Test concurrent operations
  • Test with real database (integration tests)
  • Performance tests for large user lists