forked from lunanting/cangku
74 lines
2.3 KiB
JavaScript
74 lines
2.3 KiB
JavaScript
'use strict';
|
|
|
|
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const {
|
|
_test: { buildSelectionSupplyDecision, buildSelectionSupplyMetadata },
|
|
} = require('../src/services/planningSelectionFissionService');
|
|
|
|
function completeRow(overrides = {}) {
|
|
return {
|
|
skuCode: 'SKU-A',
|
|
cost: 280,
|
|
finalPrice: 600,
|
|
freightNational: 40,
|
|
installationFee: 0,
|
|
platformCommissionRatio: 0.015,
|
|
marketingAdRatio: 0.025,
|
|
farmingRatio: 0.005,
|
|
aftersaleRatio: 0.05,
|
|
insuranceRatio: 0.05,
|
|
brandUsageRatio: 0,
|
|
operatingProfitRatio: 0.15,
|
|
promotionRatio: 0.1,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
test('company pricing is judged with the saved market price band and profit room', () => {
|
|
const decision = buildSelectionSupplyDecision(
|
|
[completeRow(), completeRow({ skuCode: 'SKU-B', finalPrice: 650 })],
|
|
{ marketEvidence: { priceBand: '500-800' } },
|
|
'company'
|
|
);
|
|
|
|
assert.equal(decision.status, 'advantage');
|
|
assert.equal(decision.passedSkuCount, 2);
|
|
assert.equal(decision.marketPriceBand, '500-800');
|
|
assert.equal(decision.rows[0].allowedMaxCost, 383);
|
|
});
|
|
|
|
test('missing cost evidence is never treated as zero cost', () => {
|
|
const decision = buildSelectionSupplyDecision(
|
|
[completeRow({ cost: null })],
|
|
{ marketEvidence: { priceBand: '500-800' } },
|
|
'company'
|
|
);
|
|
|
|
assert.equal(decision.status, 'evidence_insufficient');
|
|
assert.equal(decision.completeSkuCount, 0);
|
|
assert.equal(decision.rows[0].allowedMaxCost, null);
|
|
});
|
|
|
|
test('1688 pricing preserves the company decision in one supply comparison', () => {
|
|
const company = buildSelectionSupplyDecision(
|
|
[completeRow({ promotionRatio: -0.02 })],
|
|
{ marketEvidence: { priceBand: '500-800' } },
|
|
'company'
|
|
);
|
|
const alibaba1688 = buildSelectionSupplyDecision(
|
|
[completeRow({ cost: 220, promotionRatio: 0.18 })],
|
|
{ marketEvidence: { priceBand: '500-800' } },
|
|
'1688'
|
|
);
|
|
const metadata = buildSelectionSupplyMetadata({
|
|
marketEvidence: { priceBand: '500-800' },
|
|
supplyComparison: { company },
|
|
}, alibaba1688, '1688');
|
|
|
|
assert.equal(metadata.supplyComparison.company.status, 'no_advantage');
|
|
assert.equal(metadata.supplyComparison.alibaba1688.status, 'advantage');
|
|
assert.equal(metadata.supplyComparison.finalSource, '1688');
|
|
assert.equal(metadata.supplyDecision.source, '1688');
|
|
});
|