Files
CapaKraken/packages/engine/src/__tests__/availability.test.ts
T
Hartmut cd78f72f33 chore: full technical rename planarchy → capakraken
Complete rename of all technical identifiers across the codebase:

Package names (11 packages):
- @planarchy/* → @capakraken/* in all package.json, tsconfig, imports

Import statements: 277 files, 548 occurrences replaced

Database & Docker:
- PostgreSQL user/db: planarchy → capakraken
- Docker volumes: planarchy_pgdata → capakraken_pgdata
- Connection strings updated in docker-compose, .env, CI

CI/CD:
- GitHub Actions workflow: all filter commands updated
- Test database credentials updated

Infrastructure:
- Redis channel: planarchy:sse → capakraken:sse
- Logger service name: planarchy-api → capakraken-api
- Anonymization seed updated
- Start/stop/restart scripts updated

Test data:
- Seed emails: @planarchy.dev → @capakraken.dev
- E2E test credentials: all 11 spec files updated
- Email defaults: @planarchy.app → @capakraken.app
- localStorage keys: planarchy_* → capakraken_*

Documentation: 30+ .md files updated

Verification:
- pnpm install: workspace resolution works
- TypeScript: only pre-existing TS2589 (no new errors)
- Engine: 310/310 tests pass
- Staffing: 37/37 tests pass

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-03-27 13:18:09 +01:00

145 lines
3.6 KiB
TypeScript

import { AllocationStatus } from "@capakraken/shared";
import { describe, expect, it } from "vitest";
import { detectOverlaps, validateAvailability } from "../allocation/availability-validator.js";
const stdAvailability = {
monday: 8,
tuesday: 8,
wednesday: 8,
thursday: 8,
friday: 8,
};
describe("validateAvailability", () => {
it("passes when no existing allocations", () => {
const result = validateAvailability(
new Date("2025-01-06"),
new Date("2025-01-10"),
8,
stdAvailability,
[],
);
expect(result.valid).toBe(true);
expect(result.conflicts).toHaveLength(0);
});
it("detects conflict when combined hours exceed availability", () => {
const existing = [{
startDate: new Date("2025-01-06"),
endDate: new Date("2025-01-10"),
hoursPerDay: 6,
status: AllocationStatus.CONFIRMED,
}];
const result = validateAvailability(
new Date("2025-01-06"),
new Date("2025-01-10"),
4, // 6+4=10 > 8
stdAvailability,
existing,
);
expect(result.valid).toBe(false);
expect(result.conflicts).toHaveLength(5); // All 5 working days
});
it("passes when combined hours exactly match availability", () => {
const existing = [{
startDate: new Date("2025-01-06"),
endDate: new Date("2025-01-10"),
hoursPerDay: 4,
status: AllocationStatus.CONFIRMED,
}];
const result = validateAvailability(
new Date("2025-01-06"),
new Date("2025-01-10"),
4, // 4+4=8 ≤ 8
stdAvailability,
existing,
);
expect(result.valid).toBe(true);
});
it("ignores cancelled allocations", () => {
const existing = [{
startDate: new Date("2025-01-06"),
endDate: new Date("2025-01-10"),
hoursPerDay: 8,
status: AllocationStatus.CANCELLED,
}];
const result = validateAvailability(
new Date("2025-01-06"),
new Date("2025-01-10"),
8,
stdAvailability,
existing,
);
expect(result.valid).toBe(true);
});
it("skips non-working days in conflict check", () => {
const result = validateAvailability(
new Date("2025-01-04"), // Saturday
new Date("2025-01-05"), // Sunday
8,
stdAvailability,
[],
);
expect(result.valid).toBe(true);
expect(result.conflicts).toHaveLength(0);
});
});
describe("detectOverlaps", () => {
const existingAlloc = {
id: "alloc-1",
startDate: new Date("2025-01-06"),
endDate: new Date("2025-01-10"),
projectId: "proj-1",
status: AllocationStatus.ACTIVE,
};
it("detects overlapping allocations", () => {
const overlaps = detectOverlaps(
new Date("2025-01-08"),
new Date("2025-01-15"),
[existingAlloc],
);
expect(overlaps).toContain("alloc-1");
});
it("returns empty for non-overlapping date ranges", () => {
const overlaps = detectOverlaps(
new Date("2025-01-13"), // Starts after existing ends
new Date("2025-01-17"),
[existingAlloc],
);
expect(overlaps).toHaveLength(0);
});
it("excludes same-project allocations when excludeProjectId provided", () => {
const overlaps = detectOverlaps(
new Date("2025-01-08"),
new Date("2025-01-15"),
[existingAlloc],
"proj-1", // Exclude this project
);
expect(overlaps).toHaveLength(0);
});
it("ignores cancelled allocations", () => {
const cancelled = { ...existingAlloc, status: AllocationStatus.CANCELLED };
const overlaps = detectOverlaps(
new Date("2025-01-08"),
new Date("2025-01-15"),
[cancelled],
);
expect(overlaps).toHaveLength(0);
});
});