@barchart/portfolio-api-common 1.2.53 → 1.2.54
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.
|
@@ -395,7 +395,7 @@ module.exports = (() => {
|
|
|
395
395
|
const sell = new TransactionType('S', 'Sell', 'Sell', 0, false, true, false, false, true, false, false, false, true);
|
|
396
396
|
const buyShort = new TransactionType('BS', 'Buy To Cover', 'Buy To Cover', 0, true, false, false, false, true, false, false, false, true);
|
|
397
397
|
const sellShort = new TransactionType('SS', 'Sell Short', 'Sell Short', 0, false, true, false, true, false, false, false, true, true);
|
|
398
|
-
const dividend = new TransactionType('DV', 'Dividend', 'Dividend',
|
|
398
|
+
const dividend = new TransactionType('DV', 'Dividend', 'Dividend', 1, false, false, true, false, false, false, true, false, false);
|
|
399
399
|
const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', 'Dividend Reinvest', 1, false, false, false, true, false, false, true, false, false);
|
|
400
400
|
const dividendStock = new TransactionType('DS', 'Dividend (Stock)', 'Dividend Stock', 1, false, false, false, true, false, false, true, false, false);
|
|
401
401
|
const split = new TransactionType('SP', 'Split', 'Split', 1, false, false, false, true, false, false, true, false, false);
|
|
@@ -82,7 +82,7 @@ module.exports = (() => {
|
|
|
82
82
|
static getInvalidIndex(transactions) {
|
|
83
83
|
assert.argumentIsArray(transactions, 'transactions');
|
|
84
84
|
|
|
85
|
-
return transactions.findIndex((t, i) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(
|
|
85
|
+
return transactions.findIndex((t, i, a) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(a[ i - 1 ].date)) || (i !== 0 && t.date.getIsEqual(a[i - 1].date) && t.type.sequence < a[i - 1].type.sequence));
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
/**
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -1018,7 +1018,7 @@ module.exports = (() => {
|
|
|
1018
1018
|
const sell = new TransactionType('S', 'Sell', 'Sell', 0, false, true, false, false, true, false, false, false, true);
|
|
1019
1019
|
const buyShort = new TransactionType('BS', 'Buy To Cover', 'Buy To Cover', 0, true, false, false, false, true, false, false, false, true);
|
|
1020
1020
|
const sellShort = new TransactionType('SS', 'Sell Short', 'Sell Short', 0, false, true, false, true, false, false, false, true, true);
|
|
1021
|
-
const dividend = new TransactionType('DV', 'Dividend', 'Dividend',
|
|
1021
|
+
const dividend = new TransactionType('DV', 'Dividend', 'Dividend', 1, false, false, true, false, false, false, true, false, false);
|
|
1022
1022
|
const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', 'Dividend Reinvest', 1, false, false, false, true, false, false, true, false, false);
|
|
1023
1023
|
const dividendStock = new TransactionType('DS', 'Dividend (Stock)', 'Dividend Stock', 1, false, false, false, true, false, false, true, false, false);
|
|
1024
1024
|
const split = new TransactionType('SP', 'Split', 'Split', 1, false, false, false, true, false, false, true, false, false);
|
|
@@ -1125,7 +1125,7 @@ module.exports = (() => {
|
|
|
1125
1125
|
static getInvalidIndex(transactions) {
|
|
1126
1126
|
assert.argumentIsArray(transactions, 'transactions');
|
|
1127
1127
|
|
|
1128
|
-
return transactions.findIndex((t, i) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(
|
|
1128
|
+
return transactions.findIndex((t, i, a) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(a[ i - 1 ].date)) || (i !== 0 && t.date.getIsEqual(a[i - 1].date) && t.type.sequence < a[i - 1].type.sequence));
|
|
1129
1129
|
}
|
|
1130
1130
|
|
|
1131
1131
|
/**
|
|
@@ -17212,13 +17212,14 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
|
|
|
17212
17212
|
},{"./../../../lib/data/PositionSummaryFrame":3,"./../../../lib/data/TransactionType":4,"@barchart/common-js/lang/Day":21,"@barchart/common-js/lang/Decimal":22}],53:[function(require,module,exports){
|
|
17213
17213
|
const Day = require('@barchart/common-js/lang/Day');
|
|
17214
17214
|
|
|
17215
|
-
const
|
|
17215
|
+
const TransactionType = require('./../../../lib/data/TransactionType'),
|
|
17216
|
+
TransactionValidator = require('./../../../lib/data/TransactionValidator');
|
|
17216
17217
|
|
|
17217
17218
|
describe('When validating transaction order', () => {
|
|
17218
17219
|
'use strict';
|
|
17219
17220
|
|
|
17220
|
-
const build = (sequence, day) => {
|
|
17221
|
-
return { sequence: sequence, date: Day.parse(day) };
|
|
17221
|
+
const build = (sequence, day, type) => {
|
|
17222
|
+
return { sequence: sequence, date: Day.parse(day), type: (type || TransactionType.BUY ) };
|
|
17222
17223
|
};
|
|
17223
17224
|
|
|
17224
17225
|
it('An array of zero transactions should be valid', () => {
|
|
@@ -17229,8 +17230,16 @@ describe('When validating transaction order', () => {
|
|
|
17229
17230
|
expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-04-30'), build(3, '2018-04-30') ])).toEqual(true);
|
|
17230
17231
|
});
|
|
17231
17232
|
|
|
17233
|
+
it('An array of transactions with ordered sequences, on the same day should be valid, where a dividend occurs last, should be valid', () => {
|
|
17234
|
+
expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-04-30', TransactionType.DIVIDEND) ])).toEqual(true);
|
|
17235
|
+
});
|
|
17236
|
+
|
|
17237
|
+
it('An array of transactions with ordered sequences, on the same day should be valid, where a dividend occurs first, should not be valid', () => {
|
|
17238
|
+
expect(TransactionValidator.validateOrder([ build(1, '2018-04-30', TransactionType.DIVIDEND), build(2, '2018-04-30') ])).toEqual(false);
|
|
17239
|
+
});
|
|
17240
|
+
|
|
17232
17241
|
it('An array of transactions with ordered sequences, on the sequential days should be valid', () => {
|
|
17233
|
-
expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-05-01'), build(3, '2018-05-02') ])).toEqual(true);
|
|
17242
|
+
expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-05-01'), build(3, '2018-05-02', TransactionType.DIVIDEND) ])).toEqual(true);
|
|
17234
17243
|
});
|
|
17235
17244
|
|
|
17236
17245
|
it('An array of transactions with ordered sequences (starting after one), on the same day should not be valid', () => {
|
|
@@ -17291,7 +17300,7 @@ describe('When requesting all the user-initiated transaction types', () => {
|
|
|
17291
17300
|
expect(userInitiated.length).toEqual(9);
|
|
17292
17301
|
});
|
|
17293
17302
|
});
|
|
17294
|
-
},{"./../../../lib/data/TransactionValidator":5,"@barchart/common-js/lang/Day":21}],54:[function(require,module,exports){
|
|
17303
|
+
},{"./../../../lib/data/TransactionType":4,"./../../../lib/data/TransactionValidator":5,"@barchart/common-js/lang/Day":21}],54:[function(require,module,exports){
|
|
17295
17304
|
const Currency = require('@barchart/common-js/lang/Currency'),
|
|
17296
17305
|
Decimal = require('@barchart/common-js/lang/Decimal');
|
|
17297
17306
|
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
const Day = require('@barchart/common-js/lang/Day');
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const TransactionType = require('./../../../lib/data/TransactionType'),
|
|
4
|
+
TransactionValidator = require('./../../../lib/data/TransactionValidator');
|
|
4
5
|
|
|
5
6
|
describe('When validating transaction order', () => {
|
|
6
7
|
'use strict';
|
|
7
8
|
|
|
8
|
-
const build = (sequence, day) => {
|
|
9
|
-
return { sequence: sequence, date: Day.parse(day) };
|
|
9
|
+
const build = (sequence, day, type) => {
|
|
10
|
+
return { sequence: sequence, date: Day.parse(day), type: (type || TransactionType.BUY ) };
|
|
10
11
|
};
|
|
11
12
|
|
|
12
13
|
it('An array of zero transactions should be valid', () => {
|
|
@@ -17,8 +18,16 @@ describe('When validating transaction order', () => {
|
|
|
17
18
|
expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-04-30'), build(3, '2018-04-30') ])).toEqual(true);
|
|
18
19
|
});
|
|
19
20
|
|
|
21
|
+
it('An array of transactions with ordered sequences, on the same day should be valid, where a dividend occurs last, should be valid', () => {
|
|
22
|
+
expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-04-30', TransactionType.DIVIDEND) ])).toEqual(true);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('An array of transactions with ordered sequences, on the same day should be valid, where a dividend occurs first, should not be valid', () => {
|
|
26
|
+
expect(TransactionValidator.validateOrder([ build(1, '2018-04-30', TransactionType.DIVIDEND), build(2, '2018-04-30') ])).toEqual(false);
|
|
27
|
+
});
|
|
28
|
+
|
|
20
29
|
it('An array of transactions with ordered sequences, on the sequential days should be valid', () => {
|
|
21
|
-
expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-05-01'), build(3, '2018-05-02') ])).toEqual(true);
|
|
30
|
+
expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-05-01'), build(3, '2018-05-02', TransactionType.DIVIDEND) ])).toEqual(true);
|
|
22
31
|
});
|
|
23
32
|
|
|
24
33
|
it('An array of transactions with ordered sequences (starting after one), on the same day should not be valid', () => {
|