- incomeSwapTrade.js / swapTradeEdit.js 改为调用 SwapCalc.*(缩放/取整/全价推导) - 新增 fe-tests 守卫:4 个历史 bug 回归 + 8 场景对齐 C# FrontendCalcReference 金标准 + otcformat.js 精度配置守卫 - 新增 .git/hooks/pre-commit 自动运行前端守卫(失败阻断提交)
51 lines
2.1 KiB
JavaScript
51 lines
2.1 KiB
JavaScript
/**
|
||
* otcformat.test.js — 守卫运行时配置 otcformat.js 的精度回归
|
||
* ============================================================================
|
||
* 背景:088df270 中 otcformat.js 的 precision 被 Revert 误从 9 改回 2,
|
||
* 导致"期末全价只能录 2 位小数"。该 bug 已复发 2 次,纯前端/后端测试都碰不到。
|
||
* 本测试直接解析 App_Data/Config/otcformat.js,断言关键字段 precision 不低于预期,
|
||
* 是 ROI 最高的单一守卫(零重构、1 个文件、无依赖)。
|
||
*
|
||
* 运行:cd YLErpWeb/fe-tests && npm i && npm test
|
||
*/
|
||
const fs = require('fs');
|
||
const path = require('path');
|
||
|
||
const cfgPath = path.resolve(__dirname, '../App_Data/Config/otcformat.js');
|
||
const src = fs.readFileSync(cfgPath, 'utf8');
|
||
|
||
// otcformat.js 形如 `var main = main || {}; main.formatOptions = {...};`
|
||
// 在沙箱函数内求值并取出 main.formatOptions
|
||
const formatOptions = new Function(src + '\n;return main.formatOptions;')();
|
||
|
||
describe('otcformat.js 精度配置守卫 (088df270)', () => {
|
||
test('配置文件可被解析且含 trading 节点', () => {
|
||
expect(formatOptions).toBeDefined();
|
||
expect(formatOptions.trading).toBeDefined();
|
||
});
|
||
|
||
// 这些字段在 088df270 被误降到 2,必须保持 9(与当前全 precision=9 一致)
|
||
const mustBeNine = [
|
||
'umprice', 'umpriceP', 'umpricePR',
|
||
'tradeSinglePrice', 'tradePrice', 'StockEqvNotional', 'notional',
|
||
'premiumRate', 'premiumRateP', 'volatility',
|
||
'marginRate', 'marginRateP', 'greek'
|
||
];
|
||
|
||
mustBeNine.forEach(function (key) {
|
||
test('trading.' + key + '.precision === 9', () => {
|
||
expect(formatOptions.trading[key]).toBeDefined();
|
||
expect(formatOptions.trading[key].precision).toBe(9);
|
||
});
|
||
});
|
||
|
||
test('所有 trading 数值字段 precision 均 >= 9(防再次误降)', () => {
|
||
Object.keys(formatOptions.trading).forEach(function (key) {
|
||
const opt = formatOptions.trading[key];
|
||
if (opt && typeof opt.precision === 'number') {
|
||
expect(opt.precision).toBeGreaterThanOrEqual(9);
|
||
}
|
||
});
|
||
});
|
||
});
|