import assert from "node:assert/strict";
import test from "node:test";
import { buildHrAggregateScore, churnScoreFromPct, headcountStabilityScore, tenureScoreFromMedianMonths } from "@/lib/human-capital/scoring";

test("HR scoring helpers clamp and scale values correctly", () => {
  assert.equal(churnScoreFromPct(0), 100);
  assert.equal(churnScoreFromPct(20), 0);
  assert.equal(tenureScoreFromMedianMonths(36), 100);
  assert.equal(tenureScoreFromMedianMonths(18), 50);
  assert.equal(headcountStabilityScore(100, 100), 100);
  assert.equal(headcountStabilityScore(110, 100), 90);
});

test("buildHrAggregateScore uses configured weighted composite", () => {
  const result = buildHrAggregateScore({
    monthlyChurnPct: 5,
    medianTenureMonths: 24,
    activeHeadcount: 110,
    previousHeadcount: 100,
    kpiCompliancePct: 88,
  });

  assert.equal(result.weights.churn, 0.35);
  assert.equal(result.weights.tenure, 0.25);
  assert.equal(result.weights.headcountStability, 0.2);
  assert.equal(result.weights.kpiCompliance, 0.2);
  assert.ok(result.totalScore > 0);
  assert.ok(result.totalScore <= 100);
});
