48 lines
2.4 KiB
JavaScript
48 lines
2.4 KiB
JavaScript
/**
|
|
* 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);
|
|
});
|
|
});
|
|
});
|