← back to Sanderson Onboard

tk10873/test_proposals.mjs

17 lines

#!/usr/bin/env node
// test_proposals.mjs — unit tests for dispositionOf (pure).
import { dispositionOf } from './build_harvest_proposals.mjs';
let pass = 0, fail = 0;
const ok = (c, m) => { if (c) pass++; else { fail++; console.error(`FAIL: ${m}`); } };

ok(dispositionOf({ status: 'PROPOSED', us_retail: 342 }) === 'PROPOSE', 'firm price -> PROPOSE');
ok(dispositionOf({ status: 'FABRIC_MISCLASS', us_retail: 133 }) === 'RECLASSIFY_FABRIC', 'fabric -> RECLASSIFY_FABRIC');
ok(dispositionOf({ status: 'NOT_FOUND', us_retail: null }) === 'HOLD_NO_US_PRICE', 'not found -> HOLD_NO_US_PRICE');
ok(dispositionOf({ status: 'PROPOSED', us_retail: null }) === 'HOLD_NO_US_PRICE', 'null price -> HOLD_NO_US_PRICE');
ok(dispositionOf({ status: 'PROPOSED', us_retail: 2 }) === 'HOLD_BAD_PRICE', 'below sample -> HOLD_BAD_PRICE');
ok(dispositionOf({ status: 'PROPOSED_UNIT_FLAG', us_retail: 350 }) === 'PROPOSE_UNIT_REVIEW', 'unit flag -> PROPOSE_UNIT_REVIEW');
ok(dispositionOf({ status: 'PROPOSED_SIBLING_EST', us_retail: 342 }) === 'PROPOSE_LOW_CONF', 'sibling est -> PROPOSE_LOW_CONF');

console.log(`\ntest_proposals: ${pass} passed, ${fail} failed`);
process.exit(fail === 0 ? 0 : 1);