brackt/app/lib/__tests__
Chris Parsons 0ba2b391f8
Fix draft order initialization for teams added mid-season (#449)
* Fix draft order showing only new team when league size increased before order was set

When a commissioner increased the team count on a league that had teams
but no draft order set yet, the server created draft slots only for the
newly-added teams. This left the DB with N+K teams but only K slots,
causing the drag-and-drop list to display only the K new teams.

Two fixes:
1. Server: only append new draft slots when an order was already set
   (existingSlots.length > 0). If no order exists yet, skip slot creation
   so the page correctly treats the order as unset for all teams.
2. Frontend: buildDraftOrderTeams() appends any unslotted teams after the
   slotted ones, so a partially-corrupt DB state still shows all teams.

https://claude.ai/code/session_01M3H55gnMxRztJK9KMXqqZo

* Address code review feedback on draft order bug fix

- Move buildDraftOrderTeams to app/lib/draft-order.ts so it is importable
  and testable; remove the local copy from the settings component
- Add unit tests for buildDraftOrderTeams covering the empty, full, and
  partial-slot cases
- Tighten the draft slot guard from existingSlots.length > 0 to
  existingSlots.length === currentTeamCount so partial legacy states are
  treated the same as "order not set"
- Condense the 3-line server comment to a single line per project style
- Rename getNumTeamsInSeason → getNumDraftSlotsBySeasonId to reflect what
  the function actually counts, and update its one call site
- Add tests for the server-side slot-creation guard logic

https://claude.ai/code/session_01M3H55gnMxRztJK9KMXqqZo

* Fix lint: move shouldAppendDraftSlots to outer scope

oxlint (consistent-function-scoping) requires functions that don't close
over any variables to be defined at the outer scope rather than inside a
describe block.

https://claude.ai/code/session_01M3H55gnMxRztJK9KMXqqZo

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-05-19 18:22:47 -07:00
..
cloudinary-url.test.ts Add Cloudinary-backed avatar system (#385) 2026-05-06 14:47:37 -07:00
cloudinary.server.test.ts Add Cloudinary sports icon uploads (#393) 2026-05-07 16:07:34 -07:00
date-utils.test.ts Add upcoming events pages and fix timezone filtering, fixes #213 (#235) 2026-03-27 00:49:16 -07:00
draft-eligibility.test.ts Show why a participant is ineligible to draft (#378) 2026-05-04 21:54:14 -07:00
draft-order.test.ts Fix draft order initialization for teams added mid-season (#449) 2026-05-19 18:22:47 -07:00
draft-timer.test.ts Extract chess clock presets to shared constant (#432) 2026-05-15 14:02:49 -07:00
email.server.test.ts Add branded dark-themed HTML email template (#402) 2026-05-10 11:18:57 -07:00
flag-generator.test.ts Add Cloudinary-backed avatar system (#385) 2026-05-06 14:47:37 -07:00
normalize-team-name.test.ts Add regular season standings for NBA/NHL (fixes #89) (#192) 2026-03-21 00:12:01 -07:00
overnight-pause.test.ts Add overnight pause for draft timers (#335) 2026-04-26 22:31:52 -07:00
parse-results-text.test.ts feat: batch qualifying results entry (#290) 2026-04-12 14:52:22 -07:00
season-helpers.server.test.ts feat: add recharts library and implement PointProgressionChart component for historical views 2025-11-14 21:18:34 -08:00
sport-icon-url.test.ts Harden sport icon cleanup (#397) 2026-05-08 21:19:09 -07:00
standings-display.test.ts Show tied ranks with T prefix across standings and Discord (#239) 2026-03-27 20:45:15 -07:00
unmatched-team-reconciliation.test.ts Improve unmatched team reconciliation UX (#425) 2026-05-14 16:45:02 -07:00
utils.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