@barchart/portfolio-api-common 1.0.37 → 1.0.39
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/lib/processing/PositionContainer.js +133 -0
- package/lib/processing/PositionGroup.js +66 -0
- package/lib/processing/PositionGroupDefinition.js +43 -0
- package/lib/processing/PositionItem.js +51 -0
- package/package.json +1 -1
- package/test/SpecRunner.js +1118 -68
- package/test/specs/processing/PositionContainerSpec.js +97 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
const PositionContainer = require('./../../../lib/processing/PositionContainer'),
|
|
2
|
+
PositionGroupDefinition = require('./../../../lib/processing/PositionGroupDefinition');
|
|
3
|
+
|
|
4
|
+
describe('When a position container data is gathered', () => {
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
describe('for two portfolios, each with the same position, and the second portfolio with an additonal position', () => {
|
|
8
|
+
let portfolios;
|
|
9
|
+
let positions;
|
|
10
|
+
let summaries;
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
portfolios = [
|
|
14
|
+
{
|
|
15
|
+
portfolio: 'a',
|
|
16
|
+
name: 'a'
|
|
17
|
+
}, {
|
|
18
|
+
portfolio: 'b',
|
|
19
|
+
name: 'b'
|
|
20
|
+
}
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
positions = [
|
|
24
|
+
{
|
|
25
|
+
portfolio: 'a',
|
|
26
|
+
position: '1',
|
|
27
|
+
instrument: {
|
|
28
|
+
symbol: {
|
|
29
|
+
barchart: 'AAPL'
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
}, {
|
|
33
|
+
portfolio: 'b',
|
|
34
|
+
position: '2',
|
|
35
|
+
instrument: {
|
|
36
|
+
symbol: {
|
|
37
|
+
barchart: 'AAPL'
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}, {
|
|
41
|
+
portfolio: 'b',
|
|
42
|
+
position: '3',
|
|
43
|
+
instrument: {
|
|
44
|
+
symbol: {
|
|
45
|
+
barchart: 'TSLA'
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
summaries = [ ];
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe('and a container is created grouping by total, portfolio, and instrument', () => {
|
|
55
|
+
let definitions;
|
|
56
|
+
let container;
|
|
57
|
+
|
|
58
|
+
beforeEach(() => {
|
|
59
|
+
definitions = [
|
|
60
|
+
new PositionGroupDefinition('Total', x => true, x => 'Total'),
|
|
61
|
+
new PositionGroupDefinition('Portfolio', x => x.portfolio.portfolio, x => x.portfolio.name),
|
|
62
|
+
new PositionGroupDefinition('Position', x => x.position.position, x => x.position.instrument.symbol.barchart)
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
try {
|
|
66
|
+
container = new PositionContainer(portfolios, positions, summaries, definitions);
|
|
67
|
+
} catch (e) {
|
|
68
|
+
console.log(e);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('the "Total" group should have two children groups', () => {
|
|
73
|
+
expect(container.getGroups([ 'Total' ]).length).toEqual(2);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('the "Total" group should have three items', () => {
|
|
77
|
+
expect(container.getGroup([ 'Total' ]).items.length).toEqual(3);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('The "a" portfolio group should have one child group', () => {
|
|
81
|
+
expect(container.getGroups([ 'Total', 'a' ]).length).toEqual(1);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('the "a" portfolio group should have one item', () => {
|
|
85
|
+
expect(container.getGroup([ 'Total', 'a' ]).items.length).toEqual(1);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('The "b" portfolio group should have two child groups', () => {
|
|
89
|
+
expect(container.getGroups([ 'Total', 'b' ]).length).toEqual(2);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('the "b" portfolio group should have two items', () => {
|
|
93
|
+
expect(container.getGroup([ 'Total', 'b' ]).items.length).toEqual(2);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
});
|