@dhyasama/totem-models 12.11.0 → 12.13.0

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/Financials.js CHANGED
@@ -632,7 +632,7 @@ module.exports = function(mongoose, config) {
632
632
  query.populate('organization', 'name logoUrl');
633
633
  query.populate('customer', 'name logoUrl customer');
634
634
 
635
- const result = await query.lean({ virtuals: true });
635
+ const result = await query;
636
636
  return result;
637
637
  };
638
638
 
@@ -652,7 +652,7 @@ module.exports = function(mongoose, config) {
652
652
  match: { customer: customerId }
653
653
  });
654
654
 
655
- const result = await query.lean({ virtuals: true });
655
+ const result = await query;
656
656
  return result;
657
657
  };
658
658
 
@@ -672,7 +672,7 @@ module.exports = function(mongoose, config) {
672
672
  query.populate('customer');
673
673
  query.populate('snapshots.documents.document');
674
674
 
675
- const result = await query.lean({ virtuals: true });
675
+ const result = await query;
676
676
  if (!result) { return null; }
677
677
  else if (!result.customer) { return null; }
678
678
 
@@ -705,7 +705,7 @@ module.exports = function(mongoose, config) {
705
705
  ]
706
706
  });
707
707
 
708
- const result = await query.lean({ virtuals: true });
708
+ const result = await query;
709
709
  return result;
710
710
  };
711
711
 
@@ -734,7 +734,7 @@ module.exports = function(mongoose, config) {
734
734
  key: postmarkMessageId
735
735
  });
736
736
 
737
- const result = await query.lean({ virtuals: true });
737
+ const result = await query;
738
738
  return result;
739
739
  };
740
740
 
@@ -812,7 +812,7 @@ module.exports = function(mongoose, config) {
812
812
  'recurring.adminReminders.sent': false
813
813
  });
814
814
 
815
- const result = await query.lean({ virtuals: true });
815
+ const result = await query;
816
816
  return result;
817
817
  };
818
818
 
@@ -837,7 +837,7 @@ module.exports = function(mongoose, config) {
837
837
  }
838
838
  });
839
839
 
840
- const result = await query.lean({ virtuals: true });
840
+ const result = await query;
841
841
  var results = [];
842
842
 
843
843
  _.each(result, function(financial) {
@@ -892,7 +892,7 @@ module.exports = function(mongoose, config) {
892
892
  }
893
893
  });
894
894
 
895
- const result = await query.lean({ virtuals: true });
895
+ const result = await query;
896
896
  var results = [];
897
897
 
898
898
  _.each(result, function(financial) {
@@ -951,7 +951,7 @@ module.exports = function(mongoose, config) {
951
951
  }
952
952
  });
953
953
 
954
- const result = await query.lean({ virtuals: true });
954
+ const result = await query;
955
955
  var results = [];
956
956
 
957
957
  _.each(result, function(financial) {
@@ -1011,7 +1011,7 @@ module.exports = function(mongoose, config) {
1011
1011
  }
1012
1012
  });
1013
1013
 
1014
- let financials = await query.lean({ virtuals: true });
1014
+ let financials = await query;
1015
1015
  financials = financials || [];
1016
1016
 
1017
1017
  let results = [];
@@ -1075,7 +1075,7 @@ module.exports = function(mongoose, config) {
1075
1075
  }
1076
1076
  });
1077
1077
 
1078
- const result = await query.lean({ virtuals: true });
1078
+ const result = await query;
1079
1079
  var results = [];
1080
1080
 
1081
1081
  _.each(result, function(financial) {
@@ -1141,7 +1141,7 @@ module.exports = function(mongoose, config) {
1141
1141
  });
1142
1142
  }
1143
1143
 
1144
- const result = await query.lean({ virtuals: true });
1144
+ const result = await query;
1145
1145
  return result;
1146
1146
  };
1147
1147
 
@@ -1161,7 +1161,7 @@ module.exports = function(mongoose, config) {
1161
1161
  query.populate('customer', 'name logoUrl customer');
1162
1162
  query.populate('snapshots.notifications.stakeholders.sendTo.organization', 'name logoUrl customer');
1163
1163
 
1164
- const result = await query.lean({ virtuals: true });
1164
+ const result = await query;
1165
1165
  return result;
1166
1166
  };
