Standing orders: a re-hired intern starts on a fresh month's budget

This commit is contained in:
Frederic Jung 2026-10-28 20:03:25 +01:00
parent 946da17c8b
commit a0a492f19e
No known key found for this signature in database
2 changed files with 14 additions and 1 deletions

View file

@ -2,7 +2,9 @@
const opsCycle=(a,v)=>a[(a.indexOf(v)+1)%a.length];
Object.assign(ACT,{
opsOpen:()=>{if(S)opsModal();},
opsHire:({id})=>{if(!S||opsHired()||!own(INTERNS,id)||!opsCanHire()||!rule('clock'))return;if(!spend(INTERN_MO))return;const O=opsO();O.intern=id;O.hired=S.day;O.mon=Math.floor(S.day/30);
opsHire:({id})=>{if(!S||opsHired()||!own(INTERNS,id)||!opsCanHire()||!rule('clock'))return;if(!spend(INTERN_MO))return;const O=opsO(),m=Math.floor(S.day/30);O.intern=id;O.hired=S.day;
// A new hire starts on a fresh month's budget, whatever the last one spent.
if(m!==O.mon){O.mon=m;for(const k in O.spent)O.spent[k]=0;}
O.log.unshift({d:S.day,i:id,r:[]});toast(esc(tr('ops.hired',{name:opsName(true)})),'good',[{l:tr('ops.ops'),act:'opsOpen',args:{}}]);after();opsModal();},
opsFire:()=>{if(!opsHired())return;if(UI.confirm!=='opsFire'){UI.confirm='opsFire';opsModal();return;}UI.confirm=null;const nm=opsName();S.ops.intern=null;
toast(esc(tr('ops.fired',{name:nm})),'');after();opsModal();},

View file

@ -339,3 +339,14 @@ test('sales trial at most one offer a shift, and an offer that did not fit waits
ev('autoOffer=__a');
assert.deepEqual(errors, []);
});
test('re-hiring in a later month starts on a fresh budget, not last month\'s spending', t => {
const { ev, errors } = game(t);
hire(ev);
ev("S.ops.spent.transit=50000;ACT.opsFire();ACT.opsFire();S.day=400;ACT.opsHire({id:'kevin'});closeModal()");
assert.equal(ev('S.ops.spent.transit'), 0);
assert.equal(ev('S.ops.mon'), ev('Math.floor(S.day/30)'));
ev("S.ops.spent.transit=1234;ACT.opsFire();ACT.opsFire();ACT.opsHire({id:'annie'});closeModal()");
assert.equal(ev('S.ops.spent.transit'), 1234, 'the same month: what was spent stays spent');
assert.deepEqual(errors, []);
});