import assert from "node:assert/strict" import test from "node:test" import { findCurrentSprint, isSprintInProgress } from "../../src/lib/server/sprintSelection" const NOW = new Date("2026-02-24T15:30:00") test("isSprintInProgress uses inclusive boundaries", () => { assert.equal(isSprintInProgress("2026-02-24", "2026-02-24", NOW), true) assert.equal(isSprintInProgress("2026-02-25", "2026-02-26", NOW), false) }) test("findCurrentSprint prefers active sprint in range", () => { const sprint = findCurrentSprint( [ { id: "planning", status: "planning", startDate: "2026-02-20", endDate: "2026-02-28", projectId: "p1" }, { id: "active", status: "active", startDate: "2026-02-22", endDate: "2026-02-26", projectId: "p1" }, ], { now: NOW, projectId: "p1" } ) assert.equal(sprint?.id, "active") }) test("findCurrentSprint falls back to non-completed in range", () => { const sprint = findCurrentSprint( [{ id: "planning", status: "planning", startDate: "2026-02-20", endDate: "2026-02-28", projectId: "p1" }], { now: NOW, projectId: "p1" } ) assert.equal(sprint?.id, "planning") }) test("findCurrentSprint returns null for completed-only unless fallback enabled", () => { const sprints = [{ id: "done", status: "completed", startDate: "2026-02-20", endDate: "2026-02-28", projectId: "p1" }] as const const withoutFallback = findCurrentSprint(sprints, { now: NOW, projectId: "p1" }) const withFallback = findCurrentSprint(sprints, { now: NOW, projectId: "p1", includeCompletedFallback: true }) assert.equal(withoutFallback, null) assert.equal(withFallback?.id, "done") }) test("findCurrentSprint respects project scoping", () => { const sprint = findCurrentSprint( [ { id: "p1-active", status: "active", startDate: "2026-02-20", endDate: "2026-02-28", projectId: "p1" }, { id: "p2-active", status: "active", startDate: "2026-02-20", endDate: "2026-02-28", projectId: "p2" }, ], { now: NOW, projectId: "p2" } ) assert.equal(sprint?.id, "p2-active") }) test("findCurrentSprint returns null when no sprint is in range", () => { const sprint = findCurrentSprint( [{ id: "future", status: "active", startDate: "2026-03-01", endDate: "2026-03-07", projectId: "p1" }], { now: NOW, projectId: "p1" } ) assert.equal(sprint, null) })