fix(calendar): preserve manual picks when regenerating a month (#2)
generatePlan gains a preAssigned parameter: manual entries occupy slots, count toward eligibility (maxPerMonth/minGap) and are never double-booked; only the remaining slots per day are auto-filled. The generate handler now keeps manual:true entries for the month instead of wiping them. Adds tests for slot occupation, fully-manual days, and maxPerMonth counting. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
700ec6de1c
commit
e851bb2833
3 files changed
+54
-12
No files matched your search
@@ -187,4 +187,31 @@ function emp(id, constraints = {}) {
|
||||
assert.deepEqual(result.skippedDates, ['2026-04-02'], 'Thu in skippedDates');
|
||||
}
|
||||
|
||||
// preAssigned: manual pick occupies a slot, only remaining slots auto-filled, no double-book
|
||||
{
|
||||
const employees = [emp('alice'), emp('bob'), emp('clara')];
|
||||
const manual = [{ date: '2026-04-01', employeeId: 'alice', manual: true }];
|
||||
const result = generatePlan(['2026-04-01'], employees, [], fixed, 2, manual);
|
||||
assert.equal(result.assignments.length, 1, 'slotsPerDay=2 with 1 manual → 1 auto entry');
|
||||
assert.notEqual(result.assignments[0].employeeId, 'alice', 'manual employee not double-booked');
|
||||
assert.equal(result.assignments[0].manual, false, 'auto entry has manual:false');
|
||||
}
|
||||
|
||||
// preAssigned: day fully staffed by manual entries → nothing generated, not skipped
|
||||
{
|
||||
const employees = [emp('alice'), emp('bob')];
|
||||
const manual = [{ date: '2026-04-01', employeeId: 'alice', manual: true }];
|
||||
const result = generatePlan(['2026-04-01'], employees, [], fixed, 1, manual);
|
||||
assert.equal(result.assignments.length, 0, 'fully manual day → no auto entries');
|
||||
assert.deepEqual(result.skippedDates, [], 'fully manual day not skipped');
|
||||
}
|
||||
|
||||
// preAssigned counts toward maxPerMonth eligibility
|
||||
{
|
||||
const employees = [emp('alice', { maxPerMonth: 1 }), emp('bob'), emp('clara')];
|
||||
const manual = [{ date: '2026-04-01', employeeId: 'alice', manual: true }];
|
||||
const result = generatePlan(['2026-04-02'], employees, [], fixed, 1, manual);
|
||||
assert.notEqual(result.assignments[0].employeeId, 'alice', 'manual entry counts toward maxPerMonth');
|
||||
}
|
||||
|
||||
console.log('All algorithm tests passed.');
|
||||
Reference in new issue
Block a user