@barchart/portfolio-api-common 1.0.34 → 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.
@@ -310,4 +310,46 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
310
310
  expect(ranges[0].end.format()).toEqual('2018-12-31');
311
311
  });
312
312
  });
313
+
314
+ describe('and getting the start date for yearly frames', () => {
315
+ describe('for one year ago', function() {
316
+ let start;
317
+
318
+ beforeEach(() => {
319
+ start = PositionSummaryFrame.YEARLY.getStartDate(1);
320
+ });
321
+
322
+ it('should be in December', () => {
323
+ expect(start.month).toEqual(12);
324
+ });
325
+
326
+ it('should be on the 31st', () => {
327
+ expect(start.day).toEqual(31);
328
+ });
329
+
330
+ it('should be two years ago', () => {
331
+ expect(start.year).toEqual(Day.getToday().year - 2);
332
+ });
333
+ });
334
+
335
+ describe('for two years ago', function() {
336
+ let start;
337
+
338
+ beforeEach(() => {
339
+ start = PositionSummaryFrame.YEARLY.getStartDate(2);
340
+ });
341
+
342
+ it('should be in December', () => {
343
+ expect(start.month).toEqual(12);
344
+ });
345
+
346
+ it('should be on the 31st', () => {
347
+ expect(start.day).toEqual(31);
348
+ });
349
+
350
+ it('should be two years ago', () => {
351
+ expect(start.year).toEqual(Day.getToday().year - 3);
352
+ });
353
+ });
354
+ });
313
355
  });
@@ -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
+ });