@dhyasama/totem-models 7.57.0 → 8.0.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.
@@ -15,13 +15,11 @@ var
15
15
  Account = mongoose.model('Account');
16
16
 
17
17
  var person, person1, person2;
18
- var noteId;
19
18
  var flagId;
20
19
  var someOtherFund;
21
20
  var someOtherLp;
22
21
  var account;
23
22
  var customer1, customer2;
24
- var deal;
25
23
 
26
24
  describe('Organization', function() {
27
25
 
@@ -142,14 +140,6 @@ describe('Organization', function() {
142
140
 
143
141
  before(function (done) {
144
142
 
145
- //action
146
- //raise
147
- //valuation
148
- //sources
149
- //referrers
150
- //chairs
151
-
152
-
153
143
  customer1 = new Organization();
154
144
  customer1.name = 'New Customer';
155
145
  customer1.slug = 'new-customer';
@@ -365,8 +355,9 @@ describe('Organization', function() {
365
355
  var lp = new LimitedPartner();
366
356
  lp.name = 'SOME OTHER LP';
367
357
  lp.fundsInvested.push({fund: someOtherFund});
358
+ lp.customer = customer1;
368
359
 
369
- LimitedPartner.upsert(lp, 'test', 'lp-full', function (err, lpResult) {
360
+ LimitedPartner.upsert(lp, 'test', { role: 'lp-full' }, function (err, lpResult) {
370
361
 
371
362
  should.not.exist(err);
372
363
  should.exist(lpResult);
@@ -426,6 +417,7 @@ describe('Organization', function() {
426
417
  account.username = 'test-user';
427
418
  account.email = 'test@totemvc.com';
428
419
  account.person = person1;
420
+ account.org = org2;
429
421
 
430
422
  Account.upsert(account, function (err, result) {
431
423
 
@@ -668,31 +660,9 @@ describe('Organization', function() {
668
660
 
669
661
  });
670
662
 
671
- it('finds an org without mongoose sugar', function (done) {
672
-
673
- Organization.getByIdRaw(org1._id, {}, function (err, result) {
674
- should.not.exist(err);
675
- should.exist(result);
676
- (result instanceof Organization).should.equal(false);
677
- done();
678
- });
679
-
680
- });
681
-
682
- it('finds an org as global', function (done) {
683
-
684
- Organization.getByIdAsGlobal(org2._id, {}, function (err, result) {
685
- should.not.exist(err);
686
- should.exist(result);
687
- result.iLevel.length.should.equal(1);
688
- done();
689
- });
690
-
691
- });
692
-
693
663
  it('gets an org by id', function (done) {
694
664
 
695
- Organization.getById(org1.id, {role: 'lp-full'}, function (err, org) {
665
+ Organization.getById(org1.id, { CUSTOMER_ID: customer1._id, role: 'lp-full' }, function (err, org) {
696
666
  should.not.exist(err);
697
667
  should.exist(org);
698
668
  org1 = org;
@@ -780,19 +750,6 @@ describe('Organization', function() {
780
750
 
781
751
  });
782
752
 
783
- it('finds orgs by person without mongoose sugar', function (done) {
784
-
785
- Organization.findByPersonRaw(person._id, function (err, result) {
786
- should.not.exist(err);
787
- should.exist(result);
788
- result.length.should.equal(1);
789
- result[0]._id.toString().should.equal(org1.id.toString());
790
- (result[0] instanceof Organization).should.equal(false);
791
- done();
792
- });
793
-
794
- });
795
-
796
753
  it('finds boards of a person', function (done) {
797
754
 
798
755
  Organization.getBoardsOfPerson(person2.id, function (err, result) {
@@ -806,7 +763,7 @@ describe('Organization', function() {
806
763
 
807
764
  it('finds chairs of a person', function (done) {
808
765
 
809
- Organization.getChairsOfPerson(person2.id, function (err, result) {
766
+ Organization.getChairsOfPerson(person2.id, { CUSTOMER_ID: customer1._id }, function (err, result) {
810
767
  should.not.exist(err);
811
768
  should.exist(result);
812
769
  result.length.should.equal(1);
@@ -817,7 +774,7 @@ describe('Organization', function() {
817
774
 
818
775
  it('gets the board of a company', function (done) {
819
776
 
820
- Organization.getById(org3.id, {role: 'lp-full'}, function (err, result) {
777
+ Organization.getById(org3.id, { CUSTOMER_ID: customer1._id, role: 'lp-full' }, function (err, result) {
821
778
  should.not.exist(err);
822
779
  should.exist(result);
823
780
  var board = result.board;
@@ -850,7 +807,7 @@ describe('Organization', function() {
850
807
  updatedOrg.people.length.should.equal(1);
851
808
 
852
809
  // get populated org
853
- Organization.getById(org1.id, {role: 'lp-full'}, function (err, org) {
810
+ Organization.getById(org1.id, { CUSTOMER_ID: customer1._id, role: 'lp-full' }, function (err, org) {
854
811
 
855
812
  should.not.exist(err);
856
813
  should.exist(org);
@@ -870,54 +827,8 @@ describe('Organization', function() {
870
827
 
871
828
  });
872
829
 
873
- it('it flags an org', function (done) {
874
-
875
- Organization.flag(org4.id, false, 'flagging org4', 'test-user', function (err, org) {
876
- should.not.exist(err);
877
- should.exist(org);
878
- org.flagged.text.should.equal('flagging org4');
879
- done();
880
- });
881
- }); // end flag an org
882
-
883
- it('finds dupes by querying first word of name', function (done) {
884
-
885
- var options = {
886
- fuzzy: true,
887
- queryFirstWord: true,
888
- admin: true,
889
- pcs: []
890
- };
891
-
892
- Organization.findDupes(org3, options, function (err, dupes) {
893
- should.not.exist(err);
894
- should.exist(dupes);
895
- dupes.length.should.equal(1);
896
- done();
897
- });
898
-
899
- });
900
-
901
- it('does not find dupes by querying full name', function (done) {
902
-
903
- var options = {
904
- fuzzy: true,
905
- queryFirstWord: false,
906
- admin: true,
907
- pcs: []
908
- };
909
-
910
- Organization.findDupes(org3, options, function (err, dupes) {
911
- should.not.exist(err);
912
- should.exist(dupes);
913
- dupes.length.should.equal(0);
914
- done();
915
- });
916
-
917
- });
918
-
919
830
  it('finds orgs by domain', function (done) {
920
- Organization.findByDomains(['nothanks2.org', 'fromthesong.org'], function (err, result) {
831
+ Organization.findByDomains(['nothanks2.org', 'fromthesong.org'], { CUSTOMER_ID: customer1._id }, function (err, result) {
921
832
  should.not.exist(err);
922
833
  should.exist(result);
923
834
  result.length.should.equal(2);
@@ -926,7 +837,7 @@ describe('Organization', function() {
926
837
  });
927
838
 
928
839
  it('finds orgs by twitter with http and no www', function (done) {
929
- Organization.findBySocial('http://twitter.com/abc', function (err, result) {
840
+ Organization.findBySocial('http://twitter.com/abc', { CUSTOMER_ID: customer1._id }, function (err, result) {
930
841
  should.not.exist(err);
931
842
  should.exist(result);
932
843
  result.length.should.equal(1);
@@ -935,7 +846,7 @@ describe('Organization', function() {
935
846
  });
936
847
 
937
848
  it('will not match partial username', function (done) {
938
- Organization.findBySocial('http://twitter.com/abcdef', function (err, result) {
849
+ Organization.findBySocial('http://twitter.com/abcdef', { CUSTOMER_ID: customer1._id }, function (err, result) {
939
850
  should.not.exist(err);
940
851
  should.exist(result);
941
852
  result.length.should.equal(0);
@@ -944,7 +855,7 @@ describe('Organization', function() {
944
855
  });
945
856
 
946
857
  it('finds orgs by twitter with https and no www', function (done) {
947
- Organization.findBySocial('https://twitter.com/abc', function (err, result) {
858
+ Organization.findBySocial('https://twitter.com/abc', { CUSTOMER_ID: customer1._id }, function (err, result) {
948
859
  should.not.exist(err);
949
860
  should.exist(result);
950
861
  result.length.should.equal(1);
@@ -953,7 +864,7 @@ describe('Organization', function() {
953
864
  });
954
865
 
955
866
  it('finds orgs by twitter with http and www', function (done) {
956
- Organization.findBySocial('http://www.twitter.com/abc', function (err, result) {
867
+ Organization.findBySocial('http://www.twitter.com/abc', { CUSTOMER_ID: customer1._id }, function (err, result) {
957
868
  should.not.exist(err);
958
869
  should.exist(result);
959
870
  result.length.should.equal(1);
@@ -962,7 +873,7 @@ describe('Organization', function() {
962
873
  });
963
874
 
964
875
  it('finds orgs by twitter with https and www', function (done) {
965
- Organization.findBySocial('https://www.twitter.com/abc', function (err, result) {
876
+ Organization.findBySocial('https://www.twitter.com/abc', { CUSTOMER_ID: customer1._id }, function (err, result) {
966
877
  should.not.exist(err);
967
878
  should.exist(result);
968
879
  result.length.should.equal(1);
@@ -971,7 +882,7 @@ describe('Organization', function() {
971
882
  });
972
883
 
973
884
  it('finds orgs by twitter with no http, https or www', function (done) {
974
- Organization.findBySocial('twitter.com/abc', function (err, result) {
885
+ Organization.findBySocial('twitter.com/abc', { CUSTOMER_ID: customer1._id }, function (err, result) {
975
886
  should.not.exist(err);
976
887
  should.exist(result);
977
888
  result.length.should.equal(1);
@@ -980,7 +891,7 @@ describe('Organization', function() {
980
891
  });
981
892
 
982
893
  it('finds orgs by facebook with http and no www', function (done) {
983
- Organization.findBySocial('http://facebook.com/abc', function (err, result) {
894
+ Organization.findBySocial('http://facebook.com/abc', { CUSTOMER_ID: customer1._id }, function (err, result) {
984
895
  should.not.exist(err);
985
896
  should.exist(result);
986
897
  result.length.should.equal(1);
@@ -989,7 +900,7 @@ describe('Organization', function() {
989
900
  });
990
901
 
991
902
  it('finds orgs by linkedin with http and no www', function (done) {
992
- Organization.findBySocial('http://linkedin.com/company/abc', function (err, result) {
903
+ Organization.findBySocial('http://linkedin.com/company/abc', { CUSTOMER_ID: customer1._id }, function (err, result) {
993
904
  should.not.exist(err);
994
905
  should.exist(result);
995
906
  result.length.should.equal(1);
@@ -998,7 +909,7 @@ describe('Organization', function() {
998
909
  });
999
910
 
1000
911
  it('finds orgs by social when just a username', function (done) {
1001
- Organization.findBySocial('abc', function (err, result) {
912
+ Organization.findBySocial('abc', { CUSTOMER_ID: customer1._id }, function (err, result) {
1002
913
  should.not.exist(err);
1003
914
  should.exist(result);
1004
915
  result.length.should.equal(1);
@@ -1007,7 +918,7 @@ describe('Organization', function() {
1007
918
  });
1008
919
 
1009
920
  it('finds orgs by social when just a username with an at', function (done) {
1010
- Organization.findBySocial('@abc', function (err, result) {
921
+ Organization.findBySocial('@abc', { CUSTOMER_ID: customer1._id }, function (err, result) {
1011
922
  should.not.exist(err);
1012
923
  should.exist(result);
1013
924
  result.length.should.equal(1);
@@ -1016,7 +927,7 @@ describe('Organization', function() {
1016
927
  });
1017
928
 
1018
929
  it('finds orgs by ids', function (done) {
1019
- Organization.findByIds([org4._id, org5._id], function (err, result) {
930
+ Organization.findByIds([org4._id, org5._id], { CUSTOMER_ID: customer1._id }, function (err, result) {
1020
931
  should.not.exist(err);
1021
932
  should.exist(result);
1022
933
  result.length.should.equal(2);
@@ -1025,7 +936,7 @@ describe('Organization', function() {
1025
936
  });
1026
937
 
1027
938
  it('finds org by domain alias', function (done) {
1028
- Organization.findByDomains(['doesnotexist.io', 'myolddomain.ch'], function (err, result) {
939
+ Organization.findByDomains(['doesnotexist.io', 'myolddomain.ch'], { CUSTOMER_ID: customer1._id }, function (err, result) {
1029
940
  should.not.exist(err);
1030
941
  should.exist(result);
1031
942
  result.length.should.equal(1);
@@ -1035,7 +946,7 @@ describe('Organization', function() {
1035
946
 
1036
947
  it('adds a flag', function (done) {
1037
948
 
1038
- Organization.addFlag(org4.id, person._id, 'Sweet flag bro!', function (err, result) {
949
+ Organization.addFlag(org4.id, person._id, 'Sweet flag bro!', org2._id, function (err, result) {
1039
950
 
1040
951
  should.not.exist(err);
1041
952
  should.exist(result);
@@ -1051,48 +962,6 @@ describe('Organization', function() {
1051
962
 
1052
963
  });
1053
964
 
1054
- it('deletes a flag', function (done) {
1055
-
1056
- Organization.deleteFlag(flagId, function (err, result) {
1057
-
1058
- should.not.exist(err);
1059
-
1060
- return done();
1061
-
1062
- });
1063
-
1064
- });
1065
-
1066
- it('adds a note', function (done) {
1067
-
1068
- Organization.addNote(org4.id, person._id, 'Sweet note bro!', false, function (err, result) {
1069
-
1070
- should.not.exist(err);
1071
- should.exist(result);
1072
- should.exist(result.note);
1073
- should.exist(result.addedTo);
1074
- result.addedTo.notes.length.should.equal(1);
1075
-
1076
- noteId = result.addedTo.notes[0];
1077
-
1078
- return done();
1079
-
1080
- });
1081
-
1082
- });
1083
-
1084
- it('deletes a simple note', function (done) {
1085
-
1086
- Organization.deleteNote(noteId, function (err, result) {
1087
-
1088
- should.not.exist(err);
1089
-
1090
- return done();
1091
-
1092
- });
1093
-
1094
- });
1095
-
1096
965
  it('formats website domains', function (done) {
1097
966
 
1098
967
  var temp = new Organization();
@@ -1118,7 +987,7 @@ describe('Organization', function() {
1118
987
  result.websiteAliases.indexOf('abc.subdomain.com').should.not.equal(-1);
1119
988
  result.websiteAliases.indexOf('trailingslash.edu').should.not.equal(-1);
1120
989
 
1121
- Organization.getById(temp._id, {role: 'lp-full'}, function (err, result) {
990
+ Organization.getById(temp._id, { CUSTOMER_ID: org2._id, role: 'lp-full' }, function (err, result) {
1122
991
 
1123
992
  should.not.exist(err);
1124
993
  should.exist(result);
@@ -1138,9 +1007,9 @@ describe('Organization', function() {
1138
1007
 
1139
1008
  var lp = new LimitedPartner();
1140
1009
  lp.name = 'LP';
1141
- lp.customer = config.CUSTOMER_ID;
1010
+ lp.customer = org2;
1142
1011
 
1143
- LimitedPartner.upsert(lp, 'test', 'lp-full', function (err, lpResult) {
1012
+ LimitedPartner.upsert(lp, 'test', { role: 'lp-full' }, function (err, lpResult) {
1144
1013
 
1145
1014
  should.not.exist(err);
1146
1015
  should.exist(lpResult);
@@ -1157,14 +1026,14 @@ describe('Organization', function() {
1157
1026
  should.not.exist(err);
1158
1027
  should.exist(orgResult);
1159
1028
 
1160
- Organization.getById(orgResult._id, {role: 'lp-full'}, function (err, result) {
1029
+ Organization.getById(orgResult._id, { CUSTOMER_ID: org2._id, role: 'lp-full' }, function (err, result) {
1161
1030
 
1162
1031
  should.not.exist(err);
1163
1032
  should.exist(result);
1164
1033
  result.lps.length.should.equal(1);
1165
1034
  result.lps[0]._id.toString().should.equal(lpResult._id.toString());
1166
1035
 
1167
- Organization.getById(orgResult._id, {role: 'none'}, function (err, result) {
1036
+ Organization.getById(orgResult._id, { CUSTOMER_ID: org2._id, role: 'none' }, function (err, result) {
1168
1037
 
1169
1038
  should.not.exist(err);
1170
1039
  should.exist(result);
@@ -1384,113 +1253,6 @@ describe('Organization', function() {
1384
1253
 
1385
1254
  return done();
1386
1255
 
1387
-
1388
- });
1389
-
1390
- it('adds a deal', function(done) {
1391
-
1392
- config.CUSTOMER_ID = customer1._id.toString();
1393
-
1394
- deal = new Deal({
1395
- customer: customer1,
1396
- organization: org3,
1397
- stage: 'New'
1398
- });
1399
-
1400
- Organization.addDeal(deal, account, function(err, result) {
1401
-
1402
- should.not.exist(err);
1403
- should.exist(result);
1404
- result.org.deals.length.should.equal(1);
1405
-
1406
- deal = result.deal;
1407
-
1408
- return done();
1409
-
1410
- });
1411
-
1412
- });
1413
-
1414
- it('adds a deal again', function(done) {
1415
-
1416
- var d = new Deal({
1417
- customer: customer1,
1418
- organization: org3,
1419
- stage: 'New'
1420
- });
1421
-
1422
- Organization.addDeal(d, account, function(err, result) {
1423
-
1424
- should.exist(err);
1425
- should.not.exist(result);
1426
-
1427
- return done();
1428
-
1429
- });
1430
-
1431
- });
1432
-
1433
- it('adds a deal with an inactive state', function(done) {
1434
-
1435
- var d = new Deal({
1436
- customer: customer1,
1437
- organization: org4,
1438
- stage: 'Pending'
1439
- });
1440
-
1441
- Organization.addDeal(d, account, function(err, result) {
1442
-
1443
- should.exist(err);
1444
- should.not.exist(result);
1445
-
1446
- return done();
1447
-
1448
- });
1449
-
1450
- });
1451
-
1452
- it('adds a deal for another customer', function(done) {
1453
-
1454
- config.CUSTOMER_ID = customer2._id.toString();
1455
-
1456
- var org6 = new Organization();
1457
- org6.name = 'Newest Co';
1458
- org6.slug = 'newest-co';
1459
-
1460
- Organization.upsert(org6, 'test-user', function(err, result1) {
1461
-
1462
- should.not.exist(err);
1463
- should.exist(result1);
1464
-
1465
- var d = new Deal({
1466
- customer: customer2,
1467
- organization: result1,
1468
- stage: 'Pass'
1469
- });
1470
-
1471
- Organization.addDeal(d, account, function(err, result2) {
1472
-
1473
- should.not.exist(err);
1474
- should.exist(result2);
1475
-
1476
- return done();
1477
-
1478
- });
1479
-
1480
- });
1481
-
1482
- });
1483
-
1484
- it('deletes a deal', function (done) {
1485
-
1486
- Organization.deleteDeal(deal._id, function (err, result) {
1487
-
1488
- should.not.exist(err);
1489
-
1490
- return done();
1491
-
1492
- });
1493
-
1494
1256
  });
1495
1257
 
1496
1258
  });
@@ -1556,7 +1318,7 @@ describe('Organization', function() {
1556
1318
  });
1557
1319
 
1558
1320
  org.operating.acquired.private.push({
1559
- customer: config.CUSTOMER_ID,
1321
+ customer: org2._id,
1560
1322
  by: new mongoose.Types.ObjectId(),
1561
1323
  acquiredOn: new Date(),
1562
1324
  amount: 4
@@ -1567,13 +1329,14 @@ describe('Organization', function() {
1567
1329
  should.not.exist(err);
1568
1330
  should.exist(result);
1569
1331
 
1570
- Organization.findById(result._id, function(err, org) {
1332
+ Organization.getById(result._id, { CUSTOMER_ID: org2._id }, function(err, org) {
1571
1333
 
1572
1334
  should.not.exist(err);
1573
1335
  should.exist(org);
1574
1336
 
1575
1337
  org.status.should.equal('Acquired');
1576
1338
  org.acquired.amount.should.equal(4);
1339
+
1577
1340
  return done();
1578
1341
 
1579
1342
  });
@@ -1617,7 +1380,7 @@ describe('Organization', function() {
1617
1380
  });
1618
1381
 
1619
1382
  org.operating.closed.private.push({
1620
- customer: config.CUSTOMER_ID,
1383
+ customer: org2._id,
1621
1384
  hasZeroUnrealizedValue: false,
1622
1385
  closedOn: new Date()
1623
1386
  });
@@ -1627,7 +1390,7 @@ describe('Organization', function() {
1627
1390
  should.not.exist(err);
1628
1391
  should.exist(result);
1629
1392
 
1630
- Organization.findById(result._id, function(err, org) {
1393
+ Organization.getById(result._id, { CUSTOMER_ID: org2._id }, function(err, org) {
1631
1394
  should.not.exist(err);
1632
1395
  should.exist(org);
1633
1396
  org.status.should.equal('Shutdown');
@@ -1651,7 +1414,7 @@ describe('Organization', function() {
1651
1414
  });
1652
1415
 
1653
1416
  org.operating.closed.private.push({
1654
- customer: config.CUSTOMER_ID,
1417
+ customer: org2._id,
1655
1418
  hasZeroUnrealizedValue: true,
1656
1419
  closedOn: null
1657
1420
  });
@@ -1661,7 +1424,7 @@ describe('Organization', function() {
1661
1424
  should.not.exist(err);
1662
1425
  should.exist(result);
1663
1426
 
1664
- Organization.findById(result._id, function(err, org) {
1427
+ Organization.getById(result._id, { CUSTOMER_ID: org2._id }, function(err, org) {
1665
1428
  should.not.exist(err);
1666
1429
  should.exist(org);
1667
1430
  org.status.should.equal('Inactive');
@@ -1673,41 +1436,4 @@ describe('Organization', function() {
1673
1436
 
1674
1437
  });
1675
1438
 
1676
- // not yet tested:
1677
- // listAllFlagged
1678
- // listPage
1679
- // removeById
1680
- // stats
1681
-
1682
- // it('does not duplicate website domains with investors', function(done) {
1683
- //
1684
- // var investor = new Investor();
1685
- // investor.name = 'I Love Unique Domains';
1686
- // investor.slug = 'i-love-unique-domains';
1687
- // investor.type = 'venture_capital';
1688
- // investor.deleted = false;
1689
- // investor.website = 'myuniquedomain.com';
1690
- // investor.websiteAliases = [];
1691
- //
1692
- // Investor.upsert(investor, 'test-user', function(err, result) {
1693
- //
1694
- // should.not.exist(err);
1695
- // should.exist(result);
1696
- //
1697
- // var temp = new Organization();
1698
- // temp.name = 'I Love to Duplicate Domains';
1699
- // temp.slug = 'i-love-to-duplicate';
1700
- // temp.deleted = false;
1701
- // temp.website = 'myuniquedomain.com';
1702
- // temp.websiteAliases = [];
1703
- //
1704
- // Organization.upsert(temp, 'test-user', function(err, result) {
1705
- // should.exist(err);
1706
- // return done();
1707
- // });
1708
- //
1709
- // });
1710
- //
1711
- // });
1712
-
1713
1439
  });