refactor(web): 平仓页收付方向符号显式化unwindLegSign.js+4例单测——裸三元(x==1?±1:∓1)抽为命名函数并冻结业务事实:利息盈亏与保证金返还本金对同一InterestDirection枚举必须反号(利息=买方持有标的向交易商融资的成本,保证金返还=退客户自己交的钱,业务确认非笔误),不变量断言两符号之和恒0,顺手统一必挂;interestPnlSign对利息/保证金两腿通用(changeInterestAmount模板对两类行都绑定,已核实);另删死代码:this.ratio/this.shortRatio数据属性+赋值全库无读取(模板亦无绑定)及注释掉的历史三元;SwapUnwind.cshtml补script标签,两个执行型测试沙箱喂真实模块;行为等价(Number===1与==1对实际入参等价已验证),全套315例绿
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* unwindLegSign.test.js — 平仓页收付方向符号映射(隐式约定显式化)
|
||||
* ============================================================================
|
||||
* 冻结的领域事实(2026-08-21 业务确认):
|
||||
* 利息腿(融资成本)与保证金腿(返息/返还本金)方向【必须相反】——
|
||||
* 利息是买方持有标的向交易商融资的成本(买方付出去的钱);
|
||||
* 保证金是客户自己交的抵押金,返息/返还是把客户自己的钱退回来。
|
||||
* 两者对同一 InterestDirection 枚举符号互为镜像,这是业务事实而非笔误,
|
||||
* 任何人"顺手统一"这两个符号都会翻转保证金返还方向(资损级 bug)。
|
||||
*
|
||||
* 另冻结:PayDirection==1 → +1、PositionType==1(多头) → +1 的浮动端/多空符号。
|
||||
*
|
||||
* 运行:cd YLErpWeb/fe-tests && npx jest unwindLegSign
|
||||
*/
|
||||
const UnwindLegSign = require('../wwwroot/Scripts/app/swaptrade/unwindLegSign.js');
|
||||
|
||||
describe('收付方向符号:各枚举映射', () => {
|
||||
test('利息盈亏(利息腿/保证金腿通用):收取(1)→+1,支付(其他)→-1', () => {
|
||||
expect(UnwindLegSign.interestPnlSign(1)).toBe(1);
|
||||
expect(UnwindLegSign.interestPnlSign(0)).toBe(-1);
|
||||
expect(UnwindLegSign.interestPnlSign(null)).toBe(-1);
|
||||
});
|
||||
|
||||
test('保证金腿返还本金:与利息腿同枚举反号(返的是客户自己的钱)', () => {
|
||||
expect(UnwindLegSign.marginRebatePrincipalSign(1)).toBe(-1);
|
||||
expect(UnwindLegSign.marginRebatePrincipalSign(0)).toBe(1);
|
||||
expect(UnwindLegSign.marginRebatePrincipalSign(null)).toBe(1);
|
||||
});
|
||||
|
||||
test('浮动端收付:PayDirection==1(收取)→+1;多空:PositionType==1(多头)→+1', () => {
|
||||
expect(UnwindLegSign.payDirectionSign(1)).toBe(1);
|
||||
expect(UnwindLegSign.payDirectionSign(0)).toBe(-1);
|
||||
expect(UnwindLegSign.positionTypeSign(1)).toBe(1);
|
||||
expect(UnwindLegSign.positionTypeSign(0)).toBe(-1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('不变量:利息腿与保证金腿符号互为镜像(业务事实,禁止统一)', () => {
|
||||
test('同一 InterestDirection 下两符号之和恒为 0', () => {
|
||||
[1, 0, null, undefined, 2].forEach(dir => {
|
||||
expect(
|
||||
UnwindLegSign.interestPnlSign(dir)
|
||||
+ UnwindLegSign.marginRebatePrincipalSign(dir)
|
||||
).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user