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