@dhyasama/totem-models 4.5.1 → 4.5.3
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/Organization.js +2 -7
- package/package.json +2 -2
- package/test/Organization.js +548 -538
package/test/Organization.js
CHANGED
|
@@ -23,18 +23,18 @@ var someOtherLp;
|
|
|
23
23
|
var account;
|
|
24
24
|
var customer1, customer2;
|
|
25
25
|
|
|
26
|
-
describe
|
|
26
|
+
describe('Organization', function() {
|
|
27
27
|
|
|
28
28
|
var org1, org2, org3, org4, org5;
|
|
29
29
|
var mergeId = new mongoose.Types.ObjectId();
|
|
30
30
|
|
|
31
31
|
before(function (done) {
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
if (mongoose.connection.db) return done();
|
|
33
|
+
mongoose.connect(config.db.uri, done);
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
before(function (done) {
|
|
37
|
-
|
|
37
|
+
clearDB(done);
|
|
38
38
|
});
|
|
39
39
|
|
|
40
40
|
before(function (done) {
|
|
@@ -70,7 +70,7 @@ describe.only('Organization', function() {
|
|
|
70
70
|
org2.name = 'No Thanks 2';
|
|
71
71
|
org2.slug = 'org2-slug';
|
|
72
72
|
org2.website = 'nothanks2.org';
|
|
73
|
-
org2.websiteAliases = [
|
|
73
|
+
org2.websiteAliases = ['myolddomain.tld'];
|
|
74
74
|
org2.related = [];
|
|
75
75
|
org2.aliases.push('NT2');
|
|
76
76
|
org2.crunchbase.uuid = 'abc';
|
|
@@ -101,10 +101,10 @@ describe.only('Organization', function() {
|
|
|
101
101
|
org5.crunchbase.uuid = 'jkl';
|
|
102
102
|
org5.crunchbase.url = 'jkl';
|
|
103
103
|
|
|
104
|
-
Organization.upsert(org2, 'test-user', function(err, no2) {
|
|
105
|
-
Organization.upsert(org3, 'test-user', function(err, no3) {
|
|
106
|
-
Organization.upsert(org4, 'test-user', function(err, no4) {
|
|
107
|
-
Organization.upsert(org5, 'test-user', function(err, no5) {
|
|
104
|
+
Organization.upsert(org2, 'test-user', function (err, no2) {
|
|
105
|
+
Organization.upsert(org3, 'test-user', function (err, no3) {
|
|
106
|
+
Organization.upsert(org4, 'test-user', function (err, no4) {
|
|
107
|
+
Organization.upsert(org5, 'test-user', function (err, no5) {
|
|
108
108
|
done();
|
|
109
109
|
});
|
|
110
110
|
});
|
|
@@ -113,7 +113,7 @@ describe.only('Organization', function() {
|
|
|
113
113
|
|
|
114
114
|
});
|
|
115
115
|
|
|
116
|
-
before(function(done) {
|
|
116
|
+
before(function (done) {
|
|
117
117
|
|
|
118
118
|
person1 = new Person();
|
|
119
119
|
person1.name.first = 'Mischa';
|
|
@@ -131,9 +131,9 @@ describe.only('Organization', function() {
|
|
|
131
131
|
|
|
132
132
|
});
|
|
133
133
|
|
|
134
|
-
|
|
134
|
+
});
|
|
135
135
|
|
|
136
|
-
before(function(done) {
|
|
136
|
+
before(function (done) {
|
|
137
137
|
|
|
138
138
|
customer1 = new Organization();
|
|
139
139
|
customer1.name = 'New Customer';
|
|
@@ -165,7 +165,7 @@ describe.only('Organization', function() {
|
|
|
165
165
|
]
|
|
166
166
|
};
|
|
167
167
|
|
|
168
|
-
Organization.upsert(customer1, 'test-user', function(err, result) {
|
|
168
|
+
Organization.upsert(customer1, 'test-user', function (err, result) {
|
|
169
169
|
|
|
170
170
|
should.not.exist(err);
|
|
171
171
|
should.exist(result);
|
|
@@ -178,7 +178,7 @@ describe.only('Organization', function() {
|
|
|
178
178
|
|
|
179
179
|
});
|
|
180
180
|
|
|
181
|
-
before(function(done) {
|
|
181
|
+
before(function (done) {
|
|
182
182
|
|
|
183
183
|
customer2 = new Organization();
|
|
184
184
|
customer2.name = 'Newer Customer';
|
|
@@ -210,7 +210,7 @@ describe.only('Organization', function() {
|
|
|
210
210
|
]
|
|
211
211
|
};
|
|
212
212
|
|
|
213
|
-
Organization.upsert(customer2, 'test-user', function(err, result) {
|
|
213
|
+
Organization.upsert(customer2, 'test-user', function (err, result) {
|
|
214
214
|
|
|
215
215
|
should.not.exist(err);
|
|
216
216
|
should.exist(result);
|
|
@@ -223,7 +223,7 @@ describe.only('Organization', function() {
|
|
|
223
223
|
|
|
224
224
|
});
|
|
225
225
|
|
|
226
|
-
before(function(done) {
|
|
226
|
+
before(function (done) {
|
|
227
227
|
|
|
228
228
|
person2 = new Person();
|
|
229
229
|
person2.name.first = 'Carrie';
|
|
@@ -243,7 +243,7 @@ describe.only('Organization', function() {
|
|
|
243
243
|
|
|
244
244
|
});
|
|
245
245
|
|
|
246
|
-
before(function(done) {
|
|
246
|
+
before(function (done) {
|
|
247
247
|
|
|
248
248
|
person = new Person();
|
|
249
249
|
person.name.first = 'Stan';
|
|
@@ -251,12 +251,12 @@ describe.only('Organization', function() {
|
|
|
251
251
|
person.slug = 'stan-beeman';
|
|
252
252
|
person.avatarUrl = 'https://hello.com';
|
|
253
253
|
|
|
254
|
-
Person.upsert(person, 'test', function(err, newPerson) {
|
|
254
|
+
Person.upsert(person, 'test', function (err, newPerson) {
|
|
255
255
|
|
|
256
256
|
should.not.exist(err);
|
|
257
257
|
should.exist(newPerson);
|
|
258
258
|
|
|
259
|
-
Person.upsert(newPerson, 'test', function(err, newNewPerson) {
|
|
259
|
+
Person.upsert(newPerson, 'test', function (err, newNewPerson) {
|
|
260
260
|
|
|
261
261
|
should.not.exist(err);
|
|
262
262
|
should.exist(newNewPerson);
|
|
@@ -272,7 +272,7 @@ describe.only('Organization', function() {
|
|
|
272
272
|
|
|
273
273
|
});
|
|
274
274
|
|
|
275
|
-
before(function(done) {
|
|
275
|
+
before(function (done) {
|
|
276
276
|
|
|
277
277
|
var f = new Fund();
|
|
278
278
|
f.name = 'FUND XYZ';
|
|
@@ -280,7 +280,7 @@ describe.only('Organization', function() {
|
|
|
280
280
|
f.slug = 'fund-xyz';
|
|
281
281
|
f.abbreviation = 'FXYZ';
|
|
282
282
|
|
|
283
|
-
Fund.upsert(f, 'test', function(err, fundResult) {
|
|
283
|
+
Fund.upsert(f, 'test', function (err, fundResult) {
|
|
284
284
|
|
|
285
285
|
should.not.exist(err);
|
|
286
286
|
should.exist(fundResult);
|
|
@@ -293,13 +293,13 @@ describe.only('Organization', function() {
|
|
|
293
293
|
|
|
294
294
|
});
|
|
295
295
|
|
|
296
|
-
before(function(done) {
|
|
296
|
+
before(function (done) {
|
|
297
297
|
|
|
298
298
|
var lp = new LimitedPartner();
|
|
299
299
|
lp.name = 'SOME OTHER LP';
|
|
300
|
-
lp.fundsInvested.push({fund:someOtherFund});
|
|
300
|
+
lp.fundsInvested.push({fund: someOtherFund});
|
|
301
301
|
|
|
302
|
-
LimitedPartner.upsert(lp, 'test', 'lp-full', function(err, lpResult) {
|
|
302
|
+
LimitedPartner.upsert(lp, 'test', 'lp-full', function (err, lpResult) {
|
|
303
303
|
|
|
304
304
|
should.not.exist(err);
|
|
305
305
|
should.exist(lpResult);
|
|
@@ -312,7 +312,7 @@ describe.only('Organization', function() {
|
|
|
312
312
|
|
|
313
313
|
});
|
|
314
314
|
|
|
315
|
-
before(function(done) {
|
|
315
|
+
before(function (done) {
|
|
316
316
|
|
|
317
317
|
org3.people.push({
|
|
318
318
|
person: person2.id,
|
|
@@ -326,7 +326,7 @@ describe.only('Organization', function() {
|
|
|
326
326
|
board: 'chairman'
|
|
327
327
|
});
|
|
328
328
|
|
|
329
|
-
Organization.upsert(org3, 'test-user', function(err, result) {
|
|
329
|
+
Organization.upsert(org3, 'test-user', function (err, result) {
|
|
330
330
|
should.not.exist(err);
|
|
331
331
|
should.exist(result);
|
|
332
332
|
result.people.length.should.equal(2);
|
|
@@ -336,14 +336,14 @@ describe.only('Organization', function() {
|
|
|
336
336
|
|
|
337
337
|
});
|
|
338
338
|
|
|
339
|
-
before(function(done) {
|
|
339
|
+
before(function (done) {
|
|
340
340
|
|
|
341
341
|
org2.chairs.push({
|
|
342
342
|
first: person2.id,
|
|
343
343
|
customer: org1
|
|
344
344
|
});
|
|
345
345
|
|
|
346
|
-
Organization.upsert(org2, 'test-user', function(err, result) {
|
|
346
|
+
Organization.upsert(org2, 'test-user', function (err, result) {
|
|
347
347
|
should.not.exist(err);
|
|
348
348
|
should.exist(result);
|
|
349
349
|
result.chairs.length.should.equal(1);
|
|
@@ -353,7 +353,7 @@ describe.only('Organization', function() {
|
|
|
353
353
|
|
|
354
354
|
});
|
|
355
355
|
|
|
356
|
-
before(function(done) {
|
|
356
|
+
before(function (done) {
|
|
357
357
|
|
|
358
358
|
account = new Account();
|
|
359
359
|
account.username = 'test-user';
|
|
@@ -373,586 +373,588 @@ describe.only('Organization', function() {
|
|
|
373
373
|
|
|
374
374
|
});
|
|
375
375
|
|
|
376
|
-
|
|
376
|
+
describe('General', function () {
|
|
377
377
|
|
|
378
|
-
|
|
378
|
+
it('it soft deletes an org', function (done) {
|
|
379
379
|
|
|
380
|
-
|
|
381
|
-
should.not.exist(err);
|
|
382
|
-
should.exist(result);
|
|
383
|
-
org4 = result;
|
|
384
|
-
org4.deleted.should.equal(true);
|
|
385
|
-
done();
|
|
386
|
-
});
|
|
387
|
-
}); // end soft delete org
|
|
380
|
+
org4.deleteOrg();
|
|
388
381
|
|
|
389
|
-
|
|
382
|
+
Organization.upsert(org4, 'test-user', function (err, result) {
|
|
383
|
+
should.not.exist(err);
|
|
384
|
+
should.exist(result);
|
|
385
|
+
org4 = result;
|
|
386
|
+
org4.deleted.should.equal(true);
|
|
387
|
+
done();
|
|
388
|
+
});
|
|
389
|
+
}); // end soft delete org
|
|
390
390
|
|
|
391
|
-
|
|
391
|
+
it('it relates an org and an org', function (done) {
|
|
392
392
|
|
|
393
|
-
|
|
394
|
-
should.not.exist(err);
|
|
395
|
-
should.exist(result);
|
|
396
|
-
org3 = result;
|
|
397
|
-
org3.related.length.should.equal(1);
|
|
398
|
-
done();
|
|
399
|
-
});
|
|
400
|
-
}); // end relate 2 orgs
|
|
393
|
+
org3.relateOrg(org2.id);
|
|
401
394
|
|
|
402
|
-
|
|
395
|
+
Organization.upsert(org3, 'test-user', function (err, result) {
|
|
396
|
+
should.not.exist(err);
|
|
397
|
+
should.exist(result);
|
|
398
|
+
org3 = result;
|
|
399
|
+
org3.related.length.should.equal(1);
|
|
400
|
+
done();
|
|
401
|
+
});
|
|
402
|
+
}); // end relate 2 orgs
|
|
403
|
+
|
|
404
|
+
it('adds an org', function (done) {
|
|
405
|
+
|
|
406
|
+
org1 = new Organization();
|
|
407
|
+
org1.name = 'Testing Org 1';
|
|
408
|
+
org1.slug = 'testing-org-1';
|
|
409
|
+
org1.website = 'testingorg1.org';
|
|
410
|
+
org1.contact.email = [];
|
|
411
|
+
org1.contact.email.push({
|
|
412
|
+
email: 'work@org1.com',
|
|
413
|
+
type: 'work',
|
|
414
|
+
primary: true
|
|
415
|
+
});
|
|
416
|
+
org1.crunchbase.uuid = 'mno';
|
|
417
|
+
org1.crunchbase.url = 'mno';
|
|
403
418
|
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
primary: true
|
|
413
|
-
});
|
|
414
|
-
org1.crunchbase.uuid = 'mno';
|
|
415
|
-
org1.crunchbase.url = 'mno';
|
|
419
|
+
Organization.upsert(org1, 'test-user', function (err, org) {
|
|
420
|
+
should.not.exist(err);
|
|
421
|
+
should.exist(org);
|
|
422
|
+
org.name.should.equal('Testing Org 1');
|
|
423
|
+
org1 = org;
|
|
424
|
+
done();
|
|
425
|
+
});
|
|
426
|
+
}); // end adds an org
|
|
416
427
|
|
|
417
|
-
|
|
418
|
-
should.not.exist(err);
|
|
419
|
-
should.exist(org);
|
|
420
|
-
org.name.should.equal('Testing Org 1');
|
|
421
|
-
org1 = org;
|
|
422
|
-
done();
|
|
423
|
-
});
|
|
424
|
-
}); // end adds an org
|
|
428
|
+
it('finds a fuzzy match by name', function (done) {
|
|
425
429
|
|
|
426
|
-
|
|
430
|
+
Organization.search({
|
|
431
|
+
name: 'org 1'
|
|
432
|
+
}, {admin: true, pcs: []}, function (err, results) {
|
|
433
|
+
should.not.exist(err);
|
|
434
|
+
should.exist(results);
|
|
435
|
+
results.length.should.equal(1);
|
|
436
|
+
done();
|
|
437
|
+
});
|
|
427
438
|
|
|
428
|
-
Organization.search({
|
|
429
|
-
name: 'org 1'
|
|
430
|
-
}, { admin: true, pcs: [] }, function(err, results) {
|
|
431
|
-
should.not.exist(err);
|
|
432
|
-
should.exist(results);
|
|
433
|
-
results.length.should.equal(1);
|
|
434
|
-
done();
|
|
435
439
|
});
|
|
436
440
|
|
|
437
|
-
|
|
441
|
+
it('finds a fuzzy match by first word of name', function (done) {
|
|
438
442
|
|
|
439
|
-
|
|
443
|
+
Organization.search({
|
|
444
|
+
name: 'org 99'
|
|
445
|
+
}, {queryFirstWord: true, admin: true, pcs: []}, function (err, results) {
|
|
446
|
+
should.not.exist(err);
|
|
447
|
+
should.exist(results);
|
|
448
|
+
results.length.should.equal(1);
|
|
449
|
+
done();
|
|
450
|
+
});
|
|
440
451
|
|
|
441
|
-
Organization.search({
|
|
442
|
-
name: 'org 99'
|
|
443
|
-
}, { queryFirstWord: true, admin: true, pcs: [] }, function(err, results) {
|
|
444
|
-
should.not.exist(err);
|
|
445
|
-
should.exist(results);
|
|
446
|
-
results.length.should.equal(1);
|
|
447
|
-
done();
|
|
448
452
|
});
|
|
449
453
|
|
|
450
|
-
|
|
454
|
+
it('does not find a fuzzy match by name', function (done) {
|
|
451
455
|
|
|
452
|
-
|
|
456
|
+
Organization.search({
|
|
457
|
+
name: 'quick brown fox'
|
|
458
|
+
}, {admin: true, pcs: []}, function (err, results) {
|
|
459
|
+
should.not.exist(err);
|
|
460
|
+
should.exist(results);
|
|
461
|
+
results.length.should.equal(0);
|
|
462
|
+
done();
|
|
463
|
+
});
|
|
453
464
|
|
|
454
|
-
Organization.search({
|
|
455
|
-
name: 'quick brown fox'
|
|
456
|
-
}, { admin: true, pcs: [] }, function(err, results) {
|
|
457
|
-
should.not.exist(err);
|
|
458
|
-
should.exist(results);
|
|
459
|
-
results.length.should.equal(0);
|
|
460
|
-
done();
|
|
461
465
|
});
|
|
462
466
|
|
|
463
|
-
|
|
467
|
+
it('does not find an exact match by name', function (done) {
|
|
464
468
|
|
|
465
|
-
|
|
469
|
+
Organization.search({
|
|
470
|
+
name: 'org 1'
|
|
471
|
+
}, {fuzzy: false, admin: true, pcs: []}, function (err, results) {
|
|
472
|
+
should.not.exist(err);
|
|
473
|
+
should.exist(results);
|
|
474
|
+
results.length.should.equal(0);
|
|
475
|
+
done();
|
|
476
|
+
});
|
|
466
477
|
|
|
467
|
-
Organization.search({
|
|
468
|
-
name: 'org 1'
|
|
469
|
-
}, { fuzzy: false, admin: true, pcs: [] }, function(err, results) {
|
|
470
|
-
should.not.exist(err);
|
|
471
|
-
should.exist(results);
|
|
472
|
-
results.length.should.equal(0);
|
|
473
|
-
done();
|
|
474
478
|
});
|
|
475
479
|
|
|
476
|
-
|
|
480
|
+
it('finds an exact match by name', function (done) {
|
|
477
481
|
|
|
478
|
-
|
|
482
|
+
Organization.search({
|
|
483
|
+
name: 'testing org 1'
|
|
484
|
+
}, {fuzzy: false, admin: true, pcs: []}, function (err, results) {
|
|
485
|
+
should.not.exist(err);
|
|
486
|
+
should.exist(results);
|
|
487
|
+
results.length.should.equal(1);
|
|
488
|
+
done();
|
|
489
|
+
});
|
|
479
490
|
|
|
480
|
-
Organization.search({
|
|
481
|
-
name: 'testing org 1'
|
|
482
|
-
}, { fuzzy: false, admin: true, pcs: [] }, function(err, results) {
|
|
483
|
-
should.not.exist(err);
|
|
484
|
-
should.exist(results);
|
|
485
|
-
results.length.should.equal(1);
|
|
486
|
-
done();
|
|
487
491
|
});
|
|
488
492
|
|
|
489
|
-
|
|
493
|
+
it('finds a fuzzy match by domain', function (done) {
|
|
490
494
|
|
|
491
|
-
|
|
495
|
+
Organization.search({
|
|
496
|
+
domain: 'thesong'
|
|
497
|
+
}, {admin: true}, function (err, results) {
|
|
498
|
+
should.not.exist(err);
|
|
499
|
+
should.exist(results);
|
|
500
|
+
results.length.should.equal(1);
|
|
501
|
+
done();
|
|
502
|
+
});
|
|
492
503
|
|
|
493
|
-
Organization.search({
|
|
494
|
-
domain: 'thesong'
|
|
495
|
-
}, { admin: true }, function(err, results) {
|
|
496
|
-
should.not.exist(err);
|
|
497
|
-
should.exist(results);
|
|
498
|
-
results.length.should.equal(1);
|
|
499
|
-
done();
|
|
500
504
|
});
|
|
501
505
|
|
|
502
|
-
|
|
506
|
+
it('does not find a fuzzy match by domain', function (done) {
|
|
503
507
|
|
|
504
|
-
|
|
508
|
+
Organization.search({
|
|
509
|
+
domain: 'somethingthatisnotthere.io'
|
|
510
|
+
}, {admin: true}, function (err, results) {
|
|
511
|
+
should.not.exist(err);
|
|
512
|
+
should.exist(results);
|
|
513
|
+
results.length.should.equal(0);
|
|
514
|
+
done();
|
|
515
|
+
});
|
|
505
516
|
|
|
506
|
-
Organization.search({
|
|
507
|
-
domain: 'somethingthatisnotthere.io'
|
|
508
|
-
}, { admin: true }, function(err, results) {
|
|
509
|
-
should.not.exist(err);
|
|
510
|
-
should.exist(results);
|
|
511
|
-
results.length.should.equal(0);
|
|
512
|
-
done();
|
|
513
517
|
});
|
|
514
518
|
|
|
515
|
-
|
|
519
|
+
it('finds an exact match by domain', function (done) {
|
|
516
520
|
|
|
517
|
-
|
|
521
|
+
Organization.search({
|
|
522
|
+
domain: 'fromTHEsong.org'
|
|
523
|
+
}, {fuzzy: false, admin: true}, function (err, results) {
|
|
524
|
+
should.not.exist(err);
|
|
525
|
+
should.exist(results);
|
|
526
|
+
results.length.should.equal(1);
|
|
527
|
+
done();
|
|
528
|
+
});
|
|
518
529
|
|
|
519
|
-
Organization.search({
|
|
520
|
-
domain: 'fromTHEsong.org'
|
|
521
|
-
}, { fuzzy: false, admin: true }, function(err, results) {
|
|
522
|
-
should.not.exist(err);
|
|
523
|
-
should.exist(results);
|
|
524
|
-
results.length.should.equal(1);
|
|
525
|
-
done();
|
|
526
530
|
});
|
|
527
531
|
|
|
528
|
-
|
|
532
|
+
it('does not find an exact match by domain', function (done) {
|
|
529
533
|
|
|
530
|
-
|
|
534
|
+
Organization.search({
|
|
535
|
+
domain: 'somethingthatisnotthere.io'
|
|
536
|
+
}, {fuzzy: false, admin: true}, function (err, results) {
|
|
537
|
+
should.not.exist(err);
|
|
538
|
+
should.exist(results);
|
|
539
|
+
results.length.should.equal(0);
|
|
540
|
+
done();
|
|
541
|
+
});
|
|
531
542
|
|
|
532
|
-
Organization.search({
|
|
533
|
-
domain: 'somethingthatisnotthere.io'
|
|
534
|
-
}, { fuzzy: false, admin: true }, function(err, results) {
|
|
535
|
-
should.not.exist(err);
|
|
536
|
-
should.exist(results);
|
|
537
|
-
results.length.should.equal(0);
|
|
538
|
-
done();
|
|
539
543
|
});
|
|
540
544
|
|
|
541
|
-
|
|
545
|
+
it('searches by name with a fuzzy alias match', function (done) {
|
|
542
546
|
|
|
543
|
-
|
|
547
|
+
Organization.search({
|
|
548
|
+
name: 'sicle'
|
|
549
|
+
}, {fuzzy: true, admin: true}, function (err, results) {
|
|
550
|
+
should.not.exist(err);
|
|
551
|
+
should.exist(results);
|
|
552
|
+
results.length.should.equal(1);
|
|
553
|
+
done();
|
|
554
|
+
});
|
|
544
555
|
|
|
545
|
-
Organization.search({
|
|
546
|
-
name: 'sicle'
|
|
547
|
-
}, { fuzzy: true, admin: true }, function(err, results) {
|
|
548
|
-
should.not.exist(err);
|
|
549
|
-
should.exist(results);
|
|
550
|
-
results.length.should.equal(1);
|
|
551
|
-
done();
|
|
552
556
|
});
|
|
553
557
|
|
|
554
|
-
|
|
558
|
+
it('searches by name with a strict alias match', function (done) {
|
|
555
559
|
|
|
556
|
-
|
|
560
|
+
Organization.search({
|
|
561
|
+
name: 'NT2'
|
|
562
|
+
}, {fuzzy: false, admin: true}, function (err, results) {
|
|
563
|
+
should.not.exist(err);
|
|
564
|
+
should.exist(results);
|
|
565
|
+
results.length.should.equal(1);
|
|
566
|
+
done();
|
|
567
|
+
});
|
|
557
568
|
|
|
558
|
-
Organization.search({
|
|
559
|
-
name: 'NT2'
|
|
560
|
-
}, { fuzzy: false, admin: true }, function(err, results) {
|
|
561
|
-
should.not.exist(err);
|
|
562
|
-
should.exist(results);
|
|
563
|
-
results.length.should.equal(1);
|
|
564
|
-
done();
|
|
565
569
|
});
|
|
566
570
|
|
|
567
|
-
|
|
571
|
+
it('finds org by slug', function (done) {
|
|
568
572
|
|
|
569
|
-
|
|
573
|
+
Organization.findBySlug('org2-slug', function (err, org) {
|
|
574
|
+
should.not.exist(err);
|
|
575
|
+
should.exist(org);
|
|
576
|
+
done();
|
|
577
|
+
});
|
|
570
578
|
|
|
571
|
-
|
|
572
|
-
should.not.exist(err);
|
|
573
|
-
should.exist(org);
|
|
574
|
-
done();
|
|
575
|
-
});
|
|
579
|
+
});
|
|
576
580
|
|
|
577
|
-
|
|
581
|
+
it('finds org by slugs', function (done) {
|
|
578
582
|
|
|
579
|
-
|
|
583
|
+
Organization.findBySlugs(['fudge-3', 'org2-slug'], function (err, orgs) {
|
|
584
|
+
should.not.exist(err);
|
|
585
|
+
should.exist(orgs);
|
|
586
|
+
orgs.length.should.equal(2);
|
|
587
|
+
done();
|
|
588
|
+
});
|
|
580
589
|
|
|
581
|
-
|
|
582
|
-
should.not.exist(err);
|
|
583
|
-
should.exist(orgs);
|
|
584
|
-
orgs.length.should.equal(2);
|
|
585
|
-
done();
|
|
586
|
-
});
|
|
590
|
+
});
|
|
587
591
|
|
|
588
|
-
|
|
592
|
+
it('adds a person to people', function (done) {
|
|
589
593
|
|
|
590
|
-
|
|
594
|
+
org1.addPerson({person: person._id});
|
|
595
|
+
Organization.upsert(org1, 'test-user', function (err, updatedOrg) {
|
|
596
|
+
should.not.exist(err);
|
|
597
|
+
should.exist(updatedOrg);
|
|
598
|
+
updatedOrg.people.length.should.equal(1);
|
|
599
|
+
return done();
|
|
600
|
+
});
|
|
591
601
|
|
|
592
|
-
org1.addPerson({ person: person._id });
|
|
593
|
-
Organization.upsert(org1, 'test-user', function(err, updatedOrg) {
|
|
594
|
-
should.not.exist(err);
|
|
595
|
-
should.exist(updatedOrg);
|
|
596
|
-
updatedOrg.people.length.should.equal(1);
|
|
597
|
-
return done();
|
|
598
602
|
});
|
|
599
603
|
|
|
600
|
-
|
|
604
|
+
it('finds an org without mongoose sugar', function (done) {
|
|
601
605
|
|
|
602
|
-
|
|
606
|
+
Organization.getByIdRaw(org1._id, {}, function (err, result) {
|
|
607
|
+
should.not.exist(err);
|
|
608
|
+
should.exist(result);
|
|
609
|
+
(result instanceof Organization).should.equal(false);
|
|
610
|
+
done();
|
|
611
|
+
});
|
|
603
612
|
|
|
604
|
-
Organization.getByIdRaw(org1._id, {}, function(err, result) {
|
|
605
|
-
should.not.exist(err);
|
|
606
|
-
should.exist(result);
|
|
607
|
-
(result instanceof Organization).should.equal(false);
|
|
608
|
-
done();
|
|
609
613
|
});
|
|
610
614
|
|
|
611
|
-
|
|
615
|
+
it('gets an org by id', function (done) {
|
|
612
616
|
|
|
613
|
-
|
|
617
|
+
Organization.getById(org1.id, {role: 'lp-full'}, function (err, org) {
|
|
618
|
+
should.not.exist(err);
|
|
619
|
+
should.exist(org);
|
|
620
|
+
org1 = org;
|
|
621
|
+
org1.id.should.equal(org.id);
|
|
622
|
+
return done();
|
|
623
|
+
});
|
|
614
624
|
|
|
615
|
-
|
|
616
|
-
should.not.exist(err);
|
|
617
|
-
should.exist(org);
|
|
618
|
-
org1 = org;
|
|
619
|
-
org1.id.should.equal(org.id);
|
|
620
|
-
return done();
|
|
621
|
-
});
|
|
625
|
+
});
|
|
622
626
|
|
|
623
|
-
|
|
627
|
+
it('updates a company', function (done) {
|
|
624
628
|
|
|
625
|
-
|
|
629
|
+
org1.name = 'Update';
|
|
626
630
|
|
|
627
|
-
|
|
631
|
+
Organization.upsert(org1, 'test-user', function (err, org) {
|
|
632
|
+
should.not.exist(err);
|
|
633
|
+
should.exist(org);
|
|
634
|
+
org.name.should.equal('Update');
|
|
635
|
+
done();
|
|
636
|
+
});
|
|
628
637
|
|
|
629
|
-
|
|
630
|
-
should.not.exist(err);
|
|
631
|
-
should.exist(org);
|
|
632
|
-
org.name.should.equal('Update');
|
|
633
|
-
done();
|
|
634
|
-
});
|
|
638
|
+
});
|
|
635
639
|
|
|
636
|
-
|
|
640
|
+
it('modifies a company', function (done) {
|
|
637
641
|
|
|
638
|
-
|
|
642
|
+
var update = {
|
|
643
|
+
$set: {
|
|
644
|
+
'name': 'I updated my name!',
|
|
645
|
+
'entered.by': 'Testy McTester',
|
|
646
|
+
'entered.on': new Date()
|
|
647
|
+
}
|
|
648
|
+
};
|
|
639
649
|
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
}
|
|
646
|
-
};
|
|
650
|
+
Organization.modify(org1._id, update, function (err, org) {
|
|
651
|
+
should.not.exist(err);
|
|
652
|
+
should.exist(org);
|
|
653
|
+
org.name.should.equal('I updated my name!');
|
|
654
|
+
done();
|
|
655
|
+
});
|
|
647
656
|
|
|
648
|
-
Organization.modify(org1._id, update, function(err, org) {
|
|
649
|
-
should.not.exist(err);
|
|
650
|
-
should.exist(org);
|
|
651
|
-
org.name.should.equal('I updated my name!');
|
|
652
|
-
done();
|
|
653
657
|
});
|
|
654
658
|
|
|
655
|
-
|
|
659
|
+
it('merges an org', function (done) {
|
|
656
660
|
|
|
657
|
-
|
|
661
|
+
var merged = org1.merge(mergeId);
|
|
662
|
+
merged.should.equal(true);
|
|
663
|
+
done();
|
|
658
664
|
|
|
659
|
-
|
|
660
|
-
merged.should.equal(true);
|
|
661
|
-
done();
|
|
665
|
+
});
|
|
662
666
|
|
|
663
|
-
|
|
667
|
+
it('does not merge an org that has already been merged', function (done) {
|
|
664
668
|
|
|
665
|
-
|
|
669
|
+
var merged = org1.merge(mergeId);
|
|
670
|
+
merged.should.equal(false);
|
|
671
|
+
done();
|
|
666
672
|
|
|
667
|
-
|
|
668
|
-
merged.should.equal(false);
|
|
669
|
-
done();
|
|
673
|
+
});
|
|
670
674
|
|
|
671
|
-
|
|
675
|
+
it('finds orgs by person', function (done) {
|
|
672
676
|
|
|
673
|
-
|
|
677
|
+
Organization.findByPerson(person.id, function (err, result) {
|
|
678
|
+
should.not.exist(err);
|
|
679
|
+
should.exist(result);
|
|
680
|
+
result.length.should.equal(1);
|
|
681
|
+
result[0].id.should.equal(org1.id);
|
|
682
|
+
done();
|
|
683
|
+
});
|
|
674
684
|
|
|
675
|
-
Organization.findByPerson(person.id, function(err, result) {
|
|
676
|
-
should.not.exist(err);
|
|
677
|
-
should.exist(result);
|
|
678
|
-
result.length.should.equal(1);
|
|
679
|
-
result[0].id.should.equal(org1.id);
|
|
680
|
-
done();
|
|
681
685
|
});
|
|
682
686
|
|
|
683
|
-
|
|
687
|
+
it('finds orgs by person without mongoose sugar', function (done) {
|
|
684
688
|
|
|
685
|
-
|
|
689
|
+
Organization.findByPersonRaw(person._id, function (err, result) {
|
|
690
|
+
should.not.exist(err);
|
|
691
|
+
should.exist(result);
|
|
692
|
+
result.length.should.equal(1);
|
|
693
|
+
result[0]._id.toString().should.equal(org1.id.toString());
|
|
694
|
+
(result[0] instanceof Organization).should.equal(false);
|
|
695
|
+
done();
|
|
696
|
+
});
|
|
686
697
|
|
|
687
|
-
Organization.findByPersonRaw(person._id, function(err, result) {
|
|
688
|
-
should.not.exist(err);
|
|
689
|
-
should.exist(result);
|
|
690
|
-
result.length.should.equal(1);
|
|
691
|
-
result[0]._id.toString().should.equal(org1.id.toString());
|
|
692
|
-
(result[0] instanceof Organization).should.equal(false);
|
|
693
|
-
done();
|
|
694
698
|
});
|
|
695
699
|
|
|
696
|
-
|
|
700
|
+
it('finds boards of a person', function (done) {
|
|
697
701
|
|
|
698
|
-
|
|
702
|
+
Organization.getBoardsOfPerson(person2.id, function (err, result) {
|
|
703
|
+
should.not.exist(err);
|
|
704
|
+
should.exist(result);
|
|
705
|
+
result.length.should.equal(1);
|
|
706
|
+
done();
|
|
707
|
+
});
|
|
699
708
|
|
|
700
|
-
Organization.getBoardsOfPerson(person2.id, function(err, result) {
|
|
701
|
-
should.not.exist(err);
|
|
702
|
-
should.exist(result);
|
|
703
|
-
result.length.should.equal(1);
|
|
704
|
-
done();
|
|
705
709
|
});
|
|
706
710
|
|
|
707
|
-
|
|
711
|
+
it('finds chairs of a person', function (done) {
|
|
708
712
|
|
|
709
|
-
|
|
713
|
+
Organization.getChairsOfPerson(person2.id, function (err, result) {
|
|
714
|
+
should.not.exist(err);
|
|
715
|
+
should.exist(result);
|
|
716
|
+
result.length.should.equal(1);
|
|
717
|
+
done();
|
|
718
|
+
});
|
|
710
719
|
|
|
711
|
-
Organization.getChairsOfPerson(person2.id, function(err, result) {
|
|
712
|
-
should.not.exist(err);
|
|
713
|
-
should.exist(result);
|
|
714
|
-
result.length.should.equal(1);
|
|
715
|
-
done();
|
|
716
720
|
});
|
|
717
721
|
|
|
718
|
-
|
|
722
|
+
it('gets the board of a company', function (done) {
|
|
719
723
|
|
|
720
|
-
|
|
724
|
+
Organization.getById(org3.id, {role: 'lp-full'}, function (err, result) {
|
|
725
|
+
should.not.exist(err);
|
|
726
|
+
should.exist(result);
|
|
727
|
+
var board = result.board;
|
|
728
|
+
board.all.length.should.equal(2);
|
|
729
|
+
done();
|
|
730
|
+
});
|
|
721
731
|
|
|
722
|
-
Organization.getById(org3.id, { role: 'lp-full' }, function(err, result) {
|
|
723
|
-
should.not.exist(err);
|
|
724
|
-
should.exist(result);
|
|
725
|
-
var board = result.board;
|
|
726
|
-
board.all.length.should.equal(2);
|
|
727
|
-
done();
|
|
728
732
|
});
|
|
729
733
|
|
|
730
|
-
|
|
734
|
+
it('removes a person from people (unpopulated)', function (done) {
|
|
731
735
|
|
|
732
|
-
|
|
736
|
+
// remove person
|
|
737
|
+
org1.removePerson(person.id);
|
|
738
|
+
Organization.upsert(org1, 'test-user', function (err, updatedOrg) {
|
|
739
|
+
should.not.exist(err);
|
|
740
|
+
should.exist(updatedOrg);
|
|
741
|
+
updatedOrg.people.length.should.equal(0);
|
|
742
|
+
done();
|
|
743
|
+
});
|
|
733
744
|
|
|
734
|
-
// remove person
|
|
735
|
-
org1.removePerson(person.id);
|
|
736
|
-
Organization.upsert(org1, 'test-user', function(err, updatedOrg) {
|
|
737
|
-
should.not.exist(err);
|
|
738
|
-
should.exist(updatedOrg);
|
|
739
|
-
updatedOrg.people.length.should.equal(0);
|
|
740
|
-
done();
|
|
741
745
|
});
|
|
742
746
|
|
|
743
|
-
|
|
747
|
+
it('removes a person from people (populated)', function (done) {
|
|
744
748
|
|
|
745
|
-
|
|
749
|
+
// add person to be removed
|
|
750
|
+
org1.addPerson({person: person.id});
|
|
751
|
+
Organization.upsert(org1, 'test-user', function (err, updatedOrg) {
|
|
752
|
+
should.not.exist(err);
|
|
753
|
+
should.exist(updatedOrg);
|
|
754
|
+
updatedOrg.people.length.should.equal(1);
|
|
746
755
|
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
Organization.upsert(org1, 'test-user', function(err, updatedOrg) {
|
|
750
|
-
should.not.exist(err);
|
|
751
|
-
should.exist(updatedOrg);
|
|
752
|
-
updatedOrg.people.length.should.equal(1);
|
|
756
|
+
// get populated org
|
|
757
|
+
Organization.getById(org1.id, {role: 'lp-full'}, function (err, org) {
|
|
753
758
|
|
|
754
|
-
|
|
755
|
-
|
|
759
|
+
should.not.exist(err);
|
|
760
|
+
should.exist(org);
|
|
756
761
|
|
|
757
|
-
|
|
758
|
-
|
|
762
|
+
// remove person
|
|
763
|
+
org.removePerson(person.id);
|
|
764
|
+
Organization.upsert(org, 'test-user', function (err, updatedOrg) {
|
|
765
|
+
should.not.exist(err);
|
|
766
|
+
should.exist(updatedOrg);
|
|
767
|
+
updatedOrg.people.length.should.equal(0);
|
|
768
|
+
done();
|
|
769
|
+
});
|
|
759
770
|
|
|
760
|
-
// remove person
|
|
761
|
-
org.removePerson(person.id);
|
|
762
|
-
Organization.upsert(org, 'test-user', function(err, updatedOrg) {
|
|
763
|
-
should.not.exist(err);
|
|
764
|
-
should.exist(updatedOrg);
|
|
765
|
-
updatedOrg.people.length.should.equal(0);
|
|
766
|
-
done();
|
|
767
771
|
});
|
|
768
772
|
|
|
769
773
|
});
|
|
770
774
|
|
|
771
775
|
});
|
|
772
776
|
|
|
773
|
-
|
|
777
|
+
it('it flags an org', function (done) {
|
|
774
778
|
|
|
775
|
-
|
|
779
|
+
Organization.flag(org4.id, false, 'flagging org4', 'test-user', function (err, org) {
|
|
780
|
+
should.not.exist(err);
|
|
781
|
+
should.exist(org);
|
|
782
|
+
org.flagged.text.should.equal('flagging org4');
|
|
783
|
+
done();
|
|
784
|
+
});
|
|
785
|
+
}); // end flag an org
|
|
776
786
|
|
|
777
|
-
|
|
778
|
-
should.not.exist(err);
|
|
779
|
-
should.exist(org);
|
|
780
|
-
org.flagged.text.should.equal('flagging org4');
|
|
781
|
-
done();
|
|
782
|
-
});
|
|
783
|
-
}); // end flag an org
|
|
787
|
+
it('finds dupes by querying first word of name', function (done) {
|
|
784
788
|
|
|
785
|
-
|
|
789
|
+
var options = {
|
|
790
|
+
fuzzy: true,
|
|
791
|
+
queryFirstWord: true,
|
|
792
|
+
admin: true,
|
|
793
|
+
pcs: []
|
|
794
|
+
};
|
|
786
795
|
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
796
|
+
Organization.findDupes(org3, options, function (err, dupes) {
|
|
797
|
+
should.not.exist(err);
|
|
798
|
+
should.exist(dupes);
|
|
799
|
+
dupes.length.should.equal(1);
|
|
800
|
+
done();
|
|
801
|
+
});
|
|
793
802
|
|
|
794
|
-
Organization.findDupes(org3, options, function(err, dupes) {
|
|
795
|
-
should.not.exist(err);
|
|
796
|
-
should.exist(dupes);
|
|
797
|
-
dupes.length.should.equal(1);
|
|
798
|
-
done();
|
|
799
803
|
});
|
|
800
804
|
|
|
801
|
-
|
|
805
|
+
it('does not find dupes by querying full name', function (done) {
|
|
802
806
|
|
|
803
|
-
|
|
807
|
+
var options = {
|
|
808
|
+
fuzzy: true,
|
|
809
|
+
queryFirstWord: false,
|
|
810
|
+
admin: true,
|
|
811
|
+
pcs: []
|
|
812
|
+
};
|
|
804
813
|
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
814
|
+
Organization.findDupes(org3, options, function (err, dupes) {
|
|
815
|
+
should.not.exist(err);
|
|
816
|
+
should.exist(dupes);
|
|
817
|
+
dupes.length.should.equal(0);
|
|
818
|
+
done();
|
|
819
|
+
});
|
|
811
820
|
|
|
812
|
-
Organization.findDupes(org3, options, function(err, dupes) {
|
|
813
|
-
should.not.exist(err);
|
|
814
|
-
should.exist(dupes);
|
|
815
|
-
dupes.length.should.equal(0);
|
|
816
|
-
done();
|
|
817
821
|
});
|
|
818
822
|
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
return done();
|
|
823
|
+
it('finds orgs by domain', function (done) {
|
|
824
|
+
Organization.findByDomains(['nothanks2.org', 'fromthesong.org'], function (err, result) {
|
|
825
|
+
should.not.exist(err);
|
|
826
|
+
should.exist(result);
|
|
827
|
+
result.length.should.equal(2);
|
|
828
|
+
return done();
|
|
829
|
+
});
|
|
827
830
|
});
|
|
828
|
-
});
|
|
829
831
|
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
832
|
+
it('finds orgs by ids', function (done) {
|
|
833
|
+
Organization.findByIds([org4._id, org5._id], function (err, result) {
|
|
834
|
+
should.not.exist(err);
|
|
835
|
+
should.exist(result);
|
|
836
|
+
result.length.should.equal(2);
|
|
837
|
+
return done();
|
|
838
|
+
});
|
|
836
839
|
});
|
|
837
|
-
});
|
|
838
840
|
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
841
|
+
it('finds org by domain alias', function (done) {
|
|
842
|
+
Organization.findByDomains(['doesnotexist.io', 'myolddomain.tld'], function (err, result) {
|
|
843
|
+
should.not.exist(err);
|
|
844
|
+
should.exist(result);
|
|
845
|
+
result.length.should.equal(1);
|
|
846
|
+
return done();
|
|
847
|
+
});
|
|
845
848
|
});
|
|
846
|
-
});
|
|
847
849
|
|
|
848
|
-
|
|
850
|
+
it('adds a flag', function (done) {
|
|
849
851
|
|
|
850
|
-
|
|
852
|
+
Organization.addFlag(org4.id, person._id, 'Sweet flag bro!', function (err, result) {
|
|
851
853
|
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
854
|
+
should.not.exist(err);
|
|
855
|
+
should.exist(result);
|
|
856
|
+
should.exist(result.flag);
|
|
857
|
+
should.exist(result.addedTo);
|
|
858
|
+
result.addedTo.flags.length.should.equal(1);
|
|
857
859
|
|
|
858
|
-
|
|
860
|
+
flagId = result.addedTo.flags[0];
|
|
859
861
|
|
|
860
|
-
|
|
862
|
+
return done();
|
|
863
|
+
|
|
864
|
+
});
|
|
861
865
|
|
|
862
866
|
});
|
|
863
867
|
|
|
864
|
-
|
|
868
|
+
it('deletes a flag', function (done) {
|
|
865
869
|
|
|
866
|
-
|
|
870
|
+
Organization.deleteFlag(flagId, function (err, result) {
|
|
867
871
|
|
|
868
|
-
|
|
872
|
+
should.not.exist(err);
|
|
869
873
|
|
|
870
|
-
|
|
874
|
+
return done();
|
|
871
875
|
|
|
872
|
-
|
|
876
|
+
});
|
|
873
877
|
|
|
874
878
|
});
|
|
875
879
|
|
|
876
|
-
|
|
880
|
+
it('adds a note', function (done) {
|
|
877
881
|
|
|
878
|
-
|
|
882
|
+
Organization.addNote(org4.id, person._id, 'Sweet note bro!', function (err, result) {
|
|
879
883
|
|
|
880
|
-
|
|
884
|
+
should.not.exist(err);
|
|
885
|
+
should.exist(result);
|
|
886
|
+
should.exist(result.note);
|
|
887
|
+
should.exist(result.addedTo);
|
|
888
|
+
result.addedTo.notes.length.should.equal(1);
|
|
881
889
|
|
|
882
|
-
|
|
883
|
-
should.exist(result);
|
|
884
|
-
should.exist(result.note);
|
|
885
|
-
should.exist(result.addedTo);
|
|
886
|
-
result.addedTo.notes.length.should.equal(1);
|
|
890
|
+
noteId = result.addedTo.notes[0];
|
|
887
891
|
|
|
888
|
-
|
|
892
|
+
return done();
|
|
889
893
|
|
|
890
|
-
|
|
894
|
+
});
|
|
891
895
|
|
|
892
896
|
});
|
|
893
897
|
|
|
894
|
-
|
|
898
|
+
it('deletes a simple note', function (done) {
|
|
895
899
|
|
|
896
|
-
|
|
900
|
+
Organization.deleteNote(noteId, function (err, result) {
|
|
897
901
|
|
|
898
|
-
|
|
902
|
+
should.not.exist(err);
|
|
899
903
|
|
|
900
|
-
|
|
904
|
+
return done();
|
|
901
905
|
|
|
902
|
-
|
|
906
|
+
});
|
|
903
907
|
|
|
904
908
|
});
|
|
905
909
|
|
|
906
|
-
|
|
910
|
+
it('formats website domains', function (done) {
|
|
907
911
|
|
|
908
|
-
|
|
912
|
+
var temp = new Organization();
|
|
913
|
+
temp.name = 'I Love Poorly Formatted Domains';
|
|
914
|
+
temp.slug = 'i-love';
|
|
915
|
+
temp.deleted = false;
|
|
916
|
+
temp.website = 'https://www.yum.net/';
|
|
917
|
+
temp.websiteAliases = [
|
|
918
|
+
'http://yum.co',
|
|
919
|
+
'anglophile.co.uk',
|
|
920
|
+
'abc.subdomain.com',
|
|
921
|
+
'trailingslash.edu/'
|
|
922
|
+
];
|
|
909
923
|
|
|
910
|
-
|
|
911
|
-
temp.name = 'I Love Poorly Formatted Domains';
|
|
912
|
-
temp.slug = 'i-love';
|
|
913
|
-
temp.deleted = false;
|
|
914
|
-
temp.website = 'https://www.yum.net/';
|
|
915
|
-
temp.websiteAliases = [
|
|
916
|
-
'http://yum.co',
|
|
917
|
-
'anglophile.co.uk',
|
|
918
|
-
'abc.subdomain.com',
|
|
919
|
-
'trailingslash.edu/'
|
|
920
|
-
];
|
|
924
|
+
Organization.upsert(temp, 'test-user', function (err, result) {
|
|
921
925
|
|
|
922
|
-
|
|
926
|
+
should.not.exist(err);
|
|
927
|
+
should.exist(result);
|
|
928
|
+
result.website.should.equal('yum.net');
|
|
929
|
+
result.websiteAliases.length.should.equal(5); // the four aliases plus the primary
|
|
930
|
+
result.websiteAliases.indexOf('yum.co').should.not.equal(-1);
|
|
931
|
+
result.websiteAliases.indexOf('anglophile.co.uk').should.not.equal(-1);
|
|
932
|
+
result.websiteAliases.indexOf('abc.subdomain.com').should.not.equal(-1);
|
|
933
|
+
result.websiteAliases.indexOf('trailingslash.edu').should.not.equal(-1);
|
|
923
934
|
|
|
924
|
-
|
|
925
|
-
should.exist(result);
|
|
926
|
-
result.website.should.equal('yum.net');
|
|
927
|
-
result.websiteAliases.length.should.equal(5); // the four aliases plus the primary
|
|
928
|
-
result.websiteAliases.indexOf('yum.co').should.not.equal(-1);
|
|
929
|
-
result.websiteAliases.indexOf('anglophile.co.uk').should.not.equal(-1);
|
|
930
|
-
result.websiteAliases.indexOf('abc.subdomain.com').should.not.equal(-1);
|
|
931
|
-
result.websiteAliases.indexOf('trailingslash.edu').should.not.equal(-1);
|
|
935
|
+
Organization.getById(temp._id, {role: 'lp-full'}, function (err, result) {
|
|
932
936
|
|
|
933
|
-
|
|
937
|
+
should.not.exist(err);
|
|
938
|
+
should.exist(result);
|
|
934
939
|
|
|
935
|
-
|
|
936
|
-
|
|
940
|
+
// main website should no longer be here because of post-find hook
|
|
941
|
+
result.websiteAliases.length.should.equal(4);
|
|
937
942
|
|
|
938
|
-
|
|
939
|
-
result.websiteAliases.length.should.equal(4);
|
|
943
|
+
return done();
|
|
940
944
|
|
|
941
|
-
|
|
945
|
+
});
|
|
942
946
|
|
|
943
947
|
});
|
|
944
948
|
|
|
945
949
|
});
|
|
946
950
|
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
it('gets lps', function(done) {
|
|
951
|
+
it('gets lps', function (done) {
|
|
950
952
|
|
|
951
953
|
var lp = new LimitedPartner();
|
|
952
954
|
lp.name = 'LP';
|
|
953
955
|
lp.customer = config.CUSTOMER_ID;
|
|
954
956
|
|
|
955
|
-
LimitedPartner.upsert(lp, 'test', 'lp-full', function(err, lpResult) {
|
|
957
|
+
LimitedPartner.upsert(lp, 'test', 'lp-full', function (err, lpResult) {
|
|
956
958
|
|
|
957
959
|
should.not.exist(err);
|
|
958
960
|
should.exist(lpResult);
|
|
@@ -964,19 +966,19 @@ describe.only('Organization', function() {
|
|
|
964
966
|
o.lps.push(lpResult);
|
|
965
967
|
o.lps.push(someOtherLp);
|
|
966
968
|
|
|
967
|
-
Organization.upsert(o, 'test-user', function(err, orgResult) {
|
|
969
|
+
Organization.upsert(o, 'test-user', function (err, orgResult) {
|
|
968
970
|
|
|
969
971
|
should.not.exist(err);
|
|
970
972
|
should.exist(orgResult);
|
|
971
973
|
|
|
972
|
-
Organization.getById(orgResult._id, {
|
|
974
|
+
Organization.getById(orgResult._id, {role: 'lp-full'}, function (err, result) {
|
|
973
975
|
|
|
974
976
|
should.not.exist(err);
|
|
975
977
|
should.exist(result);
|
|
976
978
|
result.lps.length.should.equal(1);
|
|
977
979
|
result.lps[0]._id.toString().should.equal(lpResult._id.toString());
|
|
978
980
|
|
|
979
|
-
Organization.getById(orgResult._id, {
|
|
981
|
+
Organization.getById(orgResult._id, {role: 'none'}, function (err, result) {
|
|
980
982
|
|
|
981
983
|
should.not.exist(err);
|
|
982
984
|
should.exist(result);
|
|
@@ -991,130 +993,138 @@ describe.only('Organization', function() {
|
|
|
991
993
|
|
|
992
994
|
});
|
|
993
995
|
|
|
994
|
-
|
|
996
|
+
});
|
|
995
997
|
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
var o = new Organization();
|
|
999
|
-
o.name = 'ORG';
|
|
1000
|
-
o.slug = 'org';
|
|
1001
|
-
o.website = 'org.org';
|
|
1002
|
-
|
|
1003
|
-
o.contact.address = [];
|
|
1004
|
-
o.contact.address.push({
|
|
1005
|
-
city: 'Testville',
|
|
1006
|
-
state: 'Test',
|
|
1007
|
-
country: 'TSA',
|
|
1008
|
-
type: 'work',
|
|
1009
|
-
primary: true
|
|
1010
|
-
});
|
|
1011
|
-
o.contact.address.push({
|
|
1012
|
-
city: 'Testville',
|
|
1013
|
-
state: 'Test',
|
|
1014
|
-
country: 'TSA',
|
|
1015
|
-
type: 'other',
|
|
1016
|
-
primary: true
|
|
1017
|
-
});
|
|
1018
|
-
o.contact.address.push({
|
|
1019
|
-
city: 'Bangor',
|
|
1020
|
-
state: 'ME',
|
|
1021
|
-
country: 'USA',
|
|
1022
|
-
type: 'other',
|
|
1023
|
-
primary: true
|
|
1024
|
-
});
|
|
1025
|
-
o.contact.address.push({
|
|
1026
|
-
city: '',
|
|
1027
|
-
state: '',
|
|
1028
|
-
country: '',
|
|
1029
|
-
type: 'other',
|
|
1030
|
-
primary: true
|
|
1031
|
-
});
|
|
1032
|
-
|
|
1033
|
-
o.contact.email = [];
|
|
1034
|
-
o.contact.email.push({
|
|
1035
|
-
email: 'test@org.org',
|
|
1036
|
-
type: 'work',
|
|
1037
|
-
primary: true
|
|
1038
|
-
});
|
|
1039
|
-
o.contact.email.push({
|
|
1040
|
-
email: 'test@org.org',
|
|
1041
|
-
type: 'other',
|
|
1042
|
-
primary: true
|
|
1043
|
-
});
|
|
1044
|
-
o.contact.email.push({
|
|
1045
|
-
email: 'admin@org.org',
|
|
1046
|
-
type: 'other',
|
|
1047
|
-
primary: true
|
|
1048
|
-
});
|
|
1049
|
-
o.contact.email.push({
|
|
1050
|
-
email: '',
|
|
1051
|
-
type: 'test',
|
|
1052
|
-
primary: false
|
|
1053
|
-
});
|
|
1054
|
-
|
|
1055
|
-
o.contact.phone = [];
|
|
1056
|
-
o.contact.phone.push({
|
|
1057
|
-
number: '2075551212',
|
|
1058
|
-
type: 'work',
|
|
1059
|
-
primary: true
|
|
1060
|
-
});
|
|
1061
|
-
o.contact.phone.push({
|
|
1062
|
-
number: '2075551212',
|
|
1063
|
-
type: 'other',
|
|
1064
|
-
primary: true
|
|
1065
|
-
});
|
|
1066
|
-
o.contact.phone.push({
|
|
1067
|
-
number: null,
|
|
1068
|
-
type: null,
|
|
1069
|
-
primary: null
|
|
1070
|
-
});
|
|
1071
|
-
o.contact.phone.push({
|
|
1072
|
-
number: '3455551212',
|
|
1073
|
-
type: 'other',
|
|
1074
|
-
primary: true
|
|
1075
|
-
});
|
|
1076
|
-
|
|
1077
|
-
Organization.upsert(o, 'test-user', function(err, org) {
|
|
998
|
+
it('cleans contact info', function (done) {
|
|
1078
999
|
|
|
1079
|
-
|
|
1080
|
-
|
|
1000
|
+
var o = new Organization();
|
|
1001
|
+
o.name = 'ORG';
|
|
1002
|
+
o.slug = 'org';
|
|
1003
|
+
o.website = 'org.org';
|
|
1081
1004
|
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1005
|
+
o.contact.address = [];
|
|
1006
|
+
o.contact.address.push({
|
|
1007
|
+
city: 'Testville',
|
|
1008
|
+
state: 'Test',
|
|
1009
|
+
country: 'TSA',
|
|
1010
|
+
type: 'work',
|
|
1011
|
+
primary: true
|
|
1012
|
+
});
|
|
1013
|
+
o.contact.address.push({
|
|
1014
|
+
city: 'Testville',
|
|
1015
|
+
state: 'Test',
|
|
1016
|
+
country: 'TSA',
|
|
1017
|
+
type: 'other',
|
|
1018
|
+
primary: true
|
|
1019
|
+
});
|
|
1020
|
+
o.contact.address.push({
|
|
1021
|
+
city: 'Bangor',
|
|
1022
|
+
state: 'ME',
|
|
1023
|
+
country: 'USA',
|
|
1024
|
+
type: 'other',
|
|
1025
|
+
primary: true
|
|
1026
|
+
});
|
|
1027
|
+
o.contact.address.push({
|
|
1028
|
+
city: '',
|
|
1029
|
+
state: '',
|
|
1030
|
+
country: '',
|
|
1031
|
+
type: 'other',
|
|
1032
|
+
primary: true
|
|
1033
|
+
});
|
|
1085
1034
|
|
|
1086
|
-
|
|
1087
|
-
|
|
1035
|
+
o.contact.email = [];
|
|
1036
|
+
o.contact.email.push({
|
|
1037
|
+
email: 'test@org.org',
|
|
1038
|
+
type: 'work',
|
|
1039
|
+
primary: true
|
|
1040
|
+
});
|
|
1041
|
+
o.contact.email.push({
|
|
1042
|
+
email: 'test@org.org',
|
|
1043
|
+
type: 'other',
|
|
1044
|
+
primary: true
|
|
1045
|
+
});
|
|
1046
|
+
o.contact.email.push({
|
|
1047
|
+
email: 'admin@org.org',
|
|
1048
|
+
type: 'other',
|
|
1049
|
+
primary: true
|
|
1050
|
+
});
|
|
1051
|
+
o.contact.email.push({
|
|
1052
|
+
email: '',
|
|
1053
|
+
type: 'test',
|
|
1054
|
+
primary: false
|
|
1055
|
+
});
|
|
1088
1056
|
|
|
1089
|
-
|
|
1090
|
-
|
|
1057
|
+
o.contact.phone = [];
|
|
1058
|
+
o.contact.phone.push({
|
|
1059
|
+
number: '2075551212',
|
|
1060
|
+
type: 'work',
|
|
1061
|
+
primary: true
|
|
1062
|
+
});
|
|
1063
|
+
o.contact.phone.push({
|
|
1064
|
+
number: '2075551212',
|
|
1065
|
+
type: 'other',
|
|
1066
|
+
primary: true
|
|
1067
|
+
});
|
|
1068
|
+
o.contact.phone.push({
|
|
1069
|
+
number: null,
|
|
1070
|
+
type: null,
|
|
1071
|
+
primary: null
|
|
1072
|
+
});
|
|
1073
|
+
o.contact.phone.push({
|
|
1074
|
+
number: '3455551212',
|
|
1075
|
+
type: 'other',
|
|
1076
|
+
primary: true
|
|
1077
|
+
});
|
|
1091
1078
|
|
|
1092
|
-
|
|
1093
|
-
primaryPhones.length.should.be.lessThan(2);
|
|
1079
|
+
Organization.upsert(o, 'test-user', function (err, org) {
|
|
1094
1080
|
|
|
1095
|
-
|
|
1081
|
+
should.not.exist(err);
|
|
1082
|
+
should.exist(org);
|
|
1083
|
+
|
|
1084
|
+
org.contact.address.length.should.equal(2);
|
|
1085
|
+
org.contact.email.length.should.equal(2);
|
|
1086
|
+
org.contact.phone.length.should.equal(2);
|
|
1087
|
+
|
|
1088
|
+
var primaryAddresses = _.filter(org.contact.address, function (item) {
|
|
1089
|
+
return item.primary;
|
|
1090
|
+
});
|
|
1091
|
+
primaryAddresses.length.should.be.lessThan(2);
|
|
1092
|
+
|
|
1093
|
+
var primaryEmails = _.filter(org.contact.email, function (item) {
|
|
1094
|
+
return item.primary;
|
|
1095
|
+
});
|
|
1096
|
+
primaryEmails.length.should.be.lessThan(2);
|
|
1097
|
+
|
|
1098
|
+
var primaryPhones = _.filter(org.contact.phone, function (item) {
|
|
1099
|
+
return item.primary;
|
|
1100
|
+
});
|
|
1101
|
+
primaryPhones.length.should.be.lessThan(2);
|
|
1096
1102
|
|
|
1103
|
+
done();
|
|
1104
|
+
|
|
1105
|
+
});
|
|
1097
1106
|
});
|
|
1098
|
-
});
|
|
1099
1107
|
|
|
1100
|
-
|
|
1108
|
+
it('cleans people', function (done) {
|
|
1101
1109
|
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1110
|
+
var littleDirtyOrg = new Organization();
|
|
1111
|
+
littleDirtyOrg.name = 'N00b';
|
|
1112
|
+
littleDirtyOrg.slug = 'n00b';
|
|
1105
1113
|
|
|
1106
|
-
|
|
1114
|
+
var temp = new mongoose.Types.ObjectId();
|
|
1107
1115
|
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1116
|
+
littleDirtyOrg.addPerson({person: temp});
|
|
1117
|
+
littleDirtyOrg.addPerson({person: temp});
|
|
1118
|
+
littleDirtyOrg.addPerson({person: new mongoose.Types.ObjectId()});
|
|
1119
|
+
littleDirtyOrg.addPerson({person: new mongoose.Types.ObjectId()});
|
|
1120
|
+
|
|
1121
|
+
Organization.upsert(littleDirtyOrg, 'test-user', function (err, result) {
|
|
1122
|
+
should.not.exist(err);
|
|
1123
|
+
should.exist(result);
|
|
1124
|
+
result.people.length.should.equal(3);
|
|
1125
|
+
return done();
|
|
1126
|
+
});
|
|
1112
1127
|
|
|
1113
|
-
Organization.upsert(littleDirtyOrg, 'test-user', function(err, result) {
|
|
1114
|
-
should.not.exist(err);
|
|
1115
|
-
should.exist(result);
|
|
1116
|
-
result.people.length.should.equal(3);
|
|
1117
|
-
return done();
|
|
1118
1128
|
});
|
|
1119
1129
|
|
|
1120
1130
|
});
|