Sold-out wave sizes can't be reached by upgrading a smaller wave (#201)

From #202 by JMF-Alex, moved onto 2.0: its test now lives in tests/pnis-and-sold-out.test.js (the peering inbox tests are gone) and also checks the panel button and that nothing is charged.
This commit is contained in:
JMF-Alex 2026-10-28 17:02:48 +01:00 • committed by Frederic Jung
parent abd55c0846
commit 91481b1d6b
No known key found for this signature in database
4 changed files with 23 additions and 2 deletions

View file

@ -125,3 +125,22 @@ test('now and then a route is sold out of a wave size, for a while, and asking a
assert.match(ev("document.getElementById('toasts').textContent"), /No 400G capacity on this route/);
assert.deepEqual(errors, []);
});
test('#201 a sold-out wave size cannot be reached by upgrading a smaller wave on the route', () => {
const { ev, errors } = load();
setup(ev);
ev("ACT.buildPop({city:'ams'});S.pops.ams.rgen=3;S.cash=1e9");
const day = ev("(()=>{for(let d=90;d<20000;d++){S.day=d;if(soldOut('fra','ams',2,null)&&!soldOut('fra','ams',1,null))return d;}return -1;})()");
assert.ok(day > 0, 'it happens');
ev(`S.day=${day};S.links.push({id:'upw',a:'fra',b:'ams',kind:'wave',tier:1,km:400,sub:false,cable:null,mo:1,mult:1,trench:'upw',cut:0,day:0})`);
const cash = ev('S.cash');
ev("ACT.upLink({id:'upw',tier:2})");
assert.equal(ev("S.links.find(l=>l.id==='upw').tier"), 1, 'still the old size');
assert.equal(ev('S.cash'), cash, 'nothing charged');
assert.match(ev("document.getElementById('toasts').textContent"), /No 400G capacity on this route/);
// the link panel's button for that size is disabled and says why
ev("UI.sel={type:'link',id:'upw'};renderPanel()");
const b = ev(`(()=>{const b=[...document.querySelectorAll('[data-act=upLink]')].find(x=>JSON.parse(x.dataset.args).tier===2);return b?b.disabled+':'+b.textContent:''})()`);
assert.match(b, /^true:.*sold out/i);
assert.deepEqual(errors, []);
});