wip(est-test): 개발 중 저장 3 — 깃 싱크(11-08)
This commit is contained in:
@@ -1,6 +1,132 @@
|
||||
from test_est_rea_parity import run
|
||||
|
||||
|
||||
def test_machine_restore_group_uses_saved_baseline_without_changing_other_groups():
|
||||
result = run(
|
||||
"math",
|
||||
"""(()=>{
|
||||
const p=EstNative.empty();
|
||||
p.tables.MachMainDat=[{PkID:1,Index:1,Code:'M1',Name:'장비1'},{PkID:2,Index:0,GN:2},
|
||||
{PkID:3,Index:1,Code:'M2',Name:'장비2'},{PkID:4,Index:0,GN:3}];
|
||||
p.tables.MachTitleDat=[{Code:'M1',Name:'장비1'},{Code:'M2',Name:'장비2'}];
|
||||
const q=EstModel.validate(JSON.parse(JSON.stringify(EstBusiness.baseline(p))));
|
||||
q.tables.MachMainDat[1].GN=9;q.tables.MachMainDat[3].GN=7;
|
||||
const before=JSON.stringify(q), rows=EstMachine.restoreGroup(q,'M1');
|
||||
const originalUntouched=JSON.stringify(q)===before;
|
||||
let missing=false,duplicate=false,collision=false;
|
||||
const legacy=structuredClone(q);delete legacy.baseline.tables.MachMainDat;
|
||||
try { EstMachine.restoreGroup(legacy,'M1'); } catch { missing=true; }
|
||||
const conflict=structuredClone(q);conflict.tables.MachMainDat[3].PkID=2;
|
||||
try { EstMachine.restoreGroup(conflict,'M1'); } catch { collision=true; }
|
||||
q.tables.MachMainDat.push({Index:1,Code:'M1'});
|
||||
try { EstMachine.restoreGroup(q,'M1'); } catch { duplicate=true; }
|
||||
return {restored:rows[1].GN,other:rows[3].GN,originalUntouched,
|
||||
baseline:q.baseline.tables.MachMainDat[1].GN,missing,duplicate,collision};
|
||||
})()""",
|
||||
)
|
||||
assert result == {
|
||||
"restored": 2,
|
||||
"other": 7,
|
||||
"originalUntouched": True,
|
||||
"baseline": 2,
|
||||
"missing": True,
|
||||
"duplicate": True,
|
||||
"collision": True,
|
||||
}
|
||||
|
||||
|
||||
def test_machine_change_includes_new_changed_and_deleted_titles():
|
||||
result = run(
|
||||
"math",
|
||||
"""(()=>{
|
||||
const p=EstNative.empty();
|
||||
p.tables.MachTitleDat=[{Code:'M1',Name:'장비1',TC:150},{Code:'M3',Name:'신규',TC:50}];
|
||||
p.baseline={tables:{EstMainDat:[],MachTitleDat:[
|
||||
{Code:'M1',Name:'장비1',TC:100},{Code:'M2',Name:'삭제',TC:200}]}};
|
||||
return EstMachine.changes(p).map(({Code,originalTC,TC,difference,status,index})=>
|
||||
({Code,originalTC,TC,difference,status,index}));
|
||||
})()""",
|
||||
)
|
||||
assert result == [
|
||||
{
|
||||
"Code": "M1",
|
||||
"originalTC": 100,
|
||||
"TC": 150,
|
||||
"difference": 50,
|
||||
"status": "변경",
|
||||
"index": 0,
|
||||
},
|
||||
{
|
||||
"Code": "M3",
|
||||
"originalTC": None,
|
||||
"TC": 50,
|
||||
"difference": None,
|
||||
"status": "신규",
|
||||
"index": 1,
|
||||
},
|
||||
{
|
||||
"Code": "M2",
|
||||
"originalTC": 200,
|
||||
"TC": 0,
|
||||
"difference": -200,
|
||||
"status": "삭제",
|
||||
"index": None,
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def test_recover_deleted_machine_group_and_reject_id_collision():
|
||||
result = run(
|
||||
"math",
|
||||
"""(()=>{
|
||||
const p=EstNative.empty();
|
||||
p.tables.MachMainDat=[{PkID:1,Index:1,Code:'M1',Name:'first'},
|
||||
{PkID:2,Index:-2,GN:2,TU:100},{PkID:3,Index:1,Code:'M2',Name:'second'},
|
||||
{PkID:4,Index:-2,GN:3,TU:100}];
|
||||
p.tables.MachTitleDat=[{PkID:10,Code:'M1',Name:'first',TC:200},
|
||||
{PkID:11,Code:'M2',Name:'second',TC:300}];
|
||||
const q=EstBusiness.baseline(p);
|
||||
q.tables.MachMainDat=q.tables.MachMainDat.slice(2);
|
||||
q.tables.MachTitleDat=q.tables.MachTitleDat.slice(1);
|
||||
const before=JSON.stringify(q), restored=EstMachine.recoverGroup(q,'M1');
|
||||
const unchanged=JSON.stringify(q)===before;
|
||||
const collision=structuredClone(q);collision.tables.MachMainDat[1].PkID=2;
|
||||
let rejected=false;try { EstMachine.recoverGroup(collision,'M1'); } catch { rejected=true; }
|
||||
q.tables.MachMainDat=restored.rows;q.tables.MachTitleDat=restored.titles;
|
||||
return {codes:q.tables.MachTitleDat.map(x=>x.Code),quantity:q.tables.MachMainDat[1].GN,
|
||||
original:EstMachine.usage(q).find(x=>x.Code==='M1').originalPrice,unchanged,rejected};
|
||||
})()""",
|
||||
)
|
||||
assert result == {
|
||||
"codes": ["M1", "M2"],
|
||||
"quantity": 2,
|
||||
"original": 200,
|
||||
"unchanged": True,
|
||||
"rejected": True,
|
||||
}
|
||||
|
||||
|
||||
def test_recovered_machine_group_recalculates_linked_estimate_after_reopen():
|
||||
result = run(
|
||||
"math",
|
||||
"""(()=>{
|
||||
const p=EstNative.empty();p.options.SourceRefresh=true;
|
||||
p.tables.MachMainDat=[{PkID:1,Index:1,Code:'M1',Name:'machine'},
|
||||
{PkID:2,Index:-2,Name:'fuel',GN:2,TU:100}];
|
||||
p.tables.MachTitleDat=[{PkID:10,Code:'M1',Name:'machine'}];
|
||||
p.tables.EstMainDat=[{PkID:20,Code:'M1',Name:'machine',LinkIndex:105,GN:2}];
|
||||
const q=EstBusiness.baseline(EstNative.calculate(p));
|
||||
q.tables.MachMainDat=[];q.tables.MachTitleDat=[];
|
||||
const restored=EstMachine.recoverGroup(JSON.parse(JSON.stringify(q)),'M1');
|
||||
q.tables.MachMainDat=restored.rows;q.tables.MachTitleDat=restored.titles;
|
||||
const out=EstNative.calculate(EstModel.validate(JSON.parse(JSON.stringify(q))));
|
||||
return {machine:out.tables.MachTitleDat[0].TC, estimate:out.tables.EstMainDat[0].TC,
|
||||
errors:out.calculation.errors};
|
||||
})()""",
|
||||
)
|
||||
assert result == {"machine": 200, "estimate": 400, "errors": []}
|
||||
|
||||
|
||||
def test_basic_prices_changes_for_material_and_labor():
|
||||
result = run(
|
||||
"math",
|
||||
|
||||
Reference in New Issue
Block a user