1167
1167
 
@@ -1182,7 +1182,7 @@ module.exports = function(mongoose, config) {
1182
1182
  }
1183
1183
  });
1184
1184
 
1185
- const result = await query.lean({ virtuals: true });
1185
+ const result = await query;
1186
1186
  return result;
1187
1187
  };
1188
1188
 
package/lib/Flag.js CHANGED
@@ -80,7 +80,7 @@ module.exports = function(mongoose, config) {
80
80
  '_id': id
81
81
  });
82
82
 
83
- const result = await query.lean({ virtuals: true });
83
+ const result = await query;
84
84
  return result;
85
85
  };
86
86
 
package/lib/Note.js CHANGED
@@ -87,7 +87,7 @@ module.exports = function(mongoose, config) {
87
87
  'customer': options.CUSTOMER_ID
88
88
  });
89
89
 
90
- const result = await query.lean({ virtuals: true });
90
+ const result = await query;
91
91
  return result;
92
92
  };
93
93
 
@@ -638,6 +638,16 @@ module.exports = function(mongoose, config) {
638
638
  // Properties that are not persisted to the database
639
639
  ///////////////////////////////////////////////////////////////////////////////////////
640
640
 
641
+ const getOperatingData = function(self, field) {
642
+ const operating = self && self.operating ? self.operating : {};
643
+ const data = operating[field] || {};
644
+
645
+ return {
646
+ publicData: data.public || {},
647
+ privateData: data.private || []
648
+ };
649
+ };
650
+
641
651
  Organization.virtual('address.primary').get(function () {
642
652
  var addresses = this && this.contact && this.contact.address ? this.contact.address : [];
643
653
  var primary = _.find(addresses, function(address) {
@@ -706,15 +716,17 @@ module.exports = function(mongoose, config) {
706
716
  Organization.virtual('customer.deals.activeStatuses').get(function () {
707
717
 
708
718
  var self = this;
719
+ var customer = self && self.customer ? self.customer : {};
720
+ var deals = customer.deals || {};
709
721
 
710
722
  // Backwards schema compatibility
711
- if (!self.customer.deals) return [];
723
+ if (!customer.deals) return [];
712
724
 
713
725
  // Deals aren't on for customer
714
- else if (!self.customer.deals.active) return [];
726
+ else if (!deals.active) return [];
715
727
 
716
728
  // Get active status names and sort them
717
- var statuses = _.filter(self.customer.deals.statuses, function(s) { return s.active; });
729
+ var statuses = _.filter(deals.statuses || [], function(s) { return s && s.active; });
718
730
  statuses = _.sortBy(statuses, 'order');
719
731
  statuses = _.pluck(statuses, 'name');
720
732
 
@@ -833,8 +845,9 @@ module.exports = function(mongoose, config) {
833
845
  Organization.virtual('operating.closed.on').get(function () {
834
846
 
835
847
  const self = this;
836
- const publicData = self.operating.closed.public || {};
837
- const privateData = self.operating.closed.private || [];
848
+ const operatingData = getOperatingData(self, 'closed');
849
+ const publicData = operatingData.publicData;
850
+ const privateData = operatingData.privateData;
838
851
 
839
852
  if (publicData.closedOn) return publicData.closedOn;
840
853
  else if (privateData.length >= 1) {
@@ -848,8 +861,9 @@ module.exports = function(mongoose, config) {
848
861
  Organization.virtual('operating.acquired.amount').get(function () {
849
862
 
850
863
  const self = this;
851
- const publicData = self.operating.acquired.public || {};
852
- const privateData = self.operating.acquired.private || [];
864
+ const operatingData = getOperatingData(self, 'acquired');
865
+ const publicData = operatingData.publicData;
866
+ const privateData = operatingData.privateData;
853
867
 
854
868
  if (publicData.amount) return publicData.amount;
855
869
  else if (privateData.length >= 1) {
@@ -863,8 +877,9 @@ module.exports = function(mongoose, config) {
863
877
  Organization.virtual('operating.acquired.by').get(function () {
864
878
 
865
879
  const self = this;
866
- const publicData = self.operating.acquired.public || {};
867
- const privateData = self.operating.acquired.private || [];
880
+ const operatingData = getOperatingData(self, 'acquired');
881
+ const publicData = operatingData.publicData;
882
+ const privateData = operatingData.privateData;
868
883
 
869
884
  if (publicData.by) return publicData.by;
870
885
  else if (privateData.length >= 1) {
@@ -878,8 +893,9 @@ module.exports = function(mongoose, config) {
878
893
  Organization.virtual('operating.acquired.on').get(function () {
879
894
 
880
895
  const self = this;
881
- const publicData = self.operating.acquired.public || {};
882
- const privateData = self.operating.acquired.private || [];
896
+ const operatingData = getOperatingData(self, 'acquired');
897
+ const publicData = operatingData.publicData;
898
+ const privateData = operatingData.privateData;
883
899
 
884
900
  if (publicData.acquiredOn) return publicData.acquiredOn;
885
901
  else if (privateData.length >= 1) {
@@ -893,8 +909,9 @@ module.exports = function(mongoose, config) {
893
909
  Organization.virtual('operating.merged.with').get(function () {
894
910
 
895
911
  const self = this;
896
- const publicData = self.operating.merged.public || {};
897
- const privateData = self.operating.merged.private || [];
912
+ const operatingData = getOperatingData(self, 'merged');
913
+ const publicData = operatingData.publicData;
914
+ const privateData = operatingData.privateData;
898
915
 
899
916
  if (publicData.with) return publicData.with;
900
917
  else if (privateData.length >= 1) {
@@ -908,8 +925,9 @@ module.exports = function(mongoose, config) {
908
925
  Organization.virtual('operating.merged.on').get(function () {
909
926
 
910
927
  const self = this;
911
- const publicData = self.operating.merged.public || {};
912
- const privateData = self.operating.merged.private || [];
928
+ const operatingData = getOperatingData(self, 'merged');
929
+ const publicData = operatingData.publicData;
930
+ const privateData = operatingData.privateData;
913
931
 
914
932
  if (publicData.mergedOn) return publicData.mergedOn;
915
933
  else if (privateData.length >= 1) {
@@ -1114,7 +1132,7 @@ module.exports = function(mongoose, config) {
1114
1132
 
1115
1133
  let query = this.find({ $or: [ {'website': { $in : domains }}, {'websiteAliases': { $in : domains }} ], 'deleted': {$ne: true} });
1116
1134
 
1117
- const orgs = await query.lean({ virtuals: true });
1135
+ const orgs = await query;
1118
1136
  if (!orgs) { return []; }
1119
1137
 
1120
1138
  let result = orgs;
@@ -1138,7 +1156,7 @@ module.exports = function(mongoose, config) {
1138
1156
  const result = await this
1139
1157
  .find({ 'funds': { $in : fundids }, 'deleted': {$ne: true} })
1140
1158
  .select('name logoUrl funds contact')
1141
- .lean({ virtuals: true });
1159
+ ;
1142
1160
  return result;
1143
1161
  };
1144
1162
 
@@ -1160,7 +1178,7 @@ module.exports = function(mongoose, config) {
1160
1178
  if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { throw new Error('options.CUSTOMER_ID is not a valid ObjectId'); }
1161
1179
  }
1162
1180
 
1163
- const orgs = await this.find({ '_id': { $in : ids }}).lean({ virtuals: true });
1181
+ const orgs = await this.find({ '_id': { $in : ids }});
1164
1182
  if (!orgs) { return []; }
1165
1183
 
1166
1184
  let result = orgs;
@@ -1199,7 +1217,7 @@ module.exports = function(mongoose, config) {
1199
1217
  .populate('chairs.first', 'name avatarUrl title')
1200
1218
  .populate('chairs.second', 'name avatarUrl title')
1201
1219
  .populate('funds', 'name hexColorCode abbreviation')
1202
- .lean({ virtuals: true });
1220
+ ;
1203
1221
  if (!orgs) { return []; }
1204
1222
 
1205
1223
  const result = _.map(orgs, function(org) {
@@ -1224,7 +1242,7 @@ module.exports = function(mongoose, config) {
1224
1242
  const result = await this
1225
1243
  .find({ 'lps': lpid, 'deleted': {$ne: true} })
1226
1244
  .select('name logoUrl')
1227
- .lean({ virtuals: true });
1245
+ ;
1228
1246
  return result;
1229
1247
  };
1230
1248
 
@@ -1251,7 +1269,7 @@ module.exports = function(mongoose, config) {
1251
1269
  'deleted': { $ne: true }
1252
1270
  })
1253
1271
  .select('-sources -customer')
1254
- .lean({ virtuals: true });
1272
+ ;
1255
1273
  return result;
1256
1274
  };
1257
1275
 
@@ -1265,7 +1283,7 @@ module.exports = function(mongoose, config) {
1265
1283
  const run = async () => {
1266
1284
  if (!personIds) { throw new Error('personIds is required'); }
1267
1285
 
1268
- const result = await this.find({'people.person': { $in : personIds } }).lean({ virtuals: true });
1286
+ const result = await this.find({'people.person': { $in : personIds } });
1269
1287
  return result;
1270
1288
  };
1271
1289
 
@@ -1277,7 +1295,7 @@ module.exports = function(mongoose, config) {
1277
1295
  Organization.statics.findBySlug = function findBySlug(slug, cb) {
1278
1296
 
1279
1297
  const run = async () => {
1280
- const result = await this.findOne({ slug: slug, 'deleted': {$ne: true} }).lean({ virtuals: true });
1298
+ const result = await this.findOne({ slug: slug, 'deleted': {$ne: true} });
1281
1299
  return result;
1282
1300
  };
1283
1301
 
@@ -1289,7 +1307,7 @@ module.exports = function(mongoose, config) {
1289
1307
  Organization.statics.findBySlugs = function findBySlugs(slugs, cb) {
1290
1308
 
1291
1309
  const run = async () => {
1292
- const result = await this.find({ 'slug': { $in : slugs } }).lean({ virtuals: true });
1310
+ const result = await this.find({ 'slug': { $in : slugs } });
1293
1311
  return result;
1294
1312
  };
1295
1313
 
@@ -1402,7 +1420,7 @@ module.exports = function(mongoose, config) {
1402
1420
  ],
1403
1421
  'deleted': { $ne: true }
1404
1422
  })
1405
- .lean({ virtuals: true });
1423
+ ;
1406
1424
 
1407
1425
  const result = _.map(orgs, function(org) {
1408
1426
  return helpers.cleanOrg(org, options.CUSTOMER_ID);
@@ -1443,7 +1461,7 @@ module.exports = function(mongoose, config) {
1443
1461
  ],
1444
1462
  'deleted': { $ne: true }
1445
1463
  })
1446
- .lean({ virtuals: true });
1464
+ ;
1447
1465
 
1448
1466
  const result = _.map(orgs, function(org) {
1449
1467
  return helpers.cleanOrg(org, options.CUSTOMER_ID);
@@ -1460,7 +1478,7 @@ module.exports = function(mongoose, config) {
1460
1478
  Organization.statics.findByDocument = function findByDocument(id, cb) {
1461
1479
 
1462
1480
  const run = async () => {
1463
- const result = await this.findOne({ 'documents': id }).lean({ virtuals: true });
1481
+ const result = await this.findOne({ 'documents': id });
1464
1482
  return result;
1465
1483
  };
1466
1484
 
@@ -1498,7 +1516,7 @@ module.exports = function(mongoose, config) {
1498
1516
  ]}
1499
1517
  )
1500
1518
  .select('name logoUrl')
1501
- .lean({ virtuals: true });
1519
+ ;
1502
1520
  return result;
1503
1521
  };
1504
1522
 
@@ -1522,7 +1540,7 @@ module.exports = function(mongoose, config) {
1522
1540
  }
1523
1541
  })
1524
1542
  .select('name logoUrl people')
1525
- .lean({ virtuals: true });
1543
+ ;
1526
1544
  return result;
1527
1545
  };
1528
1546
 
@@ -1537,7 +1555,7 @@ module.exports = function(mongoose, config) {
1537
1555
  const result = await this
1538
1556
  .findOne({ 'funds': id, 'deleted': {$ne: true} })
1539
1557
  .select('name logoUrl')
1540
- .lean({ virtuals: true });
1558
+ ;
1541
1559
  return result;
1542
1560
  };
1543
1561
 
@@ -1589,7 +1607,7 @@ module.exports = function(mongoose, config) {
1589
1607
  query.populate(lpPopulateOptions);
1590
1608
  }
1591
1609
 
1592
- const result = await query.lean({ virtuals: true });
1610
+ const result = await query;
1593
1611
  if (options.isWorkerProcess) { return result; }
1594
1612
  else { return helpers.cleanOrg(result, options.CUSTOMER_ID); }
1595
1613
  };
@@ -1607,7 +1625,7 @@ module.exports = function(mongoose, config) {
1607
1625
  const query = this.findById(id);
1608
1626
  query.select('name aliases website websiteAliases logoUrl');
1609
1627
 
1610
- const result = await query.lean({ virtuals: true });
1628
+ const result = await query;
1611
1629
  return result;
1612
1630
  };
1613
1631
 
@@ -1632,7 +1650,7 @@ module.exports = function(mongoose, config) {
1632
1650
  let query = this.find( {'_id': { $in : ids } } );
1633
1651
  query.populate('documents');
1634
1652
 
1635
- const result = await query.lean({ virtuals: true });
1653
+ const result = await query;
1636
1654
  if (options.isWorkerProcess) { return result; }
1637
1655
  else { return _.map(result, function(r) { return helpers.cleanOrg(r, options.CUSTOMER_ID) }); }
1638
1656
  };
@@ -1659,7 +1677,7 @@ module.exports = function(mongoose, config) {
1659
1677
  ],
1660
1678
  'deleted': { $ne: true }
1661
1679
  })
1662
- .lean({ virtuals: true });
1680
+ ;
1663
1681
 
1664
1682
  const result = _.map(orgs, function(org) {
1665
1683
  return helpers.cleanOrg(org, options.CUSTOMER_ID);
@@ -1693,7 +1711,7 @@ module.exports = function(mongoose, config) {
1693
1711
  },
1694
1712
  })
1695
1713
 
1696
- const result = await query.lean({ virtuals: true });
1714
+ const result = await query;
1697
1715
  const filtered = _.filter(result, function(org) {
1698
1716
  return org.documents.length > 0;
1699
1717
  });
@@ -1719,7 +1737,7 @@ module.exports = function(mongoose, config) {
1719
1737
  .find( {'_id': { $in : orgIds } } )
1720
1738
  .select('_id valuations');
1721
1739
 
1722
- const orgs = await query.lean({ virtuals: true });
1740
+ const orgs = await query;
1723
1741
  const result = _.map(orgs, function(org) {
1724
1742
  return helpers.cleanOrg(org, customerId);
1725
1743
  });
@@ -1756,7 +1774,7 @@ module.exports = function(mongoose, config) {
1756
1774
  }
1757
1775
  })
1758
1776
 
1759
- const result = await query.lean({ virtuals: true });
1777
+ const result = await query;
1760
1778
  const filtered = _.filter(result, function(org) {
1761
1779
  return org.notes.length > 0;
1762
1780
  });
@@ -1775,7 +1793,7 @@ module.exports = function(mongoose, config) {
1775
1793
  const result = await this
1776
1794
  .find({'deleted': {$ne: true}})
1777
1795
  .select('name website websiteAliases')
1778
- .lean({ virtuals: true });
1796
+ ;
1779
1797
  return result;
1780
1798
  };
1781
1799
 
@@ -1797,7 +1815,7 @@ module.exports = function(mongoose, config) {
1797
1815
  query.select('name logoUrl lps');
1798
1816
  query.populate('lps', 'name customer');
1799
1817
 
1800
- const orgs = await query.lean({ virtuals: true });
1818
+ const orgs = await query;
1801
1819
  if (!orgs) { return []; }
1802
1820
 
1803
1821
  const result = _.map(orgs, function(org) {
@@ -1835,7 +1853,7 @@ module.exports = function(mongoose, config) {
1835
1853
  });
1836
1854
  query.sort({'createdOn':-1});
1837
1855
 
1838
- const org = await query.lean({ virtuals: true });
1856
+ const org = await query;
1839
1857
  if (!org) { return []; }
1840
1858
 
1841
1859
  const result = helpers.cleanOrg(org, options.CUSTOMER_ID);
@@ -1866,11 +1884,11 @@ module.exports = function(mongoose, config) {
1866
1884
  });
1867
1885
 
1868
1886
  // get the org requested
1869
- const org = await query.lean({ virtuals: true });
1887
+ const org = await query;
1870
1888
  if (!org) { return null; }
1871
1889
 
1872
1890
  // get the customer requesting org
1873
- const customer = await this.findById(options.CUSTOMER_ID).lean({ virtuals: true });
1891
+ const customer = await this.findById(options.CUSTOMER_ID);
1874
1892
  if (!customer) { return null; }
1875
1893
 
1876
1894
  let current = [];
@@ -2167,7 +2185,7 @@ module.exports = function(mongoose, config) {
2167
2185
  .find(query)
2168
2186
  .populate('merged')
2169
2187
  .select('logoUrl name description related website')
2170
- .lean({ virtuals: true });
2188
+ ;
2171
2189
  if (!orgs) return null;
2172
2190
 
2173
2191
  // remove related from top level
package/lib/Person.js CHANGED
@@ -150,10 +150,11 @@ module.exports = function(mongoose, config) {
150
150
  /////////////
151
151
 
152
152
  Person.virtual('name.full').get(function () {
153
+ var personName = this && this.name ? this.name : {};
153
154
  var name = '';
154
- if(this.name.first) name += this.name.first;
155
- if(this.name.first && this.name.last) name += ' ';
156
- if(this.name.last) name += this.name.last;
155
+ if(personName.first) name += personName.first;
156
+ if(personName.first && personName.last) name += ' ';
157
+ if(personName.last) name += personName.last;
157
158
  return name;
158
159
  });
159
160
 
@@ -539,7 +540,7 @@ module.exports = function(mongoose, config) {
539
540
  if (!person) { return null; }
540
541
 
541
542
  // get the customer's org
542
- const customer = await Organization.findById(options.CUSTOMER_ID).lean({ virtuals: true });
543
+ const customer = await Organization.findById(options.CUSTOMER_ID);
543
544
  if (!customer) { return null; }
544
545
 
545
546
  let current = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "12.11.0",
3
+ "version": "12.13.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",
@@ -1157,8 +1157,7 @@ describe('Organization', function() {
1157
1157
  should.not.exist(err);
1158
1158
  should.exist(org);
1159
1159
 
1160
- Organization.findById(org._id).lean({ virtuals: true })
1161
- .then(function(result) {
1160
+ Organization.findById(org._id) .then(function(result) {
1162
1161
  should.exist(result);
1163
1162
  should.exist(result.address);
1164
1163
  should.exist(result.address.primary);
@@ -1195,8 +1194,7 @@ describe('Organization', function() {
1195
1194
 
1196
1195
  Organization.findById(org._id)
1197
1196
  .select('name')
1198
- .lean({ virtuals: true })
1199
- .then(function(result) {
1197
+ .then(function(result) {
1200
1198
  should.exist(result);
1201
1199
  should.exist(result.address);
1202
1200
  should.equal(result.address.primary, null);
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+
3
+ var
4
+
5
+ should = require("should"),
6
+ mongoose = require("mongoose"),
7
+ config = require('./config')['test'];
8
+
9
+ if (!mongoose.models.Organization) {
10
+ require('../index')(mongoose, config);
11
+ }
12
+
13
+ var Organization = mongoose.model('Organization');
14
+ var Person = mongoose.model('Person');
15
+ var LimitedPartner = mongoose.model('LimitedPartner');
16
+
17
+ var applyVirtual = function(Model, path, doc) {
18
+ return Model.schema.virtualpath(path).applyGetters(undefined, doc);
19
+ };
20
+
21
+ describe('Virtuals', function() {
22
+
23
+ it('handles projected organization virtuals without parent branches', function() {
24
+
25
+ should.equal(applyVirtual(Organization, 'address.primary', { name: 'Org' }), null);
26
+ applyVirtual(Organization, 'customer.deals.activeStatuses', { name: 'Org' }).should.eql([]);
27
+ should.equal(applyVirtual(Organization, 'operating.closed.on', { name: 'Org' }), null);
28
+ should.equal(applyVirtual(Organization, 'operating.acquired.amount', { name: 'Org' }), 0);
29
+ should.equal(applyVirtual(Organization, 'operating.acquired.by', { name: 'Org' }), null);
30
+ should.equal(applyVirtual(Organization, 'operating.acquired.on', { name: 'Org' }), null);
31
+ should.equal(applyVirtual(Organization, 'operating.merged.with', { name: 'Org' }), null);
32
+ should.equal(applyVirtual(Organization, 'operating.merged.on', { name: 'Org' }), null);
33
+
34
+ });
35
+
36
+ it('returns organization virtual values when data exists', function() {
37
+
38
+ applyVirtual(Organization, 'address.primary', {
39
+ contact: {
40
+ address: [
41
+ { postalCode: '04101', primary: false },
42
+ { postalCode: '04412', primary: true }
43
+ ]
44
+ }
45
+ }).postalCode.should.equal('04412');
46
+
47
+ applyVirtual(Organization, 'customer.deals.activeStatuses', {
48
+ customer: {
49
+ deals: {
50
+ active: true,
51
+ statuses: [
52
+ { name: 'Diligence', order: 2, active: true },
53
+ { name: 'New', order: 1, active: true },
54
+ { name: 'Pass', order: 3, active: false }
55
+ ]
56
+ }
57
+ }
58
+ }).should.eql(['New', 'Diligence']);
59
+
60
+ applyVirtual(Organization, 'operating.acquired.amount', {
61
+ operating: {
62
+ acquired: {
63
+ public: { amount: 25 }
64
+ }
65
+ }
66
+ }).should.equal(25);
67
+
68
+ });
69
+
70
+ it('handles projected person virtuals without parent branches', function() {
71
+
72
+ applyVirtual(Person, 'name.full', { avatarUrl: '/x.png' }).should.equal('');
73
+ applyVirtual(Person, 'email.primary', { avatarUrl: '/x.png' }).should.equal('');
74
+ applyVirtual(Person, 'phone.primary', { avatarUrl: '/x.png' }).should.equal('');
75
+
76
+ });
77
+
78
+ it('returns person virtual values when data exists', function() {
79
+
80
+ applyVirtual(Person, 'name.full', {
81
+ name: {
82
+ first: 'Ada',
83
+ last: 'Lovelace'
84
+ }
85
+ }).should.equal('Ada Lovelace');
86
+
87
+ applyVirtual(Person, 'email.primary', {
88
+ contact: {
89
+ email: [{ email: 'ada@test.com', primary: true }]
90
+ }
91
+ }).should.equal('ada@test.com');
92
+
93
+ applyVirtual(Person, 'phone.primary', {
94
+ contact: {
95
+ phone: [{ number: '123', primary: true }]
96
+ }
97
+ }).should.equal('123');
98
+
99
+ });
100
+
101
+ it('handles projected limited partner virtuals without contact', function() {
102
+
103
+ applyVirtual(LimitedPartner, 'email.primary', { name: 'LP' }).should.equal('');
104
+ applyVirtual(LimitedPartner, 'phone.primary', { name: 'LP' }).should.equal('');
105
+ applyVirtual(LimitedPartner, 'address.primary', { name: 'LP' }).postalCode.should.equal('');
106
+
107
+ });
108
+
109
+ it('returns limited partner virtual values when data exists', function() {
110
+
111
+ applyVirtual(LimitedPartner, 'email.primary', {
112
+ contact: {
113
+ email: [{ email: 'lp@test.com', primary: true }]
114
+ }
115
+ }).should.equal('lp@test.com');
116
+
117
+ applyVirtual(LimitedPartner, 'phone.primary', {
118
+ contact: {
119
+ phone: [{ number: '456', primary: true }]
120
+ }
121
+ }).should.equal('456');
122
+
123
+ applyVirtual(LimitedPartner, 'address.primary', {
124
+ contact: {
125
+ address: [{ postalCode: '04412', primary: true }]
126
+ }
127
+ }).postalCode.should.equal('04412');
128
+
129
+ });
130
+
131
+ });