@fintekkers/ledger-models 1.1.28 → 1.1.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/catalog/measures.json +1 -1
- package/hierarchy.json +11 -11
- package/node/fintekkers/requests/valuation/product_inputs.test.js +3 -3
- package/node/fintekkers/requests/valuation/product_inputs.test.js.map +1 -1
- package/node/fintekkers/requests/valuation/product_inputs.test.ts +3 -3
- package/node/fintekkers/requests/valuation/valuation_request_pb.d.ts +0 -14
- package/node/fintekkers/requests/valuation/valuation_request_pb.js +0 -106
- package/node/wrappers/models/errors.d.ts +14 -11
- package/node/wrappers/models/errors.js +18 -13
- package/node/wrappers/models/errors.js.map +1 -1
- package/node/wrappers/models/errors.ts +20 -14
- package/node/wrappers/models/security/product_input_builders.test.js +17 -19
- package/node/wrappers/models/security/product_input_builders.test.js.map +1 -1
- package/node/wrappers/models/security/product_input_builders.test.ts +20 -22
- package/node/wrappers/models/security/product_inputs.d.ts +69 -39
- package/node/wrappers/models/security/product_inputs.deprecated.test.d.ts +1 -0
- package/node/wrappers/models/security/product_inputs.deprecated.test.js +136 -0
- package/node/wrappers/models/security/product_inputs.deprecated.test.js.map +1 -0
- package/node/wrappers/models/security/product_inputs.deprecated.test.ts +130 -0
- package/node/wrappers/models/security/product_inputs.js +143 -75
- package/node/wrappers/models/security/product_inputs.js.map +1 -1
- package/node/wrappers/models/security/product_inputs.test.js +64 -37
- package/node/wrappers/models/security/product_inputs.test.js.map +1 -1
- package/node/wrappers/models/security/product_inputs.test.ts +69 -40
- package/node/wrappers/models/security/product_inputs.ts +152 -79
- package/node/wrappers/requests/valuation/ValuationRequests.d.ts +1 -1
- package/node/wrappers/requests/valuation/ValuationRequests.js +1 -1
- package/node/wrappers/requests/valuation/ValuationRequests.ts +1 -1
- package/node/wrappers/util/object-types.test.js +5 -2
- package/node/wrappers/util/object-types.test.js.map +1 -1
- package/node/wrappers/util/object-types.test.ts +5 -2
- package/package.json +1 -1
|
@@ -24,10 +24,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
/**
|
|
27
|
-
* LM-409:
|
|
27
|
+
* LM-409: valuation_input_types in hierarchy.json, resolved by inputTypeFor /
|
|
28
28
|
* requiredMarketData.
|
|
29
29
|
*
|
|
30
|
-
* The shared cases live in ledger-models-protos/fixtures/
|
|
30
|
+
* The shared cases live in ledger-models-protos/fixtures/valuation_input_types_cases.json,
|
|
31
31
|
* read by the Java, Python and Rust tests too.
|
|
32
32
|
*/
|
|
33
33
|
const fs = __importStar(require("fs"));
|
|
@@ -39,11 +39,12 @@ const measure_pb_1 = require("../../../fintekkers/models/position/measure_pb");
|
|
|
39
39
|
const coupon_type_pb_1 = require("../../../fintekkers/models/security/coupon_type_pb");
|
|
40
40
|
const product_type_pb_1 = require("../../../fintekkers/models/security/product_type_pb");
|
|
41
41
|
const security_pb_1 = require("../../../fintekkers/models/security/security_pb");
|
|
42
|
+
const product_inputs_pb_1 = require("../../../fintekkers/requests/valuation/product_inputs_pb");
|
|
42
43
|
const PROTOS = path.resolve(__dirname, '../../../../../ledger-models-protos');
|
|
43
44
|
const BUNDLED = path.resolve(__dirname, '../../../../hierarchy.json');
|
|
44
|
-
const cases = JSON.parse(fs.readFileSync(path.join(PROTOS, 'fixtures/
|
|
45
|
+
const cases = JSON.parse(fs.readFileSync(path.join(PROTOS, 'fixtures/valuation_input_types_cases.json'), 'utf-8')).cases;
|
|
45
46
|
function sourceSection() {
|
|
46
|
-
return JSON.parse(fs.readFileSync(path.join(PROTOS, 'hierarchy.json'), 'utf-8')).
|
|
47
|
+
return JSON.parse(fs.readFileSync(path.join(PROTOS, 'hierarchy.json'), 'utf-8')).valuation_input_types;
|
|
47
48
|
}
|
|
48
49
|
function hasEnumValue(productType) {
|
|
49
50
|
return Object.prototype.hasOwnProperty.call(product_type_pb_1.ProductTypeProto, productType);
|
|
@@ -56,14 +57,14 @@ function security(productType, couponType) {
|
|
|
56
57
|
s.setBondDetails(details);
|
|
57
58
|
return s;
|
|
58
59
|
}
|
|
59
|
-
/** [
|
|
60
|
+
/** [input type, requires] through a real proto when the type has an enum value; planned leaves by name. */
|
|
60
61
|
function resolve(productType, couponType) {
|
|
61
62
|
if (!hasEnumValue(productType)) {
|
|
62
|
-
const a = (0, product_inputs_1.
|
|
63
|
-
return [a.
|
|
63
|
+
const a = (0, product_inputs_1.shippedValuationInputTypes)().require(productType, couponType);
|
|
64
|
+
return [a.inputType, [...a.requires]];
|
|
64
65
|
}
|
|
65
66
|
const s = security(productType, couponType);
|
|
66
|
-
return [(0, product_inputs_1.
|
|
67
|
+
return [(0, product_inputs_1.inputTypeFor)(s), (0, product_inputs_1.requiredMarketData)(s)];
|
|
67
68
|
}
|
|
68
69
|
function catchUnmapped(fn) {
|
|
69
70
|
try {
|
|
@@ -76,7 +77,7 @@ function catchUnmapped(fn) {
|
|
|
76
77
|
}
|
|
77
78
|
throw new Error('expected UnmappedProductTypeError');
|
|
78
79
|
}
|
|
79
|
-
describe('
|
|
80
|
+
describe('valuation_input_types shared fixture (metric 1)', () => {
|
|
80
81
|
test('has the required cases', () => {
|
|
81
82
|
expect(cases.length).toBeGreaterThanOrEqual(5);
|
|
82
83
|
const seen = cases.map(c => `${c.product_type}/${c.coupon_type}`);
|
|
@@ -91,7 +92,7 @@ describe('valuation_arms shared fixture (metric 1)', () => {
|
|
|
91
92
|
expect([e.productType, e.couponType]).toEqual([c.product_type, c.coupon_type]);
|
|
92
93
|
}
|
|
93
94
|
else {
|
|
94
|
-
expect(resolve(c.product_type, c.coupon_type)).toEqual([c.
|
|
95
|
+
expect(resolve(c.product_type, c.coupon_type)).toEqual([c.input_type, c.requires]);
|
|
95
96
|
}
|
|
96
97
|
});
|
|
97
98
|
});
|
|
@@ -114,7 +115,7 @@ describe('unmapped types raise (metric 2)', () => {
|
|
|
114
115
|
});
|
|
115
116
|
test('message names product and coupon type', () => {
|
|
116
117
|
const gold = security('GOLD', 'FLOAT');
|
|
117
|
-
const e = catchUnmapped(() => (0, product_inputs_1.
|
|
118
|
+
const e = catchUnmapped(() => (0, product_inputs_1.inputTypeFor)(gold));
|
|
118
119
|
expect(e.message).toContain('GOLD');
|
|
119
120
|
expect(e.message).toContain('FLOAT');
|
|
120
121
|
expect(() => (0, product_inputs_1.requiredMarketData)(gold)).toThrow(errors_1.UnmappedProductTypeError);
|
|
@@ -122,40 +123,66 @@ describe('unmapped types raise (metric 2)', () => {
|
|
|
122
123
|
test('unset bond_details reads as UNKNOWN_COUPON_TYPE', () => {
|
|
123
124
|
const corp = new security_pb_1.SecurityProto();
|
|
124
125
|
corp.setProductType(product_type_pb_1.ProductTypeProto.CORP_BOND);
|
|
125
|
-
expect((0, product_inputs_1.
|
|
126
|
+
expect((0, product_inputs_1.inputTypeFor)(corp)).toBe('bond');
|
|
126
127
|
const fx = new security_pb_1.SecurityProto();
|
|
127
128
|
fx.setProductType(product_type_pb_1.ProductTypeProto.FX_SPOT);
|
|
128
|
-
expect(catchUnmapped(() => (0, product_inputs_1.
|
|
129
|
+
expect(catchUnmapped(() => (0, product_inputs_1.inputTypeFor)(fx)).couponType).toBe('UNKNOWN_COUPON_TYPE');
|
|
129
130
|
});
|
|
130
131
|
});
|
|
131
|
-
|
|
132
|
+
describe('LM-411: every ProductTypeProto value maps to an input type or raises', () => {
|
|
133
|
+
const inputTypes = Object.keys(product_inputs_pb_1.ProductInput.InputCase)
|
|
134
|
+
.filter(k => k !== 'INPUT_NOT_SET')
|
|
135
|
+
.map(k => k.toLowerCase());
|
|
136
|
+
test.each(Object.keys(product_type_pb_1.ProductTypeProto))('%s', pt => {
|
|
137
|
+
const s = new security_pb_1.SecurityProto();
|
|
138
|
+
s.setProductType(product_type_pb_1.ProductTypeProto[pt]);
|
|
139
|
+
let inputType;
|
|
140
|
+
try {
|
|
141
|
+
inputType = (0, product_inputs_1.inputTypeFor)(s);
|
|
142
|
+
}
|
|
143
|
+
catch (e) {
|
|
144
|
+
if (!(e instanceof errors_1.UnmappedProductTypeError))
|
|
145
|
+
throw e;
|
|
146
|
+
expect(e.productType).toBe(pt);
|
|
147
|
+
expect(e.message).toContain(pt);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
expect(inputTypes).toContain(inputType);
|
|
151
|
+
});
|
|
152
|
+
test('PRODUCT_TYPE_UNKNOWN raises', () => {
|
|
153
|
+
const s = new security_pb_1.SecurityProto();
|
|
154
|
+
s.setProductType(product_type_pb_1.ProductTypeProto.PRODUCT_TYPE_UNKNOWN);
|
|
155
|
+
expect(catchUnmapped(() => (0, product_inputs_1.inputTypeFor)(s)).message).toContain('PRODUCT_TYPE_UNKNOWN');
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
test('bundled valuation_input_types equals the source (metric 4)', () => {
|
|
132
159
|
expect(fs.existsSync(BUNDLED)).toBe(true);
|
|
133
160
|
const bundled = JSON.parse(fs.readFileSync(BUNDLED, 'utf-8'));
|
|
134
|
-
expect(bundled.
|
|
135
|
-
expect(bundled.
|
|
161
|
+
expect(bundled.valuation_input_types).toBeDefined();
|
|
162
|
+
expect(bundled.valuation_input_types).toEqual(sourceSection());
|
|
136
163
|
});
|
|
137
164
|
test('parse rejects a requires value outside the vocabulary (metric 5)', () => {
|
|
138
165
|
const section = sourceSection();
|
|
139
166
|
section.entries[0].requires.push('FX_RATE');
|
|
140
|
-
expect(() => (0, product_inputs_1.
|
|
167
|
+
expect(() => (0, product_inputs_1.parseValuationInputTypes)(section)).toThrow(/FX_RATE/);
|
|
141
168
|
});
|
|
142
169
|
test('every leaf is covered (metric 3)', () => {
|
|
143
|
-
expect((0, product_inputs_1.
|
|
170
|
+
expect((0, product_inputs_1.shippedValuationInputTypes)().uncoveredLeaves()).toEqual([]);
|
|
144
171
|
});
|
|
145
|
-
// ---------- LM-427:
|
|
146
|
-
describe('
|
|
147
|
-
const
|
|
148
|
-
const fixture = JSON.parse(fs.readFileSync(path.resolve(PROTOS, '../test-fixtures/catalog/measures-for-
|
|
149
|
-
const names = (
|
|
150
|
-
test('fixture lists the six
|
|
151
|
-
expect(Object.keys(fixture.
|
|
152
|
-
for (const
|
|
153
|
-
expect(fixture.
|
|
172
|
+
// ---------- LM-427: measuresForInputType ----------
|
|
173
|
+
describe('measuresForInputType', () => {
|
|
174
|
+
const INPUT_TYPES = ['bond', 'tips', 'frn', 'mbs', 'equity', 'cash'];
|
|
175
|
+
const fixture = JSON.parse(fs.readFileSync(path.resolve(PROTOS, '../test-fixtures/catalog/measures-for-input-type.json'), 'utf-8'));
|
|
176
|
+
const names = (inputType) => (0, product_inputs_1.measuresForInputType)(inputType).map(m => Object.keys(measure_pb_1.MeasureProto).find(k => measure_pb_1.MeasureProto[k] === m));
|
|
177
|
+
test('fixture lists the six input types, none empty', () => {
|
|
178
|
+
expect(Object.keys(fixture.input_types).sort()).toEqual([...INPUT_TYPES].sort());
|
|
179
|
+
for (const inputType of INPUT_TYPES)
|
|
180
|
+
expect(fixture.input_types[inputType].length).toBeGreaterThan(0);
|
|
154
181
|
});
|
|
155
|
-
test.each(
|
|
156
|
-
const got = names(
|
|
182
|
+
test.each(INPUT_TYPES)('%s matches the shared fixture', inputType => {
|
|
183
|
+
const got = names(inputType);
|
|
157
184
|
expect(new Set(got).size).toBe(got.length);
|
|
158
|
-
expect([...got].sort()).toEqual([...fixture.
|
|
185
|
+
expect([...got].sort()).toEqual([...fixture.input_types[inputType]].sort());
|
|
159
186
|
});
|
|
160
187
|
test('frn and tips', () => {
|
|
161
188
|
const frn = names('frn');
|
|
@@ -164,10 +191,10 @@ describe('measuresForArm', () => {
|
|
|
164
191
|
}
|
|
165
192
|
expect(names('tips')).toEqual(expect.arrayContaining(['REFERENCE_CPI', 'INDEX_RATIO']));
|
|
166
193
|
});
|
|
167
|
-
test('an unknown
|
|
194
|
+
test('an unknown input type throws UnmappedProductTypeError', () => {
|
|
168
195
|
let error;
|
|
169
196
|
try {
|
|
170
|
-
(0, product_inputs_1.
|
|
197
|
+
(0, product_inputs_1.measuresForInputType)(fixture.unknown_input_type);
|
|
171
198
|
}
|
|
172
199
|
catch (e) {
|
|
173
200
|
error = e;
|
|
@@ -182,15 +209,15 @@ describe('measuresForArm', () => {
|
|
|
182
209
|
return measures.map(m => (m.name === name ? Object.assign(Object.assign({}, m), fields) : m));
|
|
183
210
|
}
|
|
184
211
|
test('follows implemented', () => {
|
|
185
|
-
expect((0, product_inputs_1.
|
|
186
|
-
expect((0, product_inputs_1.
|
|
212
|
+
expect((0, product_inputs_1.measuresForInputType)('frn')).toContain(measure_pb_1.MeasureProto.DISCOUNT_MARGIN);
|
|
213
|
+
expect((0, product_inputs_1.measuresForInputTypeIn)(catalogWith('DISCOUNT_MARGIN', { implemented: false }), 'frn'))
|
|
187
214
|
.not.toContain(measure_pb_1.MeasureProto.DISCOUNT_MARGIN);
|
|
188
215
|
});
|
|
189
216
|
test('follows an ancestor node', () => {
|
|
190
217
|
const measures = catalogWith('PAR_YIELD', { implemented: true, applies_to: ['GOV_BOND'] });
|
|
191
|
-
for (const
|
|
192
|
-
expect((0, product_inputs_1.
|
|
193
|
-
expect((0, product_inputs_1.
|
|
218
|
+
for (const inputType of ['frn', 'bond']) {
|
|
219
|
+
expect((0, product_inputs_1.measuresForInputType)(inputType)).not.toContain(measure_pb_1.MeasureProto.PAR_YIELD);
|
|
220
|
+
expect((0, product_inputs_1.measuresForInputTypeIn)(measures, inputType)).toContain(measure_pb_1.MeasureProto.PAR_YIELD);
|
|
194
221
|
}
|
|
195
222
|
});
|
|
196
223
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product_inputs.test.js","sourceRoot":"","sources":["product_inputs.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;GAMG;AACH,uCAAyB;AACzB,2CAA6B;AAE7B,
|
|
1
|
+
{"version":3,"file":"product_inputs.test.js","sourceRoot":"","sources":["product_inputs.test.ts"],"names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M,CAAC,IAAA,uCAAsB,EAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,yBAAY,CAAC,SAAS,CAAC,CAAC;SACvF;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* LM-409:
|
|
2
|
+
* LM-409: valuation_input_types in hierarchy.json, resolved by inputTypeFor /
|
|
3
3
|
* requiredMarketData.
|
|
4
4
|
*
|
|
5
|
-
* The shared cases live in ledger-models-protos/fixtures/
|
|
5
|
+
* The shared cases live in ledger-models-protos/fixtures/valuation_input_types_cases.json,
|
|
6
6
|
* read by the Java, Python and Rust tests too.
|
|
7
7
|
*/
|
|
8
8
|
import * as fs from 'fs';
|
|
9
9
|
import * as path from 'path';
|
|
10
10
|
|
|
11
11
|
import {
|
|
12
|
-
|
|
12
|
+
inputTypeFor, measuresForInputType, measuresForInputTypeIn, parseValuationInputTypes, requiredMarketData,
|
|
13
|
+
shippedValuationInputTypes,
|
|
13
14
|
} from './product_inputs';
|
|
14
15
|
import { descendantsOf } from './product_hierarchy';
|
|
15
16
|
import { UnmappedProductTypeError } from '../errors';
|
|
@@ -17,6 +18,7 @@ import { MeasureProto } from '../../../fintekkers/models/position/measure_pb';
|
|
|
17
18
|
import { CouponTypeProto } from '../../../fintekkers/models/security/coupon_type_pb';
|
|
18
19
|
import { ProductTypeProto } from '../../../fintekkers/models/security/product_type_pb';
|
|
19
20
|
import { BondDetailsProto, SecurityProto } from '../../../fintekkers/models/security/security_pb';
|
|
21
|
+
import { ProductInput } from '../../../fintekkers/requests/valuation/product_inputs_pb';
|
|
20
22
|
|
|
21
23
|
const PROTOS = path.resolve(__dirname, '../../../../../ledger-models-protos');
|
|
22
24
|
const BUNDLED = path.resolve(__dirname, '../../../../hierarchy.json');
|
|
@@ -24,17 +26,17 @@ const BUNDLED = path.resolve(__dirname, '../../../../hierarchy.json');
|
|
|
24
26
|
interface Case {
|
|
25
27
|
product_type: string;
|
|
26
28
|
coupon_type: string;
|
|
27
|
-
|
|
29
|
+
input_type?: string;
|
|
28
30
|
requires?: string[];
|
|
29
31
|
error?: string;
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
const cases: Case[] = JSON.parse(
|
|
33
|
-
fs.readFileSync(path.join(PROTOS, 'fixtures/
|
|
35
|
+
fs.readFileSync(path.join(PROTOS, 'fixtures/valuation_input_types_cases.json'), 'utf-8'),
|
|
34
36
|
).cases;
|
|
35
37
|
|
|
36
38
|
function sourceSection(): any {
|
|
37
|
-
return JSON.parse(fs.readFileSync(path.join(PROTOS, 'hierarchy.json'), 'utf-8')).
|
|
39
|
+
return JSON.parse(fs.readFileSync(path.join(PROTOS, 'hierarchy.json'), 'utf-8')).valuation_input_types;
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
function hasEnumValue(productType: string): boolean {
|
|
@@ -50,14 +52,14 @@ function security(productType: string, couponType: string): SecurityProto {
|
|
|
50
52
|
return s;
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
/** [
|
|
55
|
+
/** [input type, requires] through a real proto when the type has an enum value; planned leaves by name. */
|
|
54
56
|
function resolve(productType: string, couponType: string): [string, string[]] {
|
|
55
57
|
if (!hasEnumValue(productType)) {
|
|
56
|
-
const a =
|
|
57
|
-
return [a.
|
|
58
|
+
const a = shippedValuationInputTypes().require(productType, couponType);
|
|
59
|
+
return [a.inputType, [...a.requires]];
|
|
58
60
|
}
|
|
59
61
|
const s = security(productType, couponType);
|
|
60
|
-
return [
|
|
62
|
+
return [inputTypeFor(s), requiredMarketData(s)];
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
function catchUnmapped(fn: () => unknown): UnmappedProductTypeError {
|
|
@@ -70,7 +72,7 @@ function catchUnmapped(fn: () => unknown): UnmappedProductTypeError {
|
|
|
70
72
|
throw new Error('expected UnmappedProductTypeError');
|
|
71
73
|
}
|
|
72
74
|
|
|
73
|
-
describe('
|
|
75
|
+
describe('valuation_input_types shared fixture (metric 1)', () => {
|
|
74
76
|
test('has the required cases', () => {
|
|
75
77
|
expect(cases.length).toBeGreaterThanOrEqual(5);
|
|
76
78
|
const seen = cases.map(c => `${c.product_type}/${c.coupon_type}`);
|
|
@@ -85,7 +87,7 @@ describe('valuation_arms shared fixture (metric 1)', () => {
|
|
|
85
87
|
const e = catchUnmapped(() => resolve(c.product_type, c.coupon_type));
|
|
86
88
|
expect([e.productType, e.couponType]).toEqual([c.product_type, c.coupon_type]);
|
|
87
89
|
} else {
|
|
88
|
-
expect(resolve(c.product_type, c.coupon_type)).toEqual([c.
|
|
90
|
+
expect(resolve(c.product_type, c.coupon_type)).toEqual([c.input_type, c.requires]);
|
|
89
91
|
}
|
|
90
92
|
});
|
|
91
93
|
});
|
|
@@ -110,7 +112,7 @@ describe('unmapped types raise (metric 2)', () => {
|
|
|
110
112
|
|
|
111
113
|
test('message names product and coupon type', () => {
|
|
112
114
|
const gold = security('GOLD', 'FLOAT');
|
|
113
|
-
const e = catchUnmapped(() =>
|
|
115
|
+
const e = catchUnmapped(() => inputTypeFor(gold));
|
|
114
116
|
expect(e.message).toContain('GOLD');
|
|
115
117
|
expect(e.message).toContain('FLOAT');
|
|
116
118
|
expect(() => requiredMarketData(gold)).toThrow(UnmappedProductTypeError);
|
|
@@ -119,49 +121,76 @@ describe('unmapped types raise (metric 2)', () => {
|
|
|
119
121
|
test('unset bond_details reads as UNKNOWN_COUPON_TYPE', () => {
|
|
120
122
|
const corp = new SecurityProto();
|
|
121
123
|
corp.setProductType(ProductTypeProto.CORP_BOND);
|
|
122
|
-
expect(
|
|
124
|
+
expect(inputTypeFor(corp)).toBe('bond');
|
|
123
125
|
const fx = new SecurityProto();
|
|
124
126
|
fx.setProductType(ProductTypeProto.FX_SPOT);
|
|
125
|
-
expect(catchUnmapped(() =>
|
|
127
|
+
expect(catchUnmapped(() => inputTypeFor(fx)).couponType).toBe('UNKNOWN_COUPON_TYPE');
|
|
126
128
|
});
|
|
127
129
|
});
|
|
128
130
|
|
|
129
|
-
|
|
131
|
+
describe('LM-411: every ProductTypeProto value maps to an input type or raises', () => {
|
|
132
|
+
const inputTypes = Object.keys(ProductInput.InputCase)
|
|
133
|
+
.filter(k => k !== 'INPUT_NOT_SET')
|
|
134
|
+
.map(k => k.toLowerCase());
|
|
135
|
+
|
|
136
|
+
test.each(Object.keys(ProductTypeProto))('%s', pt => {
|
|
137
|
+
const s = new SecurityProto();
|
|
138
|
+
s.setProductType(ProductTypeProto[pt as keyof typeof ProductTypeProto]);
|
|
139
|
+
let inputType: string;
|
|
140
|
+
try {
|
|
141
|
+
inputType = inputTypeFor(s);
|
|
142
|
+
} catch (e) {
|
|
143
|
+
if (!(e instanceof UnmappedProductTypeError)) throw e;
|
|
144
|
+
expect(e.productType).toBe(pt);
|
|
145
|
+
expect(e.message).toContain(pt);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
expect(inputTypes).toContain(inputType);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test('PRODUCT_TYPE_UNKNOWN raises', () => {
|
|
152
|
+
const s = new SecurityProto();
|
|
153
|
+
s.setProductType(ProductTypeProto.PRODUCT_TYPE_UNKNOWN);
|
|
154
|
+
expect(catchUnmapped(() => inputTypeFor(s)).message).toContain('PRODUCT_TYPE_UNKNOWN');
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test('bundled valuation_input_types equals the source (metric 4)', () => {
|
|
130
159
|
expect(fs.existsSync(BUNDLED)).toBe(true);
|
|
131
160
|
const bundled = JSON.parse(fs.readFileSync(BUNDLED, 'utf-8'));
|
|
132
|
-
expect(bundled.
|
|
133
|
-
expect(bundled.
|
|
161
|
+
expect(bundled.valuation_input_types).toBeDefined();
|
|
162
|
+
expect(bundled.valuation_input_types).toEqual(sourceSection());
|
|
134
163
|
});
|
|
135
164
|
|
|
136
165
|
test('parse rejects a requires value outside the vocabulary (metric 5)', () => {
|
|
137
166
|
const section = sourceSection();
|
|
138
167
|
section.entries[0].requires.push('FX_RATE');
|
|
139
|
-
expect(() =>
|
|
168
|
+
expect(() => parseValuationInputTypes(section)).toThrow(/FX_RATE/);
|
|
140
169
|
});
|
|
141
170
|
|
|
142
171
|
test('every leaf is covered (metric 3)', () => {
|
|
143
|
-
expect(
|
|
172
|
+
expect(shippedValuationInputTypes().uncoveredLeaves()).toEqual([]);
|
|
144
173
|
});
|
|
145
174
|
|
|
146
|
-
// ---------- LM-427:
|
|
175
|
+
// ---------- LM-427: measuresForInputType ----------
|
|
147
176
|
|
|
148
|
-
describe('
|
|
149
|
-
const
|
|
150
|
-
const fixture: {
|
|
151
|
-
fs.readFileSync(path.resolve(PROTOS, '../test-fixtures/catalog/measures-for-
|
|
177
|
+
describe('measuresForInputType', () => {
|
|
178
|
+
const INPUT_TYPES = ['bond', 'tips', 'frn', 'mbs', 'equity', 'cash'];
|
|
179
|
+
const fixture: { input_types: Record<string, string[]>; unknown_input_type: string } = JSON.parse(
|
|
180
|
+
fs.readFileSync(path.resolve(PROTOS, '../test-fixtures/catalog/measures-for-input-type.json'), 'utf-8'),
|
|
152
181
|
);
|
|
153
|
-
const names = (
|
|
154
|
-
|
|
182
|
+
const names = (inputType: string): string[] =>
|
|
183
|
+
measuresForInputType(inputType).map(m => Object.keys(MeasureProto).find(k => (MeasureProto as any)[k] === m)!);
|
|
155
184
|
|
|
156
|
-
test('fixture lists the six
|
|
157
|
-
expect(Object.keys(fixture.
|
|
158
|
-
for (const
|
|
185
|
+
test('fixture lists the six input types, none empty', () => {
|
|
186
|
+
expect(Object.keys(fixture.input_types).sort()).toEqual([...INPUT_TYPES].sort());
|
|
187
|
+
for (const inputType of INPUT_TYPES) expect(fixture.input_types[inputType].length).toBeGreaterThan(0);
|
|
159
188
|
});
|
|
160
189
|
|
|
161
|
-
test.each(
|
|
162
|
-
const got = names(
|
|
190
|
+
test.each(INPUT_TYPES)('%s matches the shared fixture', inputType => {
|
|
191
|
+
const got = names(inputType);
|
|
163
192
|
expect(new Set(got).size).toBe(got.length);
|
|
164
|
-
expect([...got].sort()).toEqual([...fixture.
|
|
193
|
+
expect([...got].sort()).toEqual([...fixture.input_types[inputType]].sort());
|
|
165
194
|
});
|
|
166
195
|
|
|
167
196
|
test('frn and tips', () => {
|
|
@@ -172,10 +201,10 @@ describe('measuresForArm', () => {
|
|
|
172
201
|
expect(names('tips')).toEqual(expect.arrayContaining(['REFERENCE_CPI', 'INDEX_RATIO']));
|
|
173
202
|
});
|
|
174
203
|
|
|
175
|
-
test('an unknown
|
|
204
|
+
test('an unknown input type throws UnmappedProductTypeError', () => {
|
|
176
205
|
let error: unknown;
|
|
177
206
|
try {
|
|
178
|
-
|
|
207
|
+
measuresForInputType(fixture.unknown_input_type);
|
|
179
208
|
} catch (e) {
|
|
180
209
|
error = e;
|
|
181
210
|
}
|
|
@@ -193,16 +222,16 @@ describe('measuresForArm', () => {
|
|
|
193
222
|
}
|
|
194
223
|
|
|
195
224
|
test('follows implemented', () => {
|
|
196
|
-
expect(
|
|
197
|
-
expect(
|
|
225
|
+
expect(measuresForInputType('frn')).toContain(MeasureProto.DISCOUNT_MARGIN);
|
|
226
|
+
expect(measuresForInputTypeIn(catalogWith('DISCOUNT_MARGIN', { implemented: false }), 'frn'))
|
|
198
227
|
.not.toContain(MeasureProto.DISCOUNT_MARGIN);
|
|
199
228
|
});
|
|
200
229
|
|
|
201
230
|
test('follows an ancestor node', () => {
|
|
202
231
|
const measures = catalogWith('PAR_YIELD', { implemented: true, applies_to: ['GOV_BOND'] });
|
|
203
|
-
for (const
|
|
204
|
-
expect(
|
|
205
|
-
expect(
|
|
232
|
+
for (const inputType of ['frn', 'bond']) {
|
|
233
|
+
expect(measuresForInputType(inputType)).not.toContain(MeasureProto.PAR_YIELD);
|
|
234
|
+
expect(measuresForInputTypeIn(measures, inputType)).toContain(MeasureProto.PAR_YIELD);
|
|
206
235
|
}
|
|
207
236
|
});
|
|
208
237
|
});
|