Files
Aislo/resources/tester/test_est_change_workflow.py

70 lines
2.9 KiB
Python

from test_est_rea_parity import run
def test_original_recalculation_modes_keep_old_quantities_and_only_refresh_selected_prices():
result = run(
"math",
"""(()=>{
const p=EstNative.empty();
p.tables.StuffcDat=[{PkID:1,Code:'M',ValueIndex:4,InputTC:100}];
p.tables.EstMainDat=[{PkID:1,Code:'M',LinkIndex:5,GN:2},{PkID:2,LinkIndex:54}];
const q=EstBusiness.baseline(EstNative.calculate(p));
const before=JSON.stringify(q.baseline);
q.tables.StuffcDat[0].InputTC=150;q.tables.EstMainDat[0].GN=7;
q.tables.EstMainDat.splice(1,0,{PkID:3,Code:'M',LinkIndex:5,GN:1,NewItem:true});
const modes=[0,1,2].map(method=>EstBusiness.original(q,method).tables.EstMainDat);
return {modes,unchanged:before===JSON.stringify(q.baseline)};
})()""",
)
assert result["unchanged"]
for mode, rows in enumerate(result["modes"]):
assert rows[0]["GN"] == 2
assert rows[0]["TC"] == (200 if mode == 0 else 300)
assert rows[1]["TC"] == 150
assert rows[-1]["TC"] == (350 if mode == 0 else 450)
def test_design_change_includes_deleted_and_new_rows_without_modifying_contract():
result = run(
"math",
"""(()=>{
const p=EstNative.empty();p.options.SourceRefresh=false;
p.tables.EstMainDat=[{PkID:1,Code:'A',Name:'kept',GN:2,GU:100},
{PkID:3,Code:'B',Name:'removed',GN:3,NU:50},{PkID:2,LinkIndex:54}];
let q=EstBusiness.baseline(EstNative.calculate(p));
const before=JSON.stringify(q.baseline);
q.tables.EstMainDat.splice(1,1);
q.tables.EstMainDat[0].GN=4;
q.tables.EstMainDat.splice(1,0,{...EstModel.newRow('EstMainDat',q.tables.EstMainDat,q),Code:'C',Name:'new',GN:1,JU:25});
q=EstNative.calculate(q);
return {changes:EstBusiness.changes(q),same:before===JSON.stringify(q.baseline)};
})()""",
)
assert result["same"]
rows = {row["Code"]: row for row in result["changes"] if row["Code"]}
assert rows["A"]["status"] == "changed"
assert rows["A"]["difference"] == 200
assert rows["B"]["status"] == "deleted"
assert rows["B"]["originalGN"] == 3
assert rows["B"]["GN"] == rows["B"]["TC"] == 0
assert rows["B"]["difference"] == -150
assert rows["C"]["status"] == "new"
assert rows["C"]["difference"] == 25
def test_blank_codes_have_distinct_keys_and_metadata_changes_are_reported():
result = run(
"math",
"""(()=>{
const p=EstNative.empty();p.tables.EstMainDat=[
{PkID:1,Code:'A',Name:'renamed',GN:1,TC:10},
{Code:'',Name:'first'},{Code:'',Name:'second'}];
p.baseline={name:'old',tables:{EstMainDat:[
{PkID:1,Code:'A',Name:'old',GN:1,TC:10}]}};
return {rows:EstBusiness.changes(p),keys:p.tables.EstMainDat.map(EstBusiness.rowKey)};
})()""",
)
assert len(set(result["keys"][1:])) == 2
assert result["rows"][0]["status"] == "changed"
assert result["rows"][0]["difference"] == 0