@barchart/portfolio-api-common 1.2.53 → 1.2.57

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.
@@ -19,10 +19,11 @@ module.exports = (() => {
19
19
  * @param {Boolean} canSwitchDirection
20
20
  * @param {Boolean} usesSymbols
21
21
  * @param {Boolean} hasCorporateActions
22
+ * @param {Number} closeFractional
22
23
  * @param {Function} generator
23
24
  */
24
25
  class InstrumentType extends Enum {
25
- constructor(code, description, alternateDescription, canReinvest, canShort, canSwitchDirection, usesSymbols, hasCorporateActions, generator) {
26
+ constructor(code, description, alternateDescription, canReinvest, canShort, canSwitchDirection, usesSymbols, hasCorporateActions, closeFractional, generator) {
26
27
  super(code, description);
27
28
 
28
29
  assert.argumentIsRequired(alternateDescription, 'alternateDescription', String);
@@ -31,6 +32,7 @@ module.exports = (() => {
31
32
  assert.argumentIsRequired(canSwitchDirection, 'canSwitchDirection', Boolean);
32
33
  assert.argumentIsRequired(usesSymbols, 'usesSymbols', Boolean);
33
34
  assert.argumentIsRequired(hasCorporateActions, 'hasCorporateActions', Boolean);
35
+ assert.argumentIsRequired(closeFractional, 'closeFractional', Boolean);
34
36
  assert.argumentIsRequired(generator, 'generator', Function);
35
37
 
36
38
  this._alternateDescription = alternateDescription;
@@ -39,6 +41,7 @@ module.exports = (() => {
39
41
  this._canSwitchDirection = canSwitchDirection;
40
42
  this._usesSymbols = usesSymbols;
41
43
  this._hasCorporateActions = hasCorporateActions;
44
+ this._closeFractional = closeFractional;
42
45
 
43
46
  this._generator = generator;
44
47
  }
@@ -104,6 +107,17 @@ module.exports = (() => {
104
107
  return this._hasCorporateActions;
105
108
  }
106
109
 
110
+ /**
111
+ * Indicates if fractional shares should be closed when the position
112
+ * size is less than one (or some of the fractional shares are closed).
113
+ *
114
+ * @public
115
+ * @returns {Boolean}
116
+ */
117
+ get closeFractional() {
118
+ return this._closeFractional;
119
+ }
120
+
107
121
  /**
108
122
  * Generates an identifier for the instrument.
109
123
  *
@@ -201,10 +215,10 @@ module.exports = (() => {
201
215
  }
202
216
  }
203
217
 
204
- const cash = new InstrumentType('CASH', 'cash', 'Cash', false, false, true, false, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.currency.code}`);
205
- const equity = new InstrumentType('EQUITY', 'equity', 'Equities', true, true, false, true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
206
- const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', true, false, false, true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
207
- const other = new InstrumentType('OTHER', 'other', 'Other', false, false, false, false, false, (instrument) => `BARCHART-${instrument.type.code}-${uuid.v4()}`);
218
+ const cash = new InstrumentType('CASH', 'cash', 'Cash', false, false, true, false, false, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.currency.code}`);
219
+ const equity = new InstrumentType('EQUITY', 'equity', 'Equities', true, true, false, true, true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
220
+ const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', true, false, false, true, true, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
221
+ const other = new InstrumentType('OTHER', 'other', 'Other', false, false, false, false, false, false, (instrument) => `BARCHART-${instrument.type.code}-${uuid.v4()}`);
208
222
 
209
223
  const map = { };
210
224
 
@@ -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', 0, false, false, true, false, false, false, true, false, false);
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,10 @@ 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(transactions[i - 1].date)));
85
+ return transactions.findIndex((t, i) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(transactions[i - 1].date)))
86
+
87
+ //return transactions.findIndex((t, i, a) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(a[ i - 1 ].date)));
88
+ //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
89
  }
87
90
 
88
91
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.2.53",
3
+ "version": "1.2.57",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -20,10 +20,11 @@ module.exports = (() => {
20
20
  * @param {Boolean} canSwitchDirection
21
21
  * @param {Boolean} usesSymbols
22
22
  * @param {Boolean} hasCorporateActions
23
+ * @param {Number} closeFractional
23
24
  * @param {Function} generator
24
25
  */
25
26
  class InstrumentType extends Enum {
26
- constructor(code, description, alternateDescription, canReinvest, canShort, canSwitchDirection, usesSymbols, hasCorporateActions, generator) {
27
+ constructor(code, description, alternateDescription, canReinvest, canShort, canSwitchDirection, usesSymbols, hasCorporateActions, closeFractional, generator) {
27
28
  super(code, description);
28
29
 
29
30
  assert.argumentIsRequired(alternateDescription, 'alternateDescription', String);
@@ -32,6 +33,7 @@ module.exports = (() => {
32
33
  assert.argumentIsRequired(canSwitchDirection, 'canSwitchDirection', Boolean);
33
34
  assert.argumentIsRequired(usesSymbols, 'usesSymbols', Boolean);
34
35
  assert.argumentIsRequired(hasCorporateActions, 'hasCorporateActions', Boolean);
36
+ assert.argumentIsRequired(closeFractional, 'closeFractional', Boolean);
35
37
  assert.argumentIsRequired(generator, 'generator', Function);
36
38
 
37
39
  this._alternateDescription = alternateDescription;
@@ -40,6 +42,7 @@ module.exports = (() => {
40
42
  this._canSwitchDirection = canSwitchDirection;
41
43
  this._usesSymbols = usesSymbols;
42
44
  this._hasCorporateActions = hasCorporateActions;
45
+ this._closeFractional = closeFractional;
43
46
 
44
47
  this._generator = generator;
45
48
  }
@@ -105,6 +108,17 @@ module.exports = (() => {
105
108
  return this._hasCorporateActions;
106
109
  }
107
110
 
111
+ /**
112
+ * Indicates if fractional shares should be closed when the position
113
+ * size is less than one (or some of the fractional shares are closed).
114
+ *
115
+ * @public
116
+ * @returns {Boolean}
117
+ */
118
+ get closeFractional() {
119
+ return this._closeFractional;
120
+ }
121
+
108
122
  /**
109
123
  * Generates an identifier for the instrument.
110
124
  *
@@ -202,10 +216,10 @@ module.exports = (() => {
202
216
  }
203
217
  }
204
218
 
205
- const cash = new InstrumentType('CASH', 'cash', 'Cash', false, false, true, false, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.currency.code}`);
206
- const equity = new InstrumentType('EQUITY', 'equity', 'Equities', true, true, false, true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
207
- const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', true, false, false, true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
208
- const other = new InstrumentType('OTHER', 'other', 'Other', false, false, false, false, false, (instrument) => `BARCHART-${instrument.type.code}-${uuid.v4()}`);
219
+ const cash = new InstrumentType('CASH', 'cash', 'Cash', false, false, true, false, false, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.currency.code}`);
220
+ const equity = new InstrumentType('EQUITY', 'equity', 'Equities', true, true, false, true, true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
221
+ const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', true, false, false, true, true, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
222
+ const other = new InstrumentType('OTHER', 'other', 'Other', false, false, false, false, false, false, (instrument) => `BARCHART-${instrument.type.code}-${uuid.v4()}`);
209
223
 
210
224
  const map = { };
211
225
 
@@ -1018,7 +1032,7 @@ module.exports = (() => {
1018
1032
  const sell = new TransactionType('S', 'Sell', 'Sell', 0, false, true, false, false, true, false, false, false, true);
1019
1033
  const buyShort = new TransactionType('BS', 'Buy To Cover', 'Buy To Cover', 0, true, false, false, false, true, false, false, false, true);
1020
1034
  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', 0, false, false, true, false, false, false, true, false, false);
1035
+ const dividend = new TransactionType('DV', 'Dividend', 'Dividend', 1, false, false, true, false, false, false, true, false, false);
1022
1036
  const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', 'Dividend Reinvest', 1, false, false, false, true, false, false, true, false, false);
1023
1037
  const dividendStock = new TransactionType('DS', 'Dividend (Stock)', 'Dividend Stock', 1, false, false, false, true, false, false, true, false, false);
1024
1038
  const split = new TransactionType('SP', 'Split', 'Split', 1, false, false, false, true, false, false, true, false, false);
@@ -1125,7 +1139,10 @@ module.exports = (() => {
1125
1139
  static getInvalidIndex(transactions) {
1126
1140
  assert.argumentIsArray(transactions, 'transactions');
1127
1141
 
1128
- return transactions.findIndex((t, i) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(transactions[i - 1].date)));
1142
+ return transactions.findIndex((t, i) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(transactions[i - 1].date)))
1143
+
1144
+ //return transactions.findIndex((t, i, a) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(a[ i - 1 ].date)));
1145
+ //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
1146
  }
1130
1147
 
1131
1148
  /**
@@ -5149,8 +5166,8 @@ module.exports = function () {
5149
5166
  * Compares two strings (in ascending order), using {@link String#localeCompare}.
5150
5167
  *
5151
5168
  * @static
5152
- * @param {Number} a
5153
- * @param {Number} b
5169
+ * @param {String} a
5170
+ * @param {String} b
5154
5171
  * @returns {Number}
5155
5172
  */
5156
5173
  compareStrings: function compareStrings(a, b) {
@@ -5840,7 +5857,7 @@ module.exports = function () {
5840
5857
  * @returns {String}
5841
5858
  */
5842
5859
  value: function format() {
5843
- return this._year + '-' + leftPad(this._month) + '-' + leftPad(this._day);
5860
+ return leftPad(this._year, 4, '0') + '-' + leftPad(this._month, 2, '0') + '-' + leftPad(this._day, 2, '0');
5844
5861
  }
5845
5862
 
5846
5863
  /**
@@ -5957,7 +5974,7 @@ module.exports = function () {
5957
5974
  *
5958
5975
  * @static
5959
5976
  * @public
5960
- * @return {Day}
5977
+ * @returns {Day}
5961
5978
  */
5962
5979
 
5963
5980
  }, {
@@ -6049,8 +6066,11 @@ module.exports = function () {
6049
6066
 
6050
6067
  var dayRegex = /^([0-9]{4}).?([0-9]{2}).?([0-9]{2})$/;
6051
6068
 
6052
- function leftPad(value) {
6053
- return value < 10 ? '0' + value : '' + value;
6069
+ function leftPad(value, digits, character) {
6070
+ var string = value.toString();
6071
+ var padding = digits - string.length;
6072
+
6073
+ return '' + character.repeat(padding) + string;
6054
6074
  }
6055
6075
 
6056
6076
  var comparator = ComparatorBuilder.startWith(function (a, b) {
@@ -6405,7 +6425,7 @@ module.exports = function () {
6405
6425
  *
6406
6426
  * @public
6407
6427
  * @param {Decimal} instance
6408
- * @return {Boolean}
6428
+ * @returns {Boolean}
6409
6429
  */
6410
6430
  value: function getIsZero(instance) {
6411
6431
  assert.argumentIsRequired(instance, 'instance', Decimal, 'Decimal');
@@ -6418,7 +6438,7 @@ module.exports = function () {
6418
6438
  *
6419
6439
  * @public
6420
6440
  * @param {Decimal} instance
6421
- * @return {Boolean}
6441
+ * @returns {Boolean}
6422
6442
  */
6423
6443
 
6424
6444
  }, {
@@ -6434,7 +6454,7 @@ module.exports = function () {
6434
6454
  *
6435
6455
  * @public
6436
6456
  * @param {Decimal} instance
6437
- * @return {Boolean}
6457
+ * @returns {Boolean}
6438
6458
  */
6439
6459
 
6440
6460
  }, {
@@ -6450,7 +6470,7 @@ module.exports = function () {
6450
6470
  *
6451
6471
  * @public
6452
6472
  * @param {Decimal} instance
6453
- * @return {Boolean}
6473
+ * @returns {Boolean}
6454
6474
  */
6455
6475
 
6456
6476
  }, {
@@ -6466,7 +6486,7 @@ module.exports = function () {
6466
6486
  *
6467
6487
  * @public
6468
6488
  * @param {Decimal} instance
6469
- * @return {Boolean}
6489
+ * @returns {Boolean}
6470
6490
  */
6471
6491
 
6472
6492
  }, {
@@ -6482,7 +6502,7 @@ module.exports = function () {
6482
6502
  *
6483
6503
  * @public
6484
6504
  * @param {Decimal} instance
6485
- * @return {Boolean}
6505
+ * @returns {Boolean}
6486
6506
  */
6487
6507
 
6488
6508
  }, {
@@ -6872,6 +6892,7 @@ module.exports = function () {
6872
6892
  /**
6873
6893
  * The unique code.
6874
6894
  *
6895
+ * @public
6875
6896
  * @returns {String}
6876
6897
  */
6877
6898
 
@@ -6884,6 +6905,7 @@ module.exports = function () {
6884
6905
  * Returns true if the provided {@link Enum} argument is equal
6885
6906
  * to the instance.
6886
6907
  *
6908
+ * @public
6887
6909
  * @param {Enum} other
6888
6910
  * @returns {boolean}
6889
6911
  */
@@ -6908,6 +6930,7 @@ module.exports = function () {
6908
6930
  * Looks up a enumeration item; given the enumeration type and the enumeration
6909
6931
  * item's value. If no matching item can be found, a null value is returned.
6910
6932
  *
6933
+ * @public
6911
6934
  * @param {Function} type - The enumeration type.
6912
6935
  * @param {String} code - The enumeration item's code.
6913
6936
  * @returns {*|null}
@@ -6927,6 +6950,7 @@ module.exports = function () {
6927
6950
  /**
6928
6951
  * The description.
6929
6952
  *
6953
+ * @public
6930
6954
  * @returns {String}
6931
6955
  */
6932
6956
 
@@ -6946,6 +6970,7 @@ module.exports = function () {
6946
6970
  /**
6947
6971
  * Returns all of the enumeration's items (given an enumeration type).
6948
6972
  *
6973
+ * @public
6949
6974
  * @param {Function} type - The enumeration to list.
6950
6975
  * @returns {Array}
6951
6976
  */
@@ -7403,7 +7428,7 @@ module.exports = function () {
7403
7428
  * Parses the value emitted by {@link Timestamp#toJSON}.
7404
7429
  *
7405
7430
  * @public
7406
- * @param {String} value
7431
+ * @param {Number} value
7407
7432
  * @returns {Timestamp}
7408
7433
  */
7409
7434
 
@@ -8039,7 +8064,7 @@ module.exports = function () {
8039
8064
 
8040
8065
  if (typeof itemConstraint === 'function' && itemConstraint !== Function) {
8041
8066
  itemValidator = function itemValidator(value, index) {
8042
- return value instanceof itemConstraint || itemConstraint(value, variableName + '[' + index + ']');
8067
+ return itemConstraint.prototype !== undefined && value instanceof itemConstraint || itemConstraint(value, variableName + '[' + index + ']');
8043
8068
  };
8044
8069
  } else {
8045
8070
  itemValidator = function itemValidator(value, index) {
@@ -8149,7 +8174,7 @@ module.exports = function () {
8149
8174
  *
8150
8175
  * @static
8151
8176
  * @param {Object} target - The object to check for existence of the property.
8152
- * @param {String|Array<String>} propertyNames - The property to check -- either a string with separators, or an array of strings (already split by separator).
8177
+ * @param {String|Array.<String>} propertyNames - The property to check -- either a string with separators, or an array of strings (already split by separator).
8153
8178
  * @param {String=} separator - The separator (defaults to a period character).
8154
8179
  * @returns {boolean}
8155
8180
  */
@@ -8175,7 +8200,7 @@ module.exports = function () {
8175
8200
  *
8176
8201
  * @static
8177
8202
  * @param {Object} target - The object to read from.
8178
- * @param {String|Array<String>} propertyNames - The property to read -- either a string with separators, or an array of strings (already split by separator).
8203
+ * @param {String|Array.<String>} propertyNames - The property to read -- either a string with separators, or an array of strings (already split by separator).
8179
8204
  * @param {String=} separator - The separator (defaults to a period character).
8180
8205
  * @returns {*}
8181
8206
  */
@@ -8210,7 +8235,8 @@ module.exports = function () {
8210
8235
  *
8211
8236
  * @static
8212
8237
  * @param {Object} target - The object to write to.
8213
- * @param {String|Array<String>} propertyNames - The property to write -- either a string with separators, or an array of strings (already split by separator).
8238
+ * @param {String|Array.<String>} propertyNames - The property to write -- either a string with separators, or an array of strings (already split by separator).
8239
+ * @param {*} value - The value to assign.
8214
8240
  * @param {String=} separator - The separator (defaults to a period character).
8215
8241
  */
8216
8242
  write: function write(target, propertyNames, value, separator) {
@@ -8236,7 +8262,7 @@ module.exports = function () {
8236
8262
  *
8237
8263
  * @static
8238
8264
  * @param {Object} target - The object to erase a property from.
8239
- * @param {String|Array<String>} propertyNames - The property to write -- either a string with separators, or an array of strings (already split by separator).
8265
+ * @param {String|Array.<String>} propertyNames - The property to write -- either a string with separators, or an array of strings (already split by separator).
8240
8266
  * @param {String=} separator - The separator (defaults to a period character).
8241
8267
  */
8242
8268
  erase: function erase(target, propertyNames, separator) {
@@ -9489,7 +9515,7 @@ module.exports = function () {
9489
9515
  }
9490
9516
 
9491
9517
  /**
9492
- * Generates a function suitable for use by JSON.parse.
9518
+ * Generates a function suitable for use by {@link JSON.parse}.
9493
9519
  *
9494
9520
  * @public
9495
9521
  * @returns {Function}
@@ -13614,9 +13640,9 @@ moment.tz.load(require('./data/packed/latest.json'));
13614
13640
 
13615
13641
  mom = createUTC([2000, 1]).day(i);
13616
13642
  if (strict && !this._fullWeekdaysParse[i]) {
13617
- this._fullWeekdaysParse[i] = new RegExp('^' + this.weekdays(mom, '').replace('.', '\.?') + '$', 'i');
13618
- this._shortWeekdaysParse[i] = new RegExp('^' + this.weekdaysShort(mom, '').replace('.', '\.?') + '$', 'i');
13619
- this._minWeekdaysParse[i] = new RegExp('^' + this.weekdaysMin(mom, '').replace('.', '\.?') + '$', 'i');
13643
+ this._fullWeekdaysParse[i] = new RegExp('^' + this.weekdays(mom, '').replace('.', '\\.?') + '$', 'i');
13644
+ this._shortWeekdaysParse[i] = new RegExp('^' + this.weekdaysShort(mom, '').replace('.', '\\.?') + '$', 'i');
13645
+ this._minWeekdaysParse[i] = new RegExp('^' + this.weekdaysMin(mom, '').replace('.', '\\.?') + '$', 'i');
13620
13646
  }
13621
13647
  if (!this._weekdaysParse[i]) {
13622
13648
  regex = '^' + this.weekdays(mom, '') + '|^' + this.weekdaysShort(mom, '') + '|^' + this.weekdaysMin(mom, '');
@@ -14419,7 +14445,7 @@ moment.tz.load(require('./data/packed/latest.json'));
14419
14445
 
14420
14446
  function preprocessRFC2822(s) {
14421
14447
  // Remove comments and folding whitespace and replace multiple-spaces with a single space
14422
- return s.replace(/\([^)]*\)|[\n\t]/g, ' ').replace(/(\s\s+)/g, ' ').trim();
14448
+ return s.replace(/\([^)]*\)|[\n\t]/g, ' ').replace(/(\s\s+)/g, ' ').replace(/^\s\s*/, '').replace(/\s\s*$/, '');
14423
14449
  }
14424
14450
 
14425
14451
  function checkWeekday(weekdayStr, parsedInput, config) {
@@ -16598,7 +16624,7 @@ moment.tz.load(require('./data/packed/latest.json'));
16598
16624
  // Side effect imports
16599
16625
 
16600
16626
 
16601
- hooks.version = '2.22.1';
16627
+ hooks.version = '2.22.2';
16602
16628
 
16603
16629
  setHookCallback(createLocal);
16604
16630
 
@@ -17212,13 +17238,14 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
17212
17238
  },{"./../../../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
17239
  const Day = require('@barchart/common-js/lang/Day');
17214
17240
 
17215
- const TransactionValidator = require('./../../../lib/data/TransactionValidator');
17241
+ const TransactionType = require('./../../../lib/data/TransactionType'),
17242
+ TransactionValidator = require('./../../../lib/data/TransactionValidator');
17216
17243
 
17217
17244
  describe('When validating transaction order', () => {
17218
17245
  'use strict';
17219
17246
 
17220
- const build = (sequence, day) => {
17221
- return { sequence: sequence, date: Day.parse(day) };
17247
+ const build = (sequence, day, type) => {
17248
+ return { sequence: sequence, date: Day.parse(day), type: (type || TransactionType.BUY ) };
17222
17249
  };
17223
17250
 
17224
17251
  it('An array of zero transactions should be valid', () => {
@@ -17229,8 +17256,18 @@ describe('When validating transaction order', () => {
17229
17256
  expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-04-30'), build(3, '2018-04-30') ])).toEqual(true);
17230
17257
  });
17231
17258
 
17259
+ /*
17260
+ it('An array of transactions with ordered sequences, on the same day should be valid, where a dividend occurs last, should be valid', () => {
17261
+ expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-04-30', TransactionType.DIVIDEND) ])).toEqual(true);
17262
+ });
17263
+
17264
+ it('An array of transactions with ordered sequences, on the same day should be valid, where a dividend occurs first, should not be valid', () => {
17265
+ expect(TransactionValidator.validateOrder([ build(1, '2018-04-30', TransactionType.DIVIDEND), build(2, '2018-04-30') ])).toEqual(false);
17266
+ });
17267
+ */
17268
+
17232
17269
  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);
17270
+ expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-05-01'), build(3, '2018-05-02', TransactionType.DIVIDEND) ])).toEqual(true);
17234
17271
  });
17235
17272
 
17236
17273
  it('An array of transactions with ordered sequences (starting after one), on the same day should not be valid', () => {
@@ -17291,7 +17328,7 @@ describe('When requesting all the user-initiated transaction types', () => {
17291
17328
  expect(userInitiated.length).toEqual(9);
17292
17329
  });
17293
17330
  });
17294
- },{"./../../../lib/data/TransactionValidator":5,"@barchart/common-js/lang/Day":21}],54:[function(require,module,exports){
17331
+ },{"./../../../lib/data/TransactionType":4,"./../../../lib/data/TransactionValidator":5,"@barchart/common-js/lang/Day":21}],54:[function(require,module,exports){
17295
17332
  const Currency = require('@barchart/common-js/lang/Currency'),
17296
17333
  Decimal = require('@barchart/common-js/lang/Decimal');
17297
17334
 
@@ -1,12 +1,13 @@
1
1
  const Day = require('@barchart/common-js/lang/Day');
2
2
 
3
- const TransactionValidator = require('./../../../lib/data/TransactionValidator');
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,18 @@ 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
+ /*
22
+ it('An array of transactions with ordered sequences, on the same day should be valid, where a dividend occurs last, should be valid', () => {
23
+ expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-04-30', TransactionType.DIVIDEND) ])).toEqual(true);
24
+ });
25
+
26
+ it('An array of transactions with ordered sequences, on the same day should be valid, where a dividend occurs first, should not be valid', () => {
27
+ expect(TransactionValidator.validateOrder([ build(1, '2018-04-30', TransactionType.DIVIDEND), build(2, '2018-04-30') ])).toEqual(false);
28
+ });
29
+ */
30
+
20
31
  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);
32
+ expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-05-01'), build(3, '2018-05-02', TransactionType.DIVIDEND) ])).toEqual(true);
22
33
  });
23
34
 
24
35
  it('An array of transactions with ordered sequences (starting after one), on the same day should not be valid', () => {