@dhyasama/totem-models 4.4.1 → 4.5.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "4.4.1",
3
+ "version": "4.5.1",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",
@@ -30,6 +30,7 @@
30
30
  "validator": "^5.4.0"
31
31
  },
32
32
  "devDependencies": {
33
+ "mocha": "^5.2.0",
33
34
  "mocha-mongoose": "^1.2.0",
34
35
  "mongoose": "~4.5.7",
35
36
  "nock": "^7.2.2",
@@ -11,7 +11,8 @@ var
11
11
  Person = mongoose.model('Person'),
12
12
  LimitedPartner = mongoose.model('LimitedPartner'),
13
13
  Fund = mongoose.model('Fund'),
14
- Note = mongoose.model('Note');
14
+ Note = mongoose.model('Note'),
15
+ Account = mongoose.model('Account');
15
16
 
16
17
  var person, person1, person2;
17
18
  var noteId;
@@ -19,8 +20,10 @@ var eventNote;
19
20
  var flagId;
20
21
  var someOtherFund;
21
22
  var someOtherLp;
23
+ var account;
24
+ var customer1, customer2;
22
25
 
23
- describe('Organization', function() {
26
+ describe.only('Organization', function() {
24
27
 
25
28
  var org1, org2, org3, org4, org5;
26
29
  var mergeId = new mongoose.Types.ObjectId();
@@ -128,6 +131,96 @@ describe('Organization', function() {
128
131
 
129
132
  });
130
133
 
134
+ });
135
+
136
+ before(function(done) {
137
+
138
+ customer1 = new Organization();
139
+ customer1.name = 'New Customer';
140
+ customer1.slug = 'new-customer';
141
+ customer1.customer.active = true;
142
+ customer1.customer.deals = {
143
+ active: true,
144
+ statuses: [
145
+ {
146
+ name: 'New',
147
+ order: 1,
148
+ active: true
149
+ },
150
+ {
151
+ name: 'Diligence',
152
+ order: 3,
153
+ active: true
154
+ },
155
+ {
156
+ name: 'Pass',
157
+ order: 2,
158
+ active: true
159
+ },
160
+ {
161
+ name: 'Pending',
162
+ order: 4,
163
+ active: false
164
+ }
165
+ ]
166
+ };
167
+
168
+ Organization.upsert(customer1, 'test-user', function(err, result) {
169
+
170
+ should.not.exist(err);
171
+ should.exist(result);
172
+
173
+ customer1 = result;
174
+
175
+ return done();
176
+
177
+ });
178
+
179
+ });
180
+
181
+ before(function(done) {
182
+
183
+ customer2 = new Organization();
184
+ customer2.name = 'Newer Customer';
185
+ customer2.slug = 'newer-customer';
186
+ customer2.customer.active = true;
187
+ customer2.customer.deals = {
188
+ active: true,
189
+ statuses: [
190
+ {
191
+ name: 'New',
192
+ order: 1,
193
+ active: true
194
+ },
195
+ {
196
+ name: 'Diligence',
197
+ order: 3,
198
+ active: true
199
+ },
200
+ {
201
+ name: 'Pass',
202
+ order: 2,
203
+ active: true
204
+ },
205
+ {
206
+ name: 'Pending',
207
+ order: 4,
208
+ active: false
209
+ }
210
+ ]
211
+ };
212
+
213
+ Organization.upsert(customer2, 'test-user', function(err, result) {
214
+
215
+ should.not.exist(err);
216
+ should.exist(result);
217
+
218
+ customer2 = result;
219
+
220
+ return done();
221
+
222
+ });
223
+
131
224
  });
132
225
 
133
226
  before(function(done) {
@@ -260,6 +353,26 @@ describe('Organization', function() {
260
353
 
261
354
  });
262
355
 
356
+ before(function(done) {
357
+
358
+ account = new Account();
359
+ account.username = 'test-user';
360
+ account.email = 'test@totemvc.com';
361
+ account.person = person1;
362
+
363
+ Account.upsert(account, function (err, result) {
364
+
365
+ should.not.exist(err);
366
+ should.exist(result);
367
+
368
+ account = result;
369
+
370
+ return done();
371
+
372
+ });
373
+
374
+ });
375
+
263
376
  it('it soft deletes an org', function(done) {
264
377
 
265
378
  org4.deleteOrg();
@@ -1006,6 +1119,146 @@ describe('Organization', function() {
1006
1119
 
1007
1120
  });
1008
1121
 
1122
+ describe('Deals', function() {
1123
+
1124
+ var org;
1125
+
1126
+ it('gets deal statuses for a customer', function(done) {
1127
+
1128
+ var temp = config.CUSTOMER_ID;
1129
+ config.CUSTOMER_ID = customer1._id.toString();
1130
+
1131
+ var statuses = customer1.customer.deals.activeStatuses;
1132
+ statuses.length.should.equal(3);
1133
+ statuses[0].should.equal('New');
1134
+ statuses[1].should.equal('Pass');
1135
+ statuses[2].should.equal('Diligence');
1136
+
1137
+ config.CUSTOMER_ID = temp;
1138
+
1139
+ return done();
1140
+
1141
+
1142
+ });
1143
+
1144
+ it('adds a deal', function(done) {
1145
+
1146
+ org = new Organization();
1147
+ org.name = 'New Co';
1148
+ org.slug = 'new-co';
1149
+
1150
+ Organization.upsert(org, 'test-user', function(err, result) {
1151
+
1152
+ should.not.exist(err);
1153
+ should.exist(result);
1154
+
1155
+ result.addDeal('New', customer1, account);
1156
+
1157
+ Organization.upsert(result, 'test-user', function(err, result) {
1158
+
1159
+ should.not.exist(err);
1160
+ should.exist(result);
1161
+ result.deals.length.should.equal(1);
1162
+
1163
+ org = result;
1164
+
1165
+ return done();
1166
+
1167
+ });
1168
+
1169
+ });
1170
+
1171
+ });
1172
+
1173
+ it('adds a deal again', function(done) {
1174
+
1175
+ var threwError = false;
1176
+
1177
+ try {
1178
+ org.addDeal('Pass', customer1, account);
1179
+ }
1180
+ catch (err) {
1181
+ threwError = true;
1182
+ }
1183
+
1184
+ threwError.should.equal(false);
1185
+ org.deals.length.should.equal(1);
1186
+ org.deals[0].status.should.equal('Pass');
1187
+
1188
+ return done();
1189
+
1190
+ });
1191
+
1192
+ it('adds a deal with an inactive state', function(done) {
1193
+
1194
+ var threwError = false;
1195
+
1196
+ try {
1197
+ org.addDeal('Pending', customer1, account);
1198
+ }
1199
+ catch (err) {
1200
+ threwError = true;
1201
+ }
1202
+
1203
+ threwError.should.equal(true);
1204
+
1205
+ return done();
1206
+
1207
+ });
1208
+
1209
+ it('adds a deal for another customer', function(done) {
1210
+
1211
+ var org2 = new Organization();
1212
+ org2.name = 'Newest Co';
1213
+ org2.slug = 'newest-co';
1214
+
1215
+ Organization.upsert(org2, 'test-user', function(err, result) {
1216
+
1217
+ should.not.exist(err);
1218
+ should.exist(result);
1219
+
1220
+ result.addDeal('Pass', customer2, account);
1221
+
1222
+ Organization.upsert(result, 'test-user', function(err, result) {
1223
+
1224
+ should.not.exist(err);
1225
+ should.exist(result);
1226
+ result.deals.length.should.equal(1);
1227
+
1228
+ org = result;
1229
+
1230
+ return done();
1231
+
1232
+ });
1233
+
1234
+ });
1235
+
1236
+ });
1237
+
1238
+ it('gets deals', function(done) {
1239
+
1240
+ var temp = config.CUSTOMER_ID;
1241
+ config.CUSTOMER_ID = customer1._id.toString();
1242
+
1243
+ Organization.getDeals(function(err, result) {
1244
+
1245
+ should.not.exist(err);
1246
+ should.exist(result);
1247
+ result.length.should.equal(1);
1248
+ result[0].name.should.equal('New Co');
1249
+ result[0].deals.length.should.equal(1);
1250
+ result[0].deals[0].customer.toString().should.equal(customer1._id.toString());
1251
+
1252
+ config.CUSTOMER_ID = temp;
1253
+
1254
+ return done();
1255
+
1256
+ });
1257
+
1258
+ });
1259
+
1260
+ });
1261
+
1009
1262
  describe('State', function() {
1010
1263
 
1011
1264
  it('gets ipo info', function(done) {