Files
zszq-trs/YLErpWeb/fe-tests/_shim_run.js
hjhan 4f46e2634f 修复收益互换多次部分平仓预付金返还:平仓比例/名义本金改以剩余持仓为基准
unwindSwapTrade.js:
- oriClosePercent 恒为 1(Definition B 下最多平 100% 剩余,修正全部平仓/按比例少返预付金 + 进页面 getInterestList 少算)
- CloseMethod==1(全部平仓)时修正 ClosePercent=1;CloseMethod==2(部分平仓/待复核)保留已提交比例,避免覆盖
- changeCloseQty/Percent/NotionalValue 三处换算改用 PosiNotionalValue(剩余本金),不再用原始 NotionalValue

swapCalc.js: 新增 calcCloseNotionalByRemaining / calcClosePercentByRemaining 纯函数(含除零保护)
swapCalc.test.js + _shim_run.js: 补充多次部分平仓换算单测(剩余vs原始对比、第3次全平、3次合计=原始、除零保护)
2026-07-16 10:03:21 +08:00

55 lines
1.9 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* _shim_run.js — 不依赖 jest 的轻量测试运行器(仅用于在沙箱内验证测试文件逻辑)。
* 本机请用 jestcd YLErpWeb/fe-tests && npm i && npm test
*/
let passed = 0;
let failed = 0;
const failures = [];
function fmt(v) {
return typeof v === 'object' ? JSON.stringify(v) : String(v);
}
function makeExpect(actual) {
return {
toBe(expected) {
if (Object.is(actual, expected)) { passed++; }
else { failed++; failures.push('toBe: expected ' + fmt(expected) + ' got ' + fmt(actual)); }
},
toBeDefined() {
if (actual !== undefined && actual !== null) { passed++; }
else { failed++; failures.push('toBeDefined: got ' + fmt(actual)); }
},
toBeLessThanOrEqual(n) {
if (actual <= n) { passed++; }
else { failed++; failures.push('toBeLessThanOrEqual: ' + fmt(actual) + ' <= ' + n + ' failed'); }
},
toBeGreaterThan(n) {
if (actual > n) { passed++; }
else { failed++; failures.push('toBeGreaterThan: ' + fmt(actual) + ' > ' + n + ' failed'); }
},
toBeGreaterThanOrEqual(n) {
if (actual >= n) { passed++; }
else { failed++; failures.push('toBeGreaterThanOrEqual: ' + fmt(actual) + ' >= ' + n + ' failed'); }
},
};
}
global.expect = (actual) => makeExpect(actual);
global.describe = (name, fn) => { fn(); };
global.test = (name, fn) => {
try { fn(); }
catch (e) { failed++; failures.push(name + ': ' + e.message); }
};
global.it = global.test;
require('./swapCalc.test.js');
require('./otcformat.test.js');
require('./parity.test.js');
console.log('\n==== RUNNER (jest-shim) ====');
console.log('PASS=' + passed + ' FAIL=' + failed);
failures.forEach((f) => console.log(' ✗ ' + f));
console.log(failures.length ? 'RESULT: RED' : 'RESULT: GREEN');
process.exit(failed > 0 ? 1 : 0);