@barchart/portfolio-api-common 1.0.96 → 1.0.97

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.
@@ -4,7 +4,8 @@ const Currency = require('@barchart/common-js/lang/Currency'),
4
4
  const InstrumentType = require('./../../../lib/data/InstrumentType');
5
5
 
6
6
  const PositionContainer = require('./../../../lib/processing/PositionContainer'),
7
- PositionGroupDefinition = require('./../../../lib/processing/PositionGroupDefinition');
7
+ PositionLevelDefinition = require('./../../../lib/processing/definitions/PositionLevelDefinition'),
8
+ PositionTreeDefinition = require('./../../../lib/processing/definitions/PositionTreeDefinition');
8
9
 
9
10
  describe('When a position container data is gathered', () => {
10
11
  'use strict';
@@ -58,45 +59,48 @@ describe('When a position container data is gathered', () => {
58
59
  });
59
60
 
60
61
  describe('and a container is created grouping by total, portfolio, and instrument', () => {
62
+ let name;
61
63
  let definitions;
62
64
  let container;
63
65
 
64
66
  beforeEach(() => {
65
67
  definitions = [
66
- new PositionGroupDefinition('Total', x => true, x => 'Total', x => Currency.CAD),
67
- new PositionGroupDefinition('Portfolio', x => x.portfolio.portfolio, x => x.portfolio.name, x => Currency.CAD),
68
- new PositionGroupDefinition('Position', x => x.position.position, x => x.position.instrument.symbol.barchart, x => x.position.instrument.currency)
68
+ new PositionTreeDefinition(name = 'the only tree', [
69
+ new PositionLevelDefinition('Total', x => true, x => 'Total', x => Currency.CAD),
70
+ new PositionLevelDefinition('Portfolio', x => x.portfolio.portfolio, x => x.portfolio.name, x => Currency.CAD),
71
+ new PositionLevelDefinition('Position', x => x.position.position, x => x.position.instrument.symbol.barchart, x => x.position.instrument.currency)
72
+ ])
69
73
  ];
70
74
 
71
75
  try {
72
- container = new PositionContainer(portfolios, positions, summaries, definitions);
76
+ container = new PositionContainer(definitions, portfolios, positions, summaries);
73
77
  } catch (e) {
74
78
  console.log(e);
75
79
  }
76
80
  });
77
81
 
78
82
  it('the "Total" group should have two children groups', () => {
79
- expect(container.getGroups([ 'Total' ]).length).toEqual(2);
83
+ expect(container.getGroups(name, [ 'Total' ]).length).toEqual(2);
80
84
  });
81
85
 
82
86
  it('the "Total" group should have three items', () => {
83
- expect(container.getGroup([ 'Total' ]).items.length).toEqual(3);
87
+ expect(container.getGroup(name, [ 'Total' ]).items.length).toEqual(3);
84
88
  });
85
89
 
86
90
  it('The "a" portfolio group should have one child group', () => {
87
- expect(container.getGroups([ 'Total', 'a' ]).length).toEqual(1);
91
+ expect(container.getGroups(name, [ 'Total', 'a' ]).length).toEqual(1);
88
92
  });
89
93
 
90
94
  it('the "a" portfolio group should have one item', () => {
91
- expect(container.getGroup([ 'Total', 'a' ]).items.length).toEqual(1);
95
+ expect(container.getGroup(name, [ 'Total', 'a' ]).items.length).toEqual(1);
92
96
  });
93
97
 
94
98
  it('The "b" portfolio group should have two child groups', () => {
95
- expect(container.getGroups([ 'Total', 'b' ]).length).toEqual(2);
99
+ expect(container.getGroups(name, [ 'Total', 'b' ]).length).toEqual(2);
96
100
  });
97
101
 
98
102
  it('the "b" portfolio group should have two items', () => {
99
- expect(container.getGroup([ 'Total', 'b' ]).items.length).toEqual(2);
103
+ expect(container.getGroup(name, [ 'Total', 'b' ]).items.length).toEqual(2);
100
104
  });
101
105
  });
102
106
  });
@@ -1,48 +0,0 @@
1
- const assert = require('@barchart/common-js/lang/assert'),
2
- is = require('@barchart/common-js/lang/is');
3
-
4
- module.exports = (() => {
5
- 'use strict';
6
-
7
- /**
8
- * @public
9
- */
10
- class PositionGroupDefinition {
11
- constructor(name, keySelector, descriptionSelector, currencySelector, requiredGroups, single) {
12
- this._name = name;
13
-
14
- this._keySelector = keySelector;
15
- this._descriptionSelector = descriptionSelector;
16
- this._currencySelector = currencySelector;
17
-
18
- this._requiredGroups = requiredGroups || [ ];
19
- this._single = is.boolean(single) && single;
20
- }
21
-
22
- get name() {
23
- return this._name;
24
- }
25
-
26
- get keySelector() {
27
- return this._keySelector;
28
- }
29
-
30
- get descriptionSelector() {
31
- return this._descriptionSelector;
32
- }
33
-
34
- get currencySelector() {
35
- return this._currencySelector;
36
- }
37
-
38
- get requiredGroups() {
39
- return this._requiredGroups;
40
- }
41
-
42
- toString() {
43
- return '[PositionGroupDefinition]';
44
- }
45
- }
46
-
47
- return PositionGroupDefinition;
48
- })();