Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VDJVpPiGiWjJP1yVvvGhzQ
45 lines
2.8 KiB
JavaScript
45 lines
2.8 KiB
JavaScript
import test from 'node:test';
|
||
import assert from 'node:assert/strict';
|
||
import { readFile } from 'node:fs/promises';
|
||
import { computeModel } from '../calc-engine.js';
|
||
import { applySimulation, compareDept, simulatedPerson } from '../simulate.js';
|
||
|
||
const seed = JSON.parse(await readFile(new URL('../seed/demo.json', import.meta.url), 'utf8'));
|
||
const dept = Object.keys(computeModel(seed).codaGroups).find(d => computeModel(seed).codaGroups[d].coda > 0);
|
||
|
||
test('simulated people: 工讀 is O with day rate = hourly × 8; interns are A with the Intern title', () => {
|
||
const where = { dept: 'X', company: 'C' };
|
||
const partTime = simulatedPerson({ kind: 'parttime', salaryType: 'hourly', amount: 200, h1Start: 1, h1End: 6 }, where, 0);
|
||
assert.equal(partTime.role, 'O - 外包');
|
||
assert.equal(partTime.dayrate, 1600);
|
||
const intern = simulatedPerson({ kind: 'intern', salaryType: 'monthly', amount: 30000, h1Start: 1, h1End: 6 }, where, 1);
|
||
assert.equal(intern.title, 'Intern');
|
||
assert.throws(() => simulatedPerson({ kind: 'A', salaryType: 'monthly', amount: 1, h1Start: 7, h1End: 6 }, where, 2));
|
||
assert.throws(() => simulatedPerson({ kind: 'boss', salaryType: 'monthly', amount: 1 }, where, 3));
|
||
});
|
||
|
||
test('adding an artist raises the department CODA; an O does not; the original data is untouched', () => {
|
||
const before = JSON.stringify(seed);
|
||
const base = computeModel(seed);
|
||
const withA = computeModel(applySimulation(seed, dept, { additions: [{ kind: 'A', salaryType: 'monthly', amount: 50000, h1Start: 1, h1End: 6, h2Start: 7, h2End: 12 }] }));
|
||
const withO = computeModel(applySimulation(seed, dept, { additions: [{ kind: 'O', salaryType: 'daily', amount: 3000, h1Start: 1, h1End: 6 }] }));
|
||
assert.ok(withA.codaGroups[dept].coda > base.codaGroups[dept].coda);
|
||
assert.equal(withO.codaGroups[dept].coda, base.codaGroups[dept].coda);
|
||
assert.equal(JSON.stringify(seed), before);
|
||
const result = compareDept(base, withA, null, null, dept);
|
||
assert.ok(result.rows.find(r => r.key === 'actualCoda').delta > 0);
|
||
assert.equal(result.anchored, false);
|
||
});
|
||
|
||
test('the comparison includes the multiplier, the invoice share and group headcount', () => {
|
||
const base = computeModel(seed);
|
||
const group = Object.keys(base.codaGroups[dept].groups)[0];
|
||
const after = computeModel(applySimulation(seed, dept, { additions: [{ kind: 'A', group, salaryType: 'monthly', amount: 50000, h1Start: 1, h1End: 6, h2Start: 7, h2End: 12 }] }));
|
||
const result = compareDept(base, after, null, null, dept);
|
||
const multiplier = result.rows.find(r => r.key === 'multiplier');
|
||
assert.ok(multiplier.before > 0 && multiplier.after > 0);
|
||
assert.ok(result.rows.some(r => r.key === 'invoiceShare'));
|
||
const g = result.groups.find(x => x.group === group);
|
||
assert.equal(g.after.headcount - g.before.headcount, 1);
|
||
});
|