@dhyasama/totem-models 1.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.
package/test/Person.js ADDED
@@ -0,0 +1,1042 @@
1
+ "use strict";
2
+
3
+ var
4
+
5
+ should = require("should"),
6
+ _ = require('underscore'),
7
+ config = require('./config')['test'],
8
+ mongoose = require('mongoose'),
9
+ clearDB = require('mocha-mongoose')(config.db.uri, {noClear: true}),
10
+ LimitedPartner = mongoose.model('LimitedPartner'),
11
+ Person = mongoose.model('Person'),
12
+ Organization = mongoose.model('Organization'),
13
+ Account = mongoose.model('Account'),
14
+ Note = mongoose.model('Note'),
15
+ person = new Person(),
16
+ mergeId = new mongoose.Types.ObjectId(),
17
+ noteId;
18
+
19
+ var CUSTOMER_ID = config.CUSTOMER_ID;
20
+
21
+ var person2, person3, person4, person5;
22
+
23
+ var eventNote;
24
+
25
+ var lp = new LimitedPartner();
26
+ lp.name = "Testy Tester";
27
+
28
+ var org = new Organization();
29
+ org.name = 'Testy Org 1';
30
+ org.slug = 'testy-org-1';
31
+
32
+ var org2 = new Organization();
33
+ org2.name = 'Testy Org 2';
34
+ org2.slug = 'testy-org-2';
35
+
36
+ var org3 = new Organization();
37
+ org3.name = 'Testy Org 3';
38
+ org3.slug = 'testy-org-3';
39
+
40
+ var org4 = new Organization();
41
+ org4.name = 'Testy Org 4';
42
+ org4.slug = 'testy-org-4';
43
+
44
+
45
+ describe('Person', function() {
46
+
47
+ before(function(done) {
48
+ if (mongoose.connection.db) return done();
49
+ mongoose.connect(config.db.uri, done);
50
+ });
51
+
52
+ before(function(done) {
53
+ clearDB(done);
54
+ });
55
+
56
+ before(function (done) {
57
+ LimitedPartner.collection.dropIndexes(function (err, result) {
58
+ should.not.exist(err);
59
+ should.exist(result);
60
+ result.should.equal(true);
61
+ return done();
62
+ });
63
+ });
64
+
65
+ before(function (done) {
66
+ Organization.collection.dropIndexes(function (err, result) {
67
+ should.not.exist(err);
68
+ should.exist(result);
69
+ result.should.equal(true);
70
+ return done();
71
+ });
72
+ });
73
+
74
+ before(function(done) {
75
+ Organization.upsert(org, 'test-user', function(err, result1) {
76
+ should.not.exist(err);
77
+ org = result1;
78
+ Organization.upsert(org2, 'test-user', function(err, result2) {
79
+ should.not.exist(err);
80
+ org2 = result2;
81
+ Organization.upsert(org3, 'test-user', function(err, result3) {
82
+ should.not.exist(err);
83
+ org3 = result3;
84
+ Organization.upsert(org4, 'test-user', function(err, result4) {
85
+ should.not.exist(err);
86
+ org4 = result4;
87
+ done();
88
+ });
89
+ });
90
+ });
91
+ });
92
+ });
93
+
94
+ before(function (done) {
95
+ Person.setCustomerCompanyIds([
96
+ org._id.toString(),
97
+ org3._id.toString(),
98
+ org4._id.toString()
99
+ ]);
100
+ done();
101
+ });
102
+
103
+ before(function (done) {
104
+
105
+ person2 = new Person();
106
+ person2.name = {};
107
+ person2.name.first = 'test';
108
+ person2.name.last = 'two';
109
+ person2.slug = 'person2-slug';
110
+ person2.website = 'person2.com';
111
+ person2.related = [];
112
+ person2.chairs = {};
113
+ person2.chairs.first = [];
114
+ person2.chairs.second = [];
115
+ person2.contact.phone.push({
116
+ type: 'work',
117
+ number: '2079396565',
118
+ primary: true
119
+ });
120
+ person2.related.push(person.id);
121
+ person2.aliases.push('Skillet');
122
+
123
+ person3 = new Person();
124
+ person3.name = {};
125
+ person3.name.first = 'slippery';
126
+ person3.name.last = 'three';
127
+ person3.slug = 'person3-slug';
128
+ person3.related.push(person2.id);
129
+ person3.aliases.push('Slippery Pete');
130
+
131
+ person3.contact.email.push({
132
+ type: 'work',
133
+ email: 'paul@ffvc.com',
134
+ primary: true
135
+ });
136
+ person3.avatarUrl = 'https://images.somecdn.com/myfunnypic.jpg';
137
+
138
+ person4 = new Person();
139
+ person4.name = {};
140
+ person4.name.first = 'Bob';
141
+ person4.name.last = 'Plant';
142
+ person4.slug = 'bob-plant';
143
+
144
+ person5 = new Person();
145
+ person5.name = {};
146
+ person5.name.first = 'Tim';
147
+ person5.name.last = 'Reynolds';
148
+ person5.slug = 'tim-reynolds';
149
+
150
+ Person.upsert(person2, 'test-user', function(err, person2) {
151
+ Person.upsert(person3, 'test-user', function(err, person3) {
152
+ Person.upsert(person4, 'test-user', function(err, person4) {
153
+ Person.upsert(person5, 'test-user', function(err, person5) {
154
+ done();
155
+ });
156
+ });
157
+ });
158
+ });
159
+
160
+ });
161
+
162
+ before(function(done) {
163
+
164
+ var eventSummary = {
165
+ calendarEventId: new mongoose.Types.ObjectId(),
166
+ providerEventId: 'some_other_random_data',
167
+ totemCustomerId: config.CUSTOMER_ID,
168
+ summary: 'The Russians are coming',
169
+ startTime: new Date(),
170
+ attendees: {
171
+ internal: [person],
172
+ external: [person2, person3]
173
+ }
174
+ };
175
+
176
+ person4.calendarEventSummaries.push(eventSummary);
177
+
178
+ Person.upsert(person4, 'test-user', function(err, result) {
179
+ should.not.exist(err);
180
+ should.exist(result);
181
+ person4 = result;
182
+ return done();
183
+ });
184
+
185
+ });
186
+
187
+ before(function(done) {
188
+
189
+ var providerEventId = 'some_other_random_data';
190
+ var creator = person._id;
191
+ var text = 'Sweet note bro!';
192
+
193
+ Note.createForCalendarEvent(providerEventId, creator, text, function(err, result) {
194
+
195
+ should.not.exist(err);
196
+ should.exist(result);
197
+
198
+ //result.notes.length.should.equal(1);
199
+ //result.id.toString().should.equal(person2.id.toString());
200
+
201
+ eventNote = result;
202
+
203
+ return done();
204
+
205
+ });
206
+
207
+ });
208
+
209
+ it('it soft deletes a person', function(done) {
210
+
211
+ person2.deletePerson();
212
+
213
+ Person.upsert(person2, 'test-user', function(err, result) {
214
+ should.not.exist(err);
215
+ should.exist(result);
216
+ person2 = result;
217
+ person2.deleted.should.equal(true);
218
+ done();
219
+ });
220
+ }); // end soft delete org
221
+
222
+ it('adds a person', function(done) {
223
+
224
+ person.name.first = 'Testy';
225
+ person.name.last = 'McTester';
226
+ person.slug = 'testy-mctester';
227
+ person.related.push(person3.id);
228
+ person.aliases.push('Tee Money');
229
+
230
+ person.contact.email.push({
231
+ type: 'work',
232
+ email: 'dhyasama+test@gmail.com',
233
+ primary: true
234
+ });
235
+
236
+ person.contact.phone.push({
237
+ type: 'work',
238
+ number: '2079396565',
239
+ primary: true
240
+ });
241
+
242
+ Person.upsert(person, 'test', function(err, updatedPerson) {
243
+ should.not.exist(err);
244
+ should.exist(updatedPerson);
245
+ person = updatedPerson;
246
+ done();
247
+ });
248
+
249
+ }); // end adds a person
250
+
251
+ it('it relates 2 people', function(done) {
252
+
253
+ person2.relatePerson(person.id);
254
+
255
+ Person.upsert(person2, 'test-user', function(err, result) {
256
+ should.not.exist(err);
257
+ should.exist(result);
258
+ person2 = result;
259
+ person2.related.length.should.equal(2);
260
+ done();
261
+ });
262
+ }); // end relate 2 people
263
+
264
+ it('adds a chair position', function(done) {
265
+
266
+ person2.addChairPos({num: 'chair1'}, org.id);
267
+
268
+ Person.upsert(person2, 'test-user', function(err, p) {
269
+ should.not.exist(err);
270
+ should.exist(p);
271
+ p.chairs.first.length.should.equal(1);
272
+ person2 = p;
273
+ done();
274
+ });
275
+ }); // end add chair position
276
+
277
+ it('removes a chair position', function(done) {
278
+
279
+ person2.removeChair({
280
+ num: 'chair1',
281
+ val: ''
282
+ }, org.id);
283
+
284
+ Person.upsert(person2, 'test-user', function(err, p) {
285
+ should.not.exist(err);
286
+ should.exist(p);
287
+ p.chairs.first.length.should.equal(0);
288
+ person2 = p;
289
+ done();
290
+ });
291
+ }); // end remove chair position
292
+
293
+ describe('search', function() {
294
+
295
+ it('searches by phone and email', function (done) {
296
+
297
+ Person.search({
298
+ emails: ['dhyasama+test@gmail.com'],
299
+ phones: ['12079396565']
300
+ }, {fuzzy: false, admin: true}, function (err, results) {
301
+ should.not.exist(err);
302
+ should.exist(results);
303
+ results.length.should.equal(1);
304
+ done();
305
+ });
306
+
307
+ });
308
+
309
+ it('fuzzy match by first name', function (done) {
310
+
311
+ Person.search({
312
+ name: {
313
+ first: 'Slipper',
314
+ last: ''
315
+ }
316
+ }, { orLastOnly: false, admin: true }, function (err, results) {
317
+ should.not.exist(err);
318
+ should.exist(results);
319
+ results.length.should.equal(1);
320
+ done();
321
+ });
322
+
323
+ });
324
+
325
+ it('fuzzy miss by first name', function (done) {
326
+
327
+ Person.search({
328
+ name: {
329
+ first: 'Testerz',
330
+ last: ''
331
+ }
332
+ }, { admin: true }, function (err, results) {
333
+ should.not.exist(err);
334
+ should.exist(results);
335
+ results.length.should.equal(0);
336
+ done();
337
+ });
338
+
339
+ });
340
+
341
+ it('exact match by full name', function (done) {
342
+
343
+ Person.search({
344
+ name: {
345
+ full: 'Testy McTester'
346
+ }
347
+ }, {fuzzy: false, andFirstLast: true, admin: true}, function (err, results) {
348
+ should.not.exist(err);
349
+ should.exist(results);
350
+ results.length.should.equal(1);
351
+ done();
352
+ });
353
+
354
+ });
355
+
356
+ it('exact miss by full name', function (done) {
357
+
358
+ Person.search({
359
+ name: {
360
+ full: 'Test McTest'
361
+ }
362
+ }, {fuzzy: false, admin: true}, function (err, results) {
363
+ should.not.exist(err);
364
+ should.exist(results);
365
+ results.length.should.equal(0);
366
+ done();
367
+ });
368
+
369
+ });
370
+
371
+ it('searches by phone, email, name', function (done) {
372
+
373
+ Person.search({
374
+ emails: ['dhyasama+test@gmail.com'],
375
+ phones: ['12079396565'],
376
+ name: {
377
+ first: 'Testy',
378
+ last: 'McTester'
379
+ }
380
+ }, {
381
+ fuzzy: false,
382
+ andFirstLast: true,
383
+ admin: true
384
+ }, function (err, results) {
385
+ should.not.exist(err);
386
+ should.exist(results);
387
+ results.length.should.equal(1);
388
+ done();
389
+ });
390
+
391
+ });
392
+
393
+ it('searches with no match', function (done) {
394
+
395
+ Person.search({
396
+ emails: ['dhyasama+doesnotexist@gmail.com']
397
+ }, {fuzzy: false, admin: true}, function (err, results) {
398
+ should.not.exist(err);
399
+ should.exist(results);
400
+ results.length.should.equal(0);
401
+ done();
402
+ });
403
+
404
+ });
405
+
406
+ it('searches by full name with a fuzzy alias match', function (done) {
407
+
408
+ Person.search({
409
+ name: {
410
+ full: 'Money'
411
+ }
412
+ }, {fuzzy: true, admin: true}, function (err, results) {
413
+ should.not.exist(err);
414
+ should.exist(results);
415
+ results.length.should.equal(1);
416
+ done();
417
+ });
418
+
419
+ });
420
+
421
+ it('searches by first name with a fuzzy alias match', function (done) {
422
+
423
+ Person.search({
424
+ name: {
425
+ first: 'Slippery'
426
+ }
427
+ }, {fuzzy: true, admin: true}, function (err, results) {
428
+ should.not.exist(err);
429
+ should.exist(results);
430
+ results.length.should.equal(1);
431
+ done();
432
+ });
433
+
434
+ });
435
+
436
+ it('searches by email as a raw query with a match', function (done) {
437
+
438
+ Person.search({
439
+ name: {
440
+ full: 'dhyasama+test@gmail.com'
441
+ },
442
+ rawQuery: 'dhyasama+test@gmail.com'
443
+ }, {fuzzy: false, admin: true}, function (err, results) {
444
+ should.not.exist(err);
445
+ should.exist(results);
446
+ results.length.should.equal(1);
447
+ done();
448
+ });
449
+
450
+ });
451
+
452
+ it('searches by email as a raw query without a match', function (done) {
453
+
454
+ Person.search({
455
+ name: {
456
+ full: 'dhyasama+notlikelybub@gmail.com'
457
+ },
458
+ rawQuery: 'dhyasama+notlikelybub@gmail.com'
459
+ }, {fuzzy: false, admin: true}, function (err, results) {
460
+ should.not.exist(err);
461
+ should.exist(results);
462
+ results.length.should.equal(0);
463
+ done();
464
+ });
465
+
466
+ });
467
+
468
+ it('searches by phone as a raw query with a match', function (done) {
469
+
470
+ Person.search({
471
+ name: {
472
+ full: '2079396565'
473
+ },
474
+ rawQuery: '2079396565'
475
+ }, {fuzzy: false, admin: true}, function (err, results) {
476
+ should.not.exist(err);
477
+ should.exist(results);
478
+ results.length.should.equal(1);
479
+ done();
480
+ });
481
+
482
+ });
483
+
484
+ it('searches by phone as a raw query without a match', function (done) {
485
+
486
+ Person.search({
487
+ name: {
488
+ full: '+12079894629'
489
+ },
490
+ rawQuery: '+12079894629'
491
+ }, {fuzzy: true, admin: true}, function (err, results) {
492
+ should.not.exist(err);
493
+ should.exist(results);
494
+ results.length.should.equal(0);
495
+ done();
496
+ });
497
+
498
+ });
499
+
500
+ it('searches by full name with a nickname match', function (done) {
501
+
502
+ Person.search({
503
+ name: {
504
+ full: 'Robert Plant'
505
+ },
506
+ rawQuery: ''
507
+ }, { fuzzy: false, andFirstLast: true, orLastOnly: false, admin: true }, function (err, results) {
508
+ should.not.exist(err);
509
+ should.exist(results);
510
+ results.length.should.equal(1);
511
+ done();
512
+ });
513
+
514
+ });
515
+
516
+ it('searches by first and last name with a nickname match', function (done) {
517
+
518
+ Person.search({
519
+ name: {
520
+ first: 'Robert',
521
+ last: 'Plant'
522
+ },
523
+ rawQuery: ''
524
+ }, { fuzzy: false, andFirstLast: true, orLastOnly: false, admin: true }, function (err, results) {
525
+ should.not.exist(err);
526
+ should.exist(results);
527
+ results.length.should.equal(1);
528
+ done();
529
+ });
530
+
531
+ });
532
+
533
+ });
534
+
535
+ it('finds dupes with separate first and last search', function(done) {
536
+
537
+ var options = {
538
+ fuzzy: false,
539
+ andFirstLast: false,
540
+ admin: true
541
+ };
542
+
543
+ Person.findDupes(person2, options, function(err, dupes) {
544
+ should.not.exist(err);
545
+ should.exist(dupes);
546
+ dupes.length.should.equal(1);
547
+ done();
548
+ });
549
+
550
+ });
551
+
552
+ it('flags a person', function(done) {
553
+
554
+ Person.flag(person.id, false, 'test flag', 'tester', function(err, updatedPerson) {
555
+ should.not.exist(err);
556
+ should.exist(updatedPerson);
557
+ should.exist(updatedPerson.flagged);
558
+ updatedPerson.flagged.resolved.should.equal(false);
559
+ done();
560
+ });
561
+
562
+ });
563
+
564
+ it('does not flag a non-existent person', function(done) {
565
+
566
+ Person.flag(new mongoose.Types.ObjectId(), false, 'test flag', 'tester', function(err, updatedPerson) {
567
+ should.exist(err);
568
+ should.not.exist(updatedPerson);
569
+ done();
570
+ });
571
+
572
+ });
573
+
574
+ it('adds an account to a person', function(done) {
575
+
576
+ var account = new Account();
577
+
578
+ account.username = 'testy';
579
+ account.email = 'test@ffvc.com';
580
+ account.reset.token = '123456789';
581
+ account.setup.token = '987654321';
582
+ account.password = 'piratebooty';
583
+ account.person = person;
584
+
585
+ Account.upsert(account, function(err, updatedAccount) {
586
+
587
+ should.not.exist(err);
588
+ should.exist(updatedAccount);
589
+
590
+ person.account = account;
591
+
592
+ Person.upsert(person, 'test', function(err, updatedPerson) {
593
+ should.not.exist(err);
594
+ should.exist(updatedPerson);
595
+ person = updatedPerson;
596
+ done();
597
+ });
598
+
599
+ });
600
+
601
+ });
602
+
603
+ it('lists the people in a fund', function(done) {
604
+ // todo - not sure how to test this since it's tight with LimitedPartner
605
+ done();
606
+ });
607
+
608
+ it('lists the funds for a person', function(done) {
609
+ // todo - not sure how to test this since it's tight with LimitedPartner
610
+ done();
611
+ });
612
+
613
+ it('updates a person', function(done) {
614
+
615
+ person.title = 'Director of Testing';
616
+
617
+ Person.upsert(person, 'test', function(err, updatedPerson) {
618
+ should.not.exist(err);
619
+ should.exist(updatedPerson);
620
+ updatedPerson.id.should.equal(person.id);
621
+ person = updatedPerson;
622
+ done();
623
+ });
624
+
625
+ });
626
+
627
+ it('lists all people', function(done) {
628
+
629
+ Person.listAllPeople(function(err, people) {
630
+ should.not.exist(err);
631
+ should.exist(people);
632
+ //because of the soft delete test
633
+ people.length.should.equal(4);
634
+ done();
635
+ });
636
+
637
+ });
638
+
639
+ it('finds person by slug', function(done) {
640
+
641
+ Person.findBySlug('person3-slug', function(err, p) {
642
+ should.not.exist(err);
643
+ should.exist(p);
644
+ p.length.should.equal(1);
645
+ done();
646
+ });
647
+
648
+ });
649
+
650
+ it('finds people by slugs', function(done) {
651
+
652
+ Person.findBySlugs(['tim-reynolds', 'person3-slug'], function(err, people) {
653
+ should.not.exist(err);
654
+ should.exist(people);
655
+ people.length.should.equal(2);
656
+ done();
657
+ });
658
+
659
+ });
660
+
661
+ it('finds people by slugs without a match', function(done) {
662
+
663
+ Person.findBySlugs(['sweet-jesus-42', 'easy-as-abc-123'], function(err, people) {
664
+ should.not.exist(err);
665
+ should.exist(people);
666
+ people.length.should.equal(0);
667
+ done();
668
+ });
669
+
670
+ });
671
+
672
+ it('finds a user by email', function(done) {
673
+
674
+ Person.findByUniqueInfo('dhyasama+test@gmail.com', function(err, person) {
675
+ should.not.exist(err);
676
+ should.exist(person);
677
+ done();
678
+ });
679
+
680
+ });
681
+
682
+ it("doesn't find a user if email doesn't exist", function(done) {
683
+
684
+ Person.findByUniqueInfo('mcfly@delorean.com', function(err, person) {
685
+ should.not.exist(err);
686
+ should.not.exist(person);
687
+ done();
688
+ });
689
+
690
+ });
691
+
692
+ it('finds a person by id', function(done) {
693
+
694
+ Person.getById(person.id, function(err, person) {
695
+ should.not.exist(err);
696
+ should.exist(person);
697
+ done();
698
+ });
699
+
700
+ });
701
+
702
+ it('finds a person by id and customer', function(done) {
703
+
704
+ Person.getByIdCustomer(person.id, config.CUSTOMER_ID, function(err, person) {
705
+ should.not.exist(err);
706
+ should.exist(person);
707
+ done();
708
+ });
709
+
710
+ });
711
+
712
+ it('finds a person by id and customer with a populated event note', function(done) {
713
+
714
+ Person.getByIdCustomer(person4.id, config.CUSTOMER_ID, function(err, person) {
715
+ should.not.exist(err);
716
+ should.exist(person);
717
+ should.exist(person.calendarEventSummaries);
718
+ person.calendarEventSummaries.length.should.equal(1);
719
+ should.exist(person.calendarEventSummaries[0].notes);
720
+ person.calendarEventSummaries[0].notes.length.should.equal(1);
721
+ should.exist(person.calendarEventSummaries[0].notes[0].createdBy);
722
+
723
+ return done();
724
+
725
+ });
726
+
727
+ });
728
+
729
+ it('finds a person by id and populates', function(done) {
730
+
731
+ Person.getById(person5.id, function(err, person) {
732
+ should.not.exist(err);
733
+ should.exist(person);
734
+ done();
735
+ });
736
+
737
+ });
738
+
739
+ it('finds the primary email for a person', function(done) {
740
+
741
+ Person.getById(person.id, function(err, person) {
742
+
743
+ should.not.exist(err);
744
+ should.exist(person);
745
+
746
+ person.email.primary.should.equal('dhyasama+test@gmail.com');
747
+
748
+ done();
749
+
750
+ });
751
+
752
+ });
753
+
754
+ it('finds the primary phone for a person', function(done) {
755
+
756
+ Person.getById(person.id, function(err, person) {
757
+
758
+ should.not.exist(err);
759
+ should.exist(person);
760
+
761
+ person.phone.primary.should.equal('2079396565');
762
+
763
+ done();
764
+
765
+ });
766
+
767
+ });
768
+
769
+ it('merges a person', function(done) {
770
+
771
+ var merged = person.addMerged(mergeId);
772
+ merged.should.equal(true);
773
+ done();
774
+
775
+ });
776
+
777
+ it('does not merge a person that has already been merged', function(done) {
778
+
779
+ var merged = person.addMerged(mergeId);
780
+ merged.should.equal(false);
781
+ done();
782
+
783
+ });
784
+
785
+ it('it flags a person', function(done) {
786
+
787
+ Person.flag(person2.id, false, 'flagging person2', 'test-user', function(err, p) {
788
+ should.not.exist(err);
789
+ should.exist(p);
790
+ p.flagged.text.should.equal('flagging person2');
791
+ person2 = p;
792
+ done();
793
+ });
794
+ });
795
+
796
+ it('does not find dupes with conjoined first and last search', function(done) {
797
+
798
+ var options = {
799
+ fuzzy: true,
800
+ andFirstLast: true
801
+ };
802
+
803
+ person2.contact.phone = [];
804
+
805
+ Person.findDupes(person2, options, function(err, dupes) {
806
+ should.not.exist(err);
807
+ should.exist(dupes);
808
+ dupes.length.should.equal(0);
809
+ done();
810
+ });
811
+
812
+ });
813
+
814
+ it('finds dupes while ignoring short last name', function(done) {
815
+
816
+ var options = {
817
+ fuzzy: true,
818
+ andFirstLast: true
819
+ };
820
+
821
+ person2.name.last = 'M';
822
+
823
+ Person.findDupes(person2, options, function(err, dupes) {
824
+ should.not.exist(err);
825
+ should.exist(dupes);
826
+ dupes.length.should.equal(0);
827
+ done();
828
+ });
829
+
830
+ });
831
+
832
+ it('adds a note to a person', function(done) {
833
+
834
+ Person.addNote(person2.id, person3.id, 'Sweet note bro!', function(err, result) {
835
+
836
+ should.not.exist(err);
837
+ should.exist(result);
838
+ should.exist(result.note);
839
+ should.exist(result.addedTo);
840
+ result.addedTo.notes.length.should.equal(1);
841
+ result.addedTo.id.toString().should.equal(person2.id.toString());
842
+
843
+ noteId = result.addedTo.notes[0];
844
+
845
+ return done();
846
+
847
+ });
848
+
849
+ });
850
+
851
+ it('finds a person by id and customer with a populated note', function(done) {
852
+
853
+ Person.getByIdCustomer(person2.id, config.CUSTOMER_ID, function(err, person) {
854
+
855
+ should.not.exist(err);
856
+ should.exist(person);
857
+ should.exist(person.notes);
858
+ person.notes.length.should.equal(1);
859
+ should.exist(person.notes[0].createdBy);
860
+ should.exist(person.notes[0].createdBy.avatarUrl);
861
+ person.notes[0].createdBy.avatarUrl.length.should.be.above(0);
862
+ should.exist(person.notes[0].createdBy.name);
863
+ should.exist(person.notes[0].createdBy.name.first);
864
+ person.notes[0].createdBy.name.first.length.should.be.above(0);
865
+
866
+ return done();
867
+
868
+ });
869
+
870
+ });
871
+
872
+ it('deletes a simple note', function(done) {
873
+
874
+ Person.deleteNote(noteId, function(err, result) {
875
+
876
+ should.not.exist(err);
877
+
878
+ return done();
879
+
880
+ });
881
+
882
+ });
883
+
884
+ it('deletes an event note', function(done) {
885
+
886
+ Person.deleteNote(eventNote.id, function(err, result) {
887
+
888
+ should.not.exist(err);
889
+
890
+ return done();
891
+
892
+ });
893
+
894
+ });
895
+
896
+ // describe('sources', function() {
897
+ //
898
+ // // can only add source if global process
899
+ // // at this time the only process will be calendar pull
900
+ // // so run tests that add as global process
901
+ // // then switch between customer ids to make sure proper data is returned
902
+ //
903
+ // it('it cannot add a source if not global process', function(done) {
904
+ //
905
+ // Person.addSource(person3.id, person2._id, config.CUSTOMER_ID, 'calendar', function(err, result) {
906
+ //
907
+ // should.exist(err);
908
+ // should.not.exist(result);
909
+ //
910
+ // return done();
911
+ //
912
+ // });
913
+ //
914
+ // });
915
+ //
916
+ // it('it adds a source', function(done) {
917
+ //
918
+ // config.CUSTOMER_ID = 'GLOBAL_PROCESS';
919
+ //
920
+ // Person.addSource(person3.id, person2._id, CUSTOMER_ID, 'calendar', function(err, result) {
921
+ //
922
+ // should.not.exist(err);
923
+ // should.exist(result);
924
+ //
925
+ // result.sources.length.should.equal(1);
926
+ // result.sources[0].interactions.calendar.should.equal(1);
927
+ // result.sources[0].interactions.email.should.equal(0);
928
+ //
929
+ // return done();
930
+ //
931
+ // });
932
+ //
933
+ // });
934
+ //
935
+ // it('it adds the same source but for a different customer', function(done) {
936
+ //
937
+ // config.CUSTOMER_ID = 'GLOBAL_PROCESS';
938
+ //
939
+ // Person.addSource(person3.id, person2._id, investor._id, 'calendar', function(err, result) {
940
+ //
941
+ // should.not.exist(err);
942
+ // should.exist(result);
943
+ //
944
+ // result.sources.length.should.equal(2);
945
+ // result.sources[0].interactions.calendar.should.equal(1);
946
+ // result.sources[0].interactions.email.should.equal(0);
947
+ // result.sources[1].interactions.calendar.should.equal(1);
948
+ // result.sources[1].interactions.email.should.equal(0);
949
+ //
950
+ // return done();
951
+ //
952
+ // });
953
+ //
954
+ // });
955
+ //
956
+ // it('it adds a source again', function(done) {
957
+ //
958
+ // config.CUSTOMER_ID = 'GLOBAL_PROCESS';
959
+ //
960
+ // Person.addSource(person3.id, person2._id, CUSTOMER_ID, 'calendar', function(err, result) {
961
+ //
962
+ // should.not.exist(err);
963
+ // should.exist(result);
964
+ //
965
+ // result.sources.length.should.equal(2);
966
+ // result.sources[0].interactions.calendar.should.equal(2);
967
+ // result.sources[0].interactions.email.should.equal(0);
968
+ // result.sources[1].interactions.calendar.should.equal(1);
969
+ // result.sources[1].interactions.email.should.equal(0);
970
+ //
971
+ // return done();
972
+ //
973
+ // });
974
+ //
975
+ // });
976
+ //
977
+ // it('it adds a different source', function(done) {
978
+ //
979
+ // config.CUSTOMER_ID = 'GLOBAL_PROCESS';
980
+ //
981
+ // Person.addSource(person3.id, person._id, CUSTOMER_ID, 'calendar', function(err, result) {
982
+ //
983
+ // should.not.exist(err);
984
+ // should.exist(result);
985
+ //
986
+ // result.sources.length.should.equal(3);
987
+ // result.sources[0].interactions.calendar.should.equal(2);
988
+ // result.sources[0].interactions.email.should.equal(0);
989
+ // result.sources[1].interactions.calendar.should.equal(1);
990
+ // result.sources[1].interactions.email.should.equal(0);
991
+ // result.sources[2].interactions.calendar.should.equal(1);
992
+ // result.sources[2].interactions.email.should.equal(0);
993
+ //
994
+ // return done();
995
+ //
996
+ // });
997
+ //
998
+ // });
999
+ //
1000
+ // it('does not show sources belonging to a different customer', function(done) {
1001
+ //
1002
+ // config.CUSTOMER_ID = investor._id;
1003
+ //
1004
+ // Person.getById(person3.id, function(err, result) {
1005
+ //
1006
+ // should.not.exist(err);
1007
+ // should.exist(result);
1008
+ //
1009
+ // result.sources.length.should.equal(1);
1010
+ // result.sources[0].customer.toString().should.equal(investor._id.toString());
1011
+ // result.interactions.count.should.equal(1);
1012
+ // console.log(result.sources);
1013
+ //
1014
+ // return done();
1015
+ //
1016
+ // });
1017
+ //
1018
+ // });
1019
+ //
1020
+ // it('shows sources belonging to this customer', function(done) {
1021
+ //
1022
+ // config.CUSTOMER_ID = CUSTOMER_ID;
1023
+ //
1024
+ // Person.getById(person3.id, function(err, result) {
1025
+ //
1026
+ // should.not.exist(err);
1027
+ // should.exist(result);
1028
+ //
1029
+ // result.sources.length.should.equal(2);
1030
+ // result.sources[0].customer.toString().should.equal(CUSTOMER_ID.toString());
1031
+ // result.sources[1].customer.toString().should.equal(CUSTOMER_ID.toString());
1032
+ // result.interactions.count.should.equal(3);
1033
+ //
1034
+ // return done();
1035
+ //
1036
+ // });
1037
+ //
1038
+ // });
1039
+ //
1040
+ // });
1041
+
1042
+ });