@dhyasama/totem-models 7.58.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.
@@ -1,554 +1,399 @@
1
- // "use strict";
2
- //
3
- // var
4
- //
5
- // should = require("should"),
6
- // config = require('./config')['test'],
7
- // mongoose = require('mongoose'),
8
- // clearDB = require('mocha-mongoose')(config.db.uri, {noClear: true}),
9
- // LimitedPartner = mongoose.model('LimitedPartner'),
10
- // lp = new LimitedPartner(),
11
- // lpid,
12
- // Person = mongoose.model('Person'),
13
- // person = new Person(),
14
- // person1, person2,
15
- // Fund = mongoose.model('Fund'),
16
- // fund = new Fund(),
17
- // noteId,
18
- // Note = mongoose.model('Note'),
19
- // Organization = mongoose.model('Organization'),
20
- // organization = new Organization();
21
- //
22
- // var eventNote;
23
- //
24
- //
25
- //
26
- // describe.only('Limited Partner', function() {
27
- //
28
- // before(function(done) {
29
- // if (mongoose.connection.db) return done();
30
- // mongoose.connect(config.db.uri, done);
31
- // });
32
- //
33
- // before(function(done) {
34
- // clearDB(done);
35
- // });
36
- //
37
- // before(function(done) {
38
- // organization.name = 'My Org';
39
- // organization.slug = 'my-org';
40
- // Organization.upsert(organization, 'test', function(err, result) {
41
- // should.not.exist(err);
42
- // should.exist(result);
43
- // organization = result;
44
- // config.CUSTOMER_ID = organization._id.toString();
45
- // done();
46
- // });
47
- // });
48
- //
49
- // before(function(done) {
50
- // fund.name = 'My Huge Fund';
51
- // fund.slug = 'my-huge-fund';
52
- // fund.shortName = 'mhf';
53
- // Fund.upsert(fund, 'test', function(err, result) {
54
- // should.not.exist(err);
55
- // should.exist(result);
56
- // fund = result;
57
- // done();
58
- // });
59
- // });
60
- //
61
- // before(function(done) {
62
- //
63
- // person1 = new Person();
64
- // person1.name.first = 'Mischa';
65
- // person1.name.last = 'Barton';
66
- // person1.slug = 'mischa-barton';
67
- //
68
- // Person.upsert(person1, 'test', function (err, newPerson) {
69
- //
70
- // should.not.exist(err);
71
- // should.exist(newPerson);
72
- //
73
- // person1 = newPerson;
74
- //
75
- // return done();
76
- //
77
- // });
78
- //
79
- // });
80
- //
81
- // before(function(done) {
82
- //
83
- // person2 = new Person();
84
- // person2.name.first = 'Carrie';
85
- // person2.name.last = 'Coon';
86
- // person2.slug = 'carrie-coon';
87
- //
88
- // Person.upsert(person2, 'test', function (err, newPerson) {
89
- //
90
- // should.not.exist(err);
91
- // should.exist(newPerson);
92
- //
93
- // person2 = newPerson;
94
- //
95
- // return done();
96
- //
97
- // });
98
- //
99
- // });
100
- //
101
- // before(function(done) {
102
- //
103
- // person = new Person();
104
- // person.name.first = 'George';
105
- // person.name.last = 'Costanza';
106
- // person.slug = 'george';
107
- // person.avatarUrl = 'tiger.jpg';
108
- //
109
- // Person.upsert(person, 'test', function (err, newPerson) {
110
- //
111
- // var eventSummary = {
112
- // calendarEventId: new mongoose.Types.ObjectId(),
113
- // providerEventId: 'some_other_random_data',
114
- // totemCustomerId: config.CUSTOMER_ID,
115
- // summary: 'The Russians are coming',
116
- // startTime: new Date(),
117
- // attendees: {
118
- // internal: [person1],
119
- // external: [person2]
120
- // }
121
- // };
122
- //
123
- // newPerson.calendarEventSummaries.push(eventSummary);
124
- //
125
- // Person.upsert(newPerson, 'test', function(err, newNewPerson) {
126
- //
127
- // should.not.exist(err);
128
- // should.exist(newNewPerson);
129
- //
130
- // person = newNewPerson;
131
- //
132
- // person.calendarEventSummaries.length.should.equal(1);
133
- //
134
- // return done();
135
- //
136
- // });
137
- //
138
- // });
139
- //
140
- // });
141
- //
142
- // before(function(done) {
143
- //
144
- // var providerEventId = 'some_other_random_data';
145
- // var creator = person._id;
146
- // var text = 'Sweet note bro!';
147
- //
148
- // Note.createForCalendarEvent(providerEventId, creator, text, function(err, result) {
149
- //
150
- // should.not.exist(err);
151
- // should.exist(result);
152
- //
153
- // //result.notes.length.should.equal(1);
154
- // //result.id.toString().should.equal(person2.id.toString());
155
- //
156
- // eventNote = result;
157
- //
158
- // return done();
159
- //
160
- // });
161
- //
162
- // });
163
- //
164
- // it('adds a limited partner', function(done) {
165
- //
166
- // lp.name = 'United Testers';
167
- // lp.k1.nameOfInvestor = 'United T';
168
- //
169
- // lp.fundsInvested.push({
170
- // fund: fund,
171
- // committed: 1000000,
172
- // called: 400000
173
- // });
174
- //
175
- // lp.contact.phone.push({
176
- // type: 'other',
177
- // number: '12079396565',
178
- // primary: true
179
- // });
180
- //
181
- // lp.contact.email.push({
182
- // type: 'other',
183
- // email: 'dhyasama+test@gmail.com',
184
- // primary: true
185
- // });
186
- //
187
- // lp.contact.address.push({
188
- // street: '121 Union St',
189
- // city: 'Brewer',
190
- // state: 'ME',
191
- // country: 'USA',
192
- // postalCode: '04412',
193
- // primary: true
194
- // });
195
- //
196
- // LimitedPartner.upsert(lp, 'test', 'admin', function(err, updatedLp) {
197
- // should.not.exist(err);
198
- // should.exist(updatedLp);
199
- // lp = updatedLp;
200
- // done();
201
- // });
202
- //
203
- // });
204
- //
205
- // it('searches for an lp', function(done) {
206
- //
207
- // LimitedPartner.search('United', 'admin', function(err, result) {
208
- //
209
- // should.not.exist(err);
210
- // should.exist(result);
211
- //
212
- // // not sure how to refactor test
213
- // // there is an lp that matches 'United' but it's not returned because the LP.search method filters down to
214
- // // customer funds and in this test customer is created dynamically so config.CUSTOMER_ID in LP is off
215
- //
216
- // result.length.should.equal(0);
217
- // done();
218
- //
219
- // });
220
- //
221
- // });
222
- //
223
- // it('updates a limited partner', function(done) {
224
- //
225
- // LimitedPartner.getById(lp._id, 'admin', function(err, result) {
226
- //
227
- // // not sure how to refactor test
228
- // // there is an lp that matches 'United' but it's not returned because the LP.search method filters down to
229
- // // customer funds and in this test customer is created dynamically so config.CUSTOMER_ID in LP is off
230
- //
231
- // should.not.exist(err);
232
- // should.exist(result);
233
- // lp.name = 'Changed Name';
234
- //
235
- // LimitedPartner.upsert(result, 'test', 'admin', function(err, updatedLp) {
236
- // should.not.exist(err);
237
- // should.exist(updatedLp);
238
- // lp.name.should.equal('Changed Name');
239
- // lp = updatedLp;
240
- // done();
241
- // });
242
- //
243
- // });
244
- //
245
- // });
246
- //
247
- // it('adds a person to an lp', function(done) {
248
- //
249
- // // not sure how to refactor test
250
- // // there is an lp that matches 'United' but it's not returned because the LP.search method filters down to
251
- // // customer funds and in this test customer is created dynamically so config.CUSTOMER_ID in LP is off
252
- //
253
- // LimitedPartner.getById(lp.id, 'admin', function(err, result) {
254
- //
255
- // result.addPerson(person.id);
256
- //
257
- // LimitedPartner.upsert(result, 'test', 'admin', function(err, updatedLp) {
258
- // should.not.exist(err);
259
- // should.exist(updatedLp);
260
- // updatedLp.people.length.should.equal(1);
261
- // done();
262
- // });
263
- //
264
- // });
265
- //
266
- // });
267
- //
268
- // it('tries to add a person to an lp again', function(done) {
269
- //
270
- // // must be a better way to do this
271
- // // successful test means addPerson throws an error
272
- // // if the should in the try is hit then the test fails
273
- //
274
- // try {
275
- // lp.addPerson(person.id);
276
- // should.exist(e);
277
- // }
278
- // catch(e) {
279
- // should.exist(e);
280
- // };
281
- //
282
- // done();
283
- //
284
- // });
285
- //
286
- // it('lists people at an lp', function(done) {
287
- //
288
- // LimitedPartner.listPeople(lp.id, 'admin', function(err, result) {
289
- //
290
- // should.not.exist(err);
291
- // should.exist(result);
292
- // result.length.should.equal(1);
293
- //
294
- // done();
295
- //
296
- // });
297
- //
298
- // });
299
- //
300
- // it('lists limited partners', function(done) {
301
- // LimitedPartner.list('admin', function(err, lps) {
302
- // should.not.exist(err);
303
- // should.exist(lps);
304
- // lps.length.should.equal(1);
305
- // done();
306
- // });
307
- // });
308
- //
309
- // it('finds limited partners by person id', function(done) {
310
- // LimitedPartner.getByPersonId(person._id, 'lp-full', function(err, result) {
311
- // should.not.exist(err);
312
- // should.exist(result);
313
- // result.length.should.equal(1);
314
- // done();
315
- // });
316
- // });
317
- //
318
- // it('finds a limited partner by id', function(done) {
319
- // LimitedPartner.getById(lp.id, 'admin', function(err, result) {
320
- // should.not.exist(err);
321
- // should.exist(result);
322
- // result.id.should.equal(lp.id);
323
- // done();
324
- // });
325
- // });
326
- //
327
- // it('finds a limited partner by id with a populated event note', function(done) {
328
- // LimitedPartner.getById(lp.id, 'admin', function(err, result) {
329
- // should.not.exist(err);
330
- // should.exist(result);
331
- // should.exist(result.people);
332
- // result.people.length.should.equal(1);
333
- // should.exist(result.people[0].calendarEventSummaries);
334
- // result.people[0].calendarEventSummaries.length.should.equal(1);
335
- // should.exist(result.people[0].calendarEventSummaries[0].notes);
336
- // result.people[0].calendarEventSummaries[0].notes.length.should.equal(1);
337
- // should.exist(result.people[0].calendarEventSummaries[0].notes[0].createdBy);
338
- // return done();
339
- // });
340
- // });
341
- //
342
- // it('gets percent of fund called', function(done) {
343
- // var result = lp.fundPercentCalled(lp.fundsInvested[0].fund);
344
- // result.should.equal(40);
345
- // done();
346
- // });
347
- //
348
- // it('lists active funds', function(done) {
349
- //
350
- // lp.listActiveFunds(function(err, result) {
351
- // should.not.exist(err);
352
- // should.exist(result);
353
- // result.length.should.equal(1);
354
- // result[0].fund.slug.should.equal('my-huge-fund');
355
- // done();
356
- //
357
- // });
358
- //
359
- // });
360
- //
361
- // it('finds the primary email for an lp', function(done) {
362
- //
363
- // LimitedPartner.getById(lp.id, 'admin', function(err, partner) {
364
- //
365
- // should.not.exist(err);
366
- // should.exist(partner);
367
- //
368
- // partner.email.primary.should.equal('dhyasama+test@gmail.com');
369
- //
370
- // done();
371
- //
372
- // });
373
- //
374
- // });
375
- //
376
- // it('finds the primary phone for an lp', function(done) {
377
- //
378
- // LimitedPartner.getById(lp.id, 'admin', function(err, lp) {
379
- //
380
- // should.not.exist(err);
381
- // should.exist(lp);
382
- //
383
- // lp.phone.primary.should.equal('12079396565');
384
- //
385
- // done();
386
- //
387
- // });
388
- //
389
- // });
390
- //
391
- // it('finds the primary address for an lp', function(done) {
392
- //
393
- // LimitedPartner.getById(lp.id, 'admin', function(err, lp) {
394
- //
395
- // should.not.exist(err);
396
- // should.exist(lp);
397
- //
398
- // lp.address.primary.postalCode.should.equal('04412');
399
- //
400
- // done();
401
- //
402
- // });
403
- //
404
- // });
405
- //
406
- // it('does not find k1 for an lp if not allowed', function(done) {
407
- //
408
- // LimitedPartner.getById(lp.id, 'lp-names', function(err, result) {
409
- //
410
- // should.not.exist(err);
411
- // should.exist(result);
412
- // should.not.exist(result.k1.nameOfInvestor);
413
- //
414
- // done();
415
- //
416
- // });
417
- //
418
- // });
419
- //
420
- // it('finds k1 for an lp if allowed', function(done) {
421
- //
422
- // LimitedPartner.getById(lp.id, 'lp-full', function(err, lp) {
423
- //
424
- // should.not.exist(err);
425
- // should.exist(lp);
426
- // lp.k1.nameOfInvestor.should.equal('United T');
427
- //
428
- // done();
429
- //
430
- // });
431
- //
432
- // });
433
- //
434
- // it('finds name for an lp if allowed', function(done) {
435
- //
436
- // LimitedPartner.getById(lp.id, 'lp-names', function(err, lp) {
437
- //
438
- // should.not.exist(err);
439
- // should.exist(lp);
440
- // should.exist(lp.name);
441
- //
442
- // done();
443
- //
444
- // });
445
- //
446
- // });
447
- //
448
- // it('flags an lp as an admin', function(done) {
449
- //
450
- // LimitedPartner.flag(lp.id, false, 'incorrect phone', 'testy', 'admin', function(err, lp) {
451
- //
452
- // should.not.exist(err);
453
- // should.exist(lp);
454
- // should.exist(lp.name);
455
- // lp.flagged.resolved.should.equal(false);
456
- //
457
- // done();
458
- //
459
- // });
460
- //
461
- // });
462
- //
463
- // it('flags an lp as a limited user', function(done) {
464
- //
465
- // LimitedPartner.flag(lp.id, false, 'incorrect phone', 'testy', 'lp-names', function(err, lp) {
466
- //
467
- // should.not.exist(err);
468
- // should.exist(lp);
469
- // should.exist(lp.name);
470
- // lp.flagged.resolved.should.equal(false);
471
- //
472
- // done();
473
- //
474
- // });
475
- //
476
- // it('does not flag an lp as a nobody', function(done) {
477
- //
478
- // LimitedPartner.flag(lp.id, false, 'incorrect phone', 'testy', 'none', function (err, lp) {
479
- //
480
- // should.not.exist(err);
481
- // should.exist(lp);
482
- // should.not.exist(lp.flagged);
483
- //
484
- // done();
485
- //
486
- // });
487
- //
488
- // });
489
- //
490
- // });
491
- //
492
- // it('adds a note', function(done) {
493
- //
494
- // LimitedPartner.addNote(lp.id, person._id, 'Sweet note bro!', function(err, result) {
495
- //
496
- // should.not.exist(err);
497
- // should.exist(result);
498
- // should.exist(result.note);
499
- // should.exist(result.addedTo);
500
- // result.addedTo.notes.length.should.equal(1);
501
- //
502
- // noteId = result.addedTo.notes[0];
503
- //
504
- // return done();
505
- //
506
- // });
507
- //
508
- // });
509
- //
510
- // it('gets an lp by id with a populated note', function(done) {
511
- // LimitedPartner.getById(lp.id, 'admin', function(err, result) {
512
- // should.not.exist(err);
513
- // should.exist(result);
514
- // result.id.should.equal(lp.id);
515
- // should.exist(result.notes);
516
- // result.notes.length.should.equal(1);
517
- // should.exist(result.notes[0].createdBy);
518
- // should.exist(result.notes[0].createdBy.avatarUrl);
519
- // result.notes[0].createdBy.avatarUrl.length.should.be.above(0);
520
- // should.exist(result.notes[0].createdBy.name);
521
- // should.exist(result.notes[0].createdBy.name.first);
522
- // result.notes[0].createdBy.name.first.length.should.be.above(0);
523
- // done();
524
- // });
525
- // });
526
- //
527
- // it('deletes a note', function(done) {
528
- //
529
- // LimitedPartner.deleteNote(noteId, function(err, result) {
530
- //
531
- // should.not.exist(err);
532
- //
533
- // return done();
534
- //
535
- // });
536
- //
537
- // });
538
- //
539
- // it('deletes an event note', function(done) {
540
- //
541
- // LimitedPartner.deleteNote(eventNote.id, function(err, result) {
542
- //
543
- // should.not.exist(err);
544
- //
545
- // return done();
546
- //
547
- // });
548
- //
549
- // });
550
- //
551
- // // todo - findbytransaction
552
- // // todo - distributions
553
- //
554
- // });
1
+ "use strict";
2
+
3
+ var
4
+
5
+ should = require("should"),
6
+ config = require('./config')['test'],
7
+ mongoose = require('mongoose'),
8
+ clearDB = require('mocha-mongoose')(config.db.uri, {noClear: true}),
9
+ LimitedPartner = mongoose.model('LimitedPartner'),
10
+ lp = new LimitedPartner(),
11
+ Person = mongoose.model('Person'),
12
+ person = new Person(),
13
+ person1, person2,
14
+ Fund = mongoose.model('Fund'),
15
+ fund = new Fund(),
16
+ noteId,
17
+ Organization = mongoose.model('Organization'),
18
+ organization = new Organization();
19
+
20
+
21
+ describe('Limited Partner', function() {
22
+
23
+ before(function(done) {
24
+ if (mongoose.connection.db) return done();
25
+ mongoose.connect(config.db.uri, done);
26
+ });
27
+
28
+ before(function(done) {
29
+ clearDB(done);
30
+ });
31
+
32
+ before(function(done) {
33
+ organization.name = 'My Org';
34
+ organization.slug = 'my-org';
35
+ Organization.upsert(organization, 'test', function(err, result) {
36
+ should.not.exist(err);
37
+ should.exist(result);
38
+ organization = result;
39
+ done();
40
+ });
41
+ });
42
+
43
+ before(function(done) {
44
+ fund.name = 'My Huge Fund';
45
+ fund.slug = 'my-huge-fund';
46
+ fund.shortName = 'mhf';
47
+ fund.abbreviation = 'mhf';
48
+ Fund.upsert(fund, 'test', function(err, result) {
49
+ should.not.exist(err);
50
+ should.exist(result);
51
+ fund = result;
52
+ done();
53
+ });
54
+ });
55
+
56
+ before(function(done) {
57
+
58
+ person1 = new Person();
59
+ person1.name.first = 'Mischa';
60
+ person1.name.last = 'Barton';
61
+ person1.slug = 'mischa-barton';
62
+
63
+ Person.upsert(person1, 'test', function (err, newPerson) {
64
+
65
+ should.not.exist(err);
66
+ should.exist(newPerson);
67
+
68
+ person1 = newPerson;
69
+
70
+ return done();
71
+
72
+ });
73
+
74
+ });
75
+
76
+ before(function(done) {
77
+
78
+ person2 = new Person();
79
+ person2.name.first = 'Carrie';
80
+ person2.name.last = 'Coon';
81
+ person2.slug = 'carrie-coon';
82
+
83
+ Person.upsert(person2, 'test', function (err, newPerson) {
84
+
85
+ should.not.exist(err);
86
+ should.exist(newPerson);
87
+
88
+ person2 = newPerson;
89
+
90
+ return done();
91
+
92
+ });
93
+
94
+ });
95
+
96
+ before(function(done) {
97
+
98
+ person = new Person();
99
+ person.name.first = 'George';
100
+ person.name.last = 'Costanza';
101
+ person.slug = 'george';
102
+ person.avatarUrl = 'tiger.jpg';
103
+
104
+ Person.upsert(person, 'test', function (err, newPerson) {
105
+
106
+ person = newPerson;
107
+
108
+ return done();
109
+
110
+ });
111
+
112
+ });
113
+
114
+ it('adds a limited partner', function(done) {
115
+
116
+ lp.name = 'United Testers';
117
+ lp.customer = organization;
118
+
119
+ lp.fundsInvested.push({
120
+ fund: fund,
121
+ committed: 1000000,
122
+ called: 400000
123
+ });
124
+
125
+ lp.contact.phone.push({
126
+ type: 'other',
127
+ number: '12079396565',
128
+ primary: true
129
+ });
130
+
131
+ lp.contact.email.push({
132
+ type: 'other',
133
+ email: 'dhyasama+test@gmail.com',
134
+ primary: true
135
+ });
136
+
137
+ lp.contact.address.push({
138
+ street: '121 Union St',
139
+ city: 'Brewer',
140
+ state: 'ME',
141
+ country: 'USA',
142
+ postalCode: '04412',
143
+ primary: true
144
+ });
145
+
146
+ LimitedPartner.upsert(lp, 'test', { CUSTOMER_ID: organization._id, role: 'admin' }, function(err, updatedLp) {
147
+ should.not.exist(err);
148
+ should.exist(updatedLp);
149
+ lp = updatedLp;
150
+ done();
151
+ });
152
+
153
+ });
154
+
155
+ it('searches for an lp', function(done) {
156
+
157
+ LimitedPartner.search('United', { CUSTOMER_ID: organization._id, role: 'admin' }, function(err, result) {
158
+
159
+ should.not.exist(err);
160
+ should.exist(result);
161
+
162
+ result.length.should.equal(1);
163
+ done();
164
+
165
+ });
166
+
167
+ });
168
+
169
+ it('searches for an lp without the rights', function(done) {
170
+
171
+ LimitedPartner.search('United', { CUSTOMER_ID: organization._id, role: 'none' }, function(err, result) {
172
+
173
+ should.not.exist(err);
174
+ should.exist(result);
175
+
176
+ result.length.should.equal(0);
177
+ done();
178
+
179
+ });
180
+
181
+ });
182
+
183
+ it('searches for an lp of different customer', function(done) {
184
+
185
+ LimitedPartner.search('United', { CUSTOMER_ID: new mongoose.Types.ObjectId(), role: 'admin' }, function(err, result) {
186
+
187
+ should.not.exist(err);
188
+ should.exist(result);
189
+
190
+ result.length.should.equal(0);
191
+ done();
192
+
193
+ });
194
+
195
+ });
196
+
197
+ it('updates a limited partner', function(done) {
198
+
199
+ LimitedPartner.getById(lp._id, { CUSTOMER_ID: organization._id, role: 'admin' }, function(err, result) {
200
+
201
+ should.not.exist(err);
202
+ should.exist(result);
203
+ lp.name = 'Changed Name';
204
+
205
+ LimitedPartner.upsert(result, 'test', { CUSTOMER_ID: organization._id, role: 'admin' }, function(err, updatedLp) {
206
+ should.not.exist(err);
207
+ should.exist(updatedLp);
208
+ lp.name.should.equal('Changed Name');
209
+ lp = updatedLp;
210
+ done();
211
+ });
212
+
213
+ });
214
+
215
+ });
216
+
217
+ it('adds a person to an lp', function(done) {
218
+
219
+ LimitedPartner.getById(lp.id, { CUSTOMER_ID: organization._id, role: 'admin' }, function(err, result) {
220
+
221
+ result.addPerson(person.id);
222
+
223
+ LimitedPartner.upsert(result, 'test', { CUSTOMER_ID: organization._id, role: 'admin' }, function(err, updatedLp) {
224
+ should.not.exist(err);
225
+ should.exist(updatedLp);
226
+ updatedLp.people.length.should.equal(1);
227
+ done();
228
+ });
229
+
230
+ });
231
+
232
+ });
233
+
234
+ it('tries to add a person to an lp again', function(done) {
235
+
236
+ // must be a better way to do this
237
+ // successful test means addPerson throws an error
238
+ // if the should in the try is hit then the test fails
239
+
240
+ try {
241
+ lp.addPerson(person.id);
242
+ should.exist(e);
243
+ }
244
+ catch(e) {
245
+ should.exist(e);
246
+ };
247
+
248
+ done();
249
+
250
+ });
251
+
252
+ it('finds limited partners by person id', function(done) {
253
+ LimitedPartner.getByPersonId(person._id, { CUSTOMER_ID: organization._id, role: 'lp-full' }, function(err, result) {
254
+ should.not.exist(err);
255
+ should.exist(result);
256
+ result.length.should.equal(1);
257
+ done();
258
+ });
259
+ });
260
+
261
+ it('finds a limited partner by id', function(done) {
262
+ LimitedPartner.getById(lp.id, { CUSTOMER_ID: organization._id, role: 'admin' }, function(err, result) {
263
+ should.not.exist(err);
264
+ should.exist(result);
265
+ result.id.should.equal(lp.id);
266
+ done();
267
+ });
268
+ });
269
+
270
+ it('adds a note', function(done) {
271
+
272
+ LimitedPartner.addNote(lp.id, person._id, 'Sweet note bro!', false, organization._id, function(err, result) {
273
+
274
+ should.not.exist(err);
275
+ should.exist(result);
276
+ should.exist(result.note);
277
+ should.exist(result.addedTo);
278
+ result.addedTo.notes.length.should.equal(1);
279
+
280
+ noteId = result.addedTo.notes[0];
281
+
282
+ return done();
283
+
284
+ });
285
+
286
+ });
287
+
288
+ it('gets an lp by id with a populated note', function(done) {
289
+
290
+ LimitedPartner.getById(lp.id, { CUSTOMER_ID: organization._id, role: 'admin' }, function(err, result) {
291
+
292
+ should.not.exist(err);
293
+ should.exist(result);
294
+
295
+ result.id.should.equal(lp.id);
296
+
297
+ should.exist(result.notes);
298
+ result.notes.length.should.equal(1);
299
+ should.exist(result.notes[0].createdBy);
300
+ should.exist(result.notes[0].createdBy.avatarUrl);
301
+ result.notes[0].createdBy.avatarUrl.length.should.be.above(0);
302
+ should.exist(result.notes[0].createdBy.name);
303
+ should.exist(result.notes[0].createdBy.name.first);
304
+ result.notes[0].createdBy.name.first.length.should.be.above(0);
305
+
306
+ done();
307
+
308
+ });
309
+
310
+ });
311
+
312
+ it('deletes a note', function(done) {
313
+
314
+ LimitedPartner.deleteNote(noteId, organization._id, function(err, result) {
315
+
316
+ should.not.exist(err);
317
+
318
+ return done();
319
+
320
+ });
321
+
322
+ });
323
+
324
+ it('finds the primary email for an lp', function(done) {
325
+
326
+ LimitedPartner.getById(lp.id, { CUSTOMER_ID: organization._id, role: 'admin' }, function(err, partner) {
327
+
328
+ should.not.exist(err);
329
+ should.exist(partner);
330
+
331
+ partner.email.primary.should.equal('dhyasama+test@gmail.com');
332
+
333
+ done();
334
+
335
+ });
336
+
337
+ });
338
+
339
+ it('finds the primary phone for an lp', function(done) {
340
+
341
+ LimitedPartner.getById(lp.id, { CUSTOMER_ID: organization._id, role: 'admin' }, function(err, lp) {
342
+
343
+ should.not.exist(err);
344
+ should.exist(lp);
345
+
346
+ lp.phone.primary.should.equal('12079396565');
347
+
348
+ done();
349
+
350
+ });
351
+
352
+ });
353
+
354
+ it('finds the primary address for an lp', function(done) {
355
+
356
+ LimitedPartner.getById(lp.id, { CUSTOMER_ID: organization._id, role: 'admin' }, function(err, lp) {
357
+
358
+ should.not.exist(err);
359
+ should.exist(lp);
360
+
361
+ lp.address.primary.postalCode.should.equal('04412');
362
+
363
+ done();
364
+
365
+ });
366
+
367
+ });
368
+
369
+ it('finds name for an lp if allowed', function(done) {
370
+
371
+ LimitedPartner.getById(lp.id, { CUSTOMER_ID: organization._id, role: 'lp-names' }, function(err, lp) {
372
+
373
+ should.not.exist(err);
374
+ should.exist(lp);
375
+ should.exist(lp.name);
376
+
377
+ done();
378
+
379
+ });
380
+
381
+ });
382
+
383
+ it('adds a flag', function(done) {
384
+
385
+ LimitedPartner.addFlag(lp.id, person._id, 'incorrect phone', organization._id, function(err, result) {
386
+
387
+ should.not.exist(err);
388
+ should.exist(result);
389
+ should.exist(result.flag);
390
+ should.exist(result.addedTo);
391
+ result.addedTo.flags.length.should.equal(1);
392
+
393
+ done();
394
+
395
+ });
396
+
397
+ });
398
+
399
+ });