@dhyasama/totem-merge 6.0.2 → 6.2.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/index.js +15 -14
- package/lib/helpers.js +1 -1
- package/lib/organizations.js +14 -15
- package/lib/people.js +16 -13
- package/package.json +5 -10
- package/test/config.js +1 -1
- package/test/index.js +189 -98
package/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _ = require('underscore');
|
|
3
4
|
var organizations = require('./lib/organizations');
|
|
4
5
|
var people = require('./lib/people');
|
|
5
6
|
var Logger = require('@dhyasama/totem-logger');
|
|
@@ -38,24 +39,24 @@ var Merge = function(mongoose, config) {
|
|
|
38
39
|
|
|
39
40
|
//////////////////////////////////////////////
|
|
40
41
|
|
|
41
|
-
Merge.prototype.organizations = function(target, source, user,
|
|
42
|
-
organizations.merge(this, target, source, user,
|
|
42
|
+
Merge.prototype.organizations = function(target, source, user, cb) {
|
|
43
|
+
organizations.merge(this, target, source, user, cb);
|
|
43
44
|
};
|
|
44
45
|
|
|
45
|
-
Merge.prototype.organizationsById = function(targetId, sourceId, user,
|
|
46
|
+
Merge.prototype.organizationsById = function(targetId, sourceId, user, cb) {
|
|
46
47
|
|
|
47
48
|
var self = this;
|
|
48
49
|
|
|
49
50
|
self.logger.writeToInfoLog('Merge org ' + sourceId + ' into ' + targetId);
|
|
50
51
|
|
|
51
|
-
self.Organization.
|
|
52
|
+
self.Organization.getByIdAsGlobal(targetId, {}, function(err, target) {
|
|
52
53
|
|
|
53
54
|
if (err) { return cb(err, null); }
|
|
54
55
|
else if (!target) { return cb(new Error('target not found'), null); }
|
|
55
56
|
|
|
56
57
|
self.logger.writeToInfoLog(' Found target ' + target.name);
|
|
57
58
|
|
|
58
|
-
self.Organization.
|
|
59
|
+
self.Organization.getByIdAsGlobal(sourceId, {}, function(err, source) {
|
|
59
60
|
|
|
60
61
|
if (err) { return cb(err, null); }
|
|
61
62
|
else if (!source) { return cb(new Error('source not found'), null); }
|
|
@@ -63,7 +64,7 @@ Merge.prototype.organizationsById = function(targetId, sourceId, user, customerI
|
|
|
63
64
|
self.logger.writeToInfoLog(' Found source ' + source.name);
|
|
64
65
|
self.logger.writeToInfoLog(' Merging...');
|
|
65
66
|
|
|
66
|
-
organizations.merge(self, target, source, user,
|
|
67
|
+
organizations.merge(self, target, source, user, cb);
|
|
67
68
|
|
|
68
69
|
});
|
|
69
70
|
|
|
@@ -71,34 +72,34 @@ Merge.prototype.organizationsById = function(targetId, sourceId, user, customerI
|
|
|
71
72
|
|
|
72
73
|
};
|
|
73
74
|
|
|
74
|
-
Merge.prototype.people = function(target, source, user,
|
|
75
|
-
people.merge(this, target, source, user,
|
|
75
|
+
Merge.prototype.people = function(target, source, user, cb) {
|
|
76
|
+
people.merge(this, target, source, user, cb);
|
|
76
77
|
};
|
|
77
78
|
|
|
78
|
-
Merge.prototype.peopleById = function(targetId, sourceId, user,
|
|
79
|
+
Merge.prototype.peopleById = function(targetId, sourceId, user, cb) {
|
|
79
80
|
|
|
80
81
|
var self = this;
|
|
81
82
|
|
|
82
83
|
self.logger.writeToInfoLog('Merge person ' + sourceId + ' into ' + targetId);
|
|
83
84
|
|
|
84
|
-
self.Person.
|
|
85
|
+
self.Person.getByIdAsGlobal(targetId, {}, function(err, target) {
|
|
85
86
|
|
|
86
87
|
if (err) { return cb(err, null); }
|
|
87
88
|
else if (!target) { return cb(new Error('target not found'), null); }
|
|
88
89
|
|
|
89
90
|
console.log(' Found target', target.name.full);
|
|
90
|
-
console.log(' Target sources:', target.sources
|
|
91
|
+
console.log(' Target sources:', target.sources);
|
|
91
92
|
|
|
92
|
-
self.Person.
|
|
93
|
+
self.Person.getByIdAsGlobal(sourceId, {}, function(err, source) {
|
|
93
94
|
|
|
94
95
|
if (err) { return cb(err, null); }
|
|
95
96
|
else if (!source) { return cb(new Error('source not found'), null); }
|
|
96
97
|
|
|
97
98
|
self.logger.writeToInfoLog(' Found source ' + source.name.full);
|
|
98
|
-
self.logger.writeToInfoLog(' Source sources ' + source.sources
|
|
99
|
+
self.logger.writeToInfoLog(' Source sources ' + source.sources);
|
|
99
100
|
self.logger.writeToInfoLog(' Merging...');
|
|
100
101
|
|
|
101
|
-
people.merge(self, target, source, user,
|
|
102
|
+
people.merge(self, target, source, user, cb);
|
|
102
103
|
|
|
103
104
|
});
|
|
104
105
|
|
package/lib/helpers.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _ = require('underscore');
|
|
4
|
-
var utilities = require('@dhyasama/
|
|
4
|
+
var utilities = require('@dhyasama/ffvc-utilities');
|
|
5
5
|
var phoneFormatter = require('phone-formatter');
|
|
6
6
|
|
|
7
7
|
var createSnapshot = module.exports.createSnapshot = function createSnapshot(context, collectionName, doc, createdBy, cb) {
|
package/lib/organizations.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
let logger;
|
|
3
|
+
var async = require('async');
|
|
4
|
+
var _ = require('underscore');
|
|
5
|
+
var helpers = require('./helpers');
|
|
6
|
+
var ObjectId = require('mongodb').ObjectID;
|
|
7
|
+
var logger;
|
|
9
8
|
|
|
10
|
-
var merge = function merge(context, target, source, mergedBy,
|
|
9
|
+
var merge = function merge(context, target, source, mergedBy, cb) {
|
|
11
10
|
|
|
12
11
|
logger = context.logger;
|
|
13
12
|
|
|
@@ -37,7 +36,7 @@ var merge = function merge(context, target, source, mergedBy, customerId, cb) {
|
|
|
37
36
|
var url = 'https://admin.ffvc.com/orgs/' + source.id;
|
|
38
37
|
var text = 'This org should be merged with ' + url;
|
|
39
38
|
|
|
40
|
-
context.Organization.addFlag(target._id, target._id, text,
|
|
39
|
+
context.Organization.addFlag(target._id, target._id, text, function(err, result) {
|
|
41
40
|
if (err) return cb(err, null);
|
|
42
41
|
return cb(null, result);
|
|
43
42
|
});
|
|
@@ -70,7 +69,7 @@ var merge = function merge(context, target, source, mergedBy, customerId, cb) {
|
|
|
70
69
|
saveOrganization.bind(null, target, username),
|
|
71
70
|
|
|
72
71
|
// Change source references to target
|
|
73
|
-
updateReferences.bind(null, context, target, source, mergedBy
|
|
72
|
+
updateReferences.bind(null, context, target, source, mergedBy)
|
|
74
73
|
|
|
75
74
|
], function(err, results) {
|
|
76
75
|
|
|
@@ -148,7 +147,7 @@ var verifyOkToMerge = function verifyOkToMerge(target, source, cb) {
|
|
|
148
147
|
|
|
149
148
|
};
|
|
150
149
|
|
|
151
|
-
var updateReferences = function updateReferences(context, target, source, mergedBy,
|
|
150
|
+
var updateReferences = function updateReferences(context, target, source, mergedBy, cb) {
|
|
152
151
|
|
|
153
152
|
logger.writeToInfoLog('Update references...');
|
|
154
153
|
|
|
@@ -161,8 +160,8 @@ var updateReferences = function updateReferences(context, target, source, merged
|
|
|
161
160
|
var oldOrgId = ObjectId(source.id);
|
|
162
161
|
var newOrgId = ObjectId(target.id);
|
|
163
162
|
|
|
164
|
-
logger.writeToInfoLog(' Target:
|
|
165
|
-
logger.writeToInfoLog(' Source:
|
|
163
|
+
logger.writeToInfoLog(' Target:', newOrgId);
|
|
164
|
+
logger.writeToInfoLog(' Source:', oldOrgId);
|
|
166
165
|
|
|
167
166
|
// mergedBy can be either an account or a username
|
|
168
167
|
var username = mergedBy.username ? mergedBy.username : mergedBy;
|
|
@@ -171,7 +170,7 @@ var updateReferences = function updateReferences(context, target, source, merged
|
|
|
171
170
|
// and get cleaned and updated on each pull anyway
|
|
172
171
|
|
|
173
172
|
async.parallel([
|
|
174
|
-
updateDeals.bind(context, newOrgId, oldOrgId, mergedBy
|
|
173
|
+
updateDeals.bind(context, newOrgId, oldOrgId, mergedBy),
|
|
175
174
|
updateLists.bind(context, newOrgId, oldOrgId, username),
|
|
176
175
|
updateMessages.bind(context, newOrgId, oldOrgId, username),
|
|
177
176
|
updateNews.bind(context, newOrgId, oldOrgId, username),
|
|
@@ -180,7 +179,7 @@ var updateReferences = function updateReferences(context, target, source, merged
|
|
|
180
179
|
|
|
181
180
|
};
|
|
182
181
|
|
|
183
|
-
var updateDeals = function updateDeals(newOrgId, oldOrgId, user,
|
|
182
|
+
var updateDeals = function updateDeals(newOrgId, oldOrgId, user, cb) {
|
|
184
183
|
|
|
185
184
|
logger.writeToInfoLog(' Updating deals...');
|
|
186
185
|
|
|
@@ -205,7 +204,7 @@ var updateDeals = function updateDeals(newOrgId, oldOrgId, user, customerId, cb)
|
|
|
205
204
|
logger.writeToInfoLog(' Found ' + tasks.length + ' deal references to update');
|
|
206
205
|
|
|
207
206
|
var queue = async.queue(function(task, callback) {
|
|
208
|
-
self.Deal.modifyById(task.id, task.update, {
|
|
207
|
+
self.Deal.modifyById(task.id, task.update, {}, function(err, result) {
|
|
209
208
|
if (err) { return callback(err, null); }
|
|
210
209
|
else if (result) { updated.push(result); }
|
|
211
210
|
return callback(null, result);
|
package/lib/people.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
let ObjectId = mongoose.Types.ObjectId;
|
|
3
|
+
var async = require('async');
|
|
4
|
+
var _ = require('underscore');
|
|
5
|
+
var helpers = require('./helpers');
|
|
6
|
+
var ObjectId = require('mongodb').ObjectID;
|
|
8
7
|
|
|
9
|
-
var merge = function merge(context, target, source, mergedBy,
|
|
8
|
+
var merge = function merge(context, target, source, mergedBy, cb) {
|
|
10
9
|
|
|
11
10
|
console.log('Merging people...');
|
|
12
11
|
|
|
@@ -21,6 +20,9 @@ var merge = function merge(context, target, source, mergedBy, customerId, cb) {
|
|
|
21
20
|
|
|
22
21
|
console.log('Saving target person...');
|
|
23
22
|
console.log(' ID:', person._id.toString());
|
|
23
|
+
console.log(' LinkedIn:', person.social.linkedin);
|
|
24
|
+
console.log(' Twitter:', person.social.twitter);
|
|
25
|
+
console.log(' Email:', person.contact.email);
|
|
24
26
|
|
|
25
27
|
context.Person.upsert(person, username, function(err, result) {
|
|
26
28
|
return callback(err, result);
|
|
@@ -33,7 +35,7 @@ var merge = function merge(context, target, source, mergedBy, customerId, cb) {
|
|
|
33
35
|
var url = 'https://admin.totemvc.com/people/' + source.id;
|
|
34
36
|
var text = 'This person should be merged with ' + url;
|
|
35
37
|
|
|
36
|
-
context.Person.addFlag(target._id, target._id, text,
|
|
38
|
+
context.Person.addFlag(target._id, target._id, text, function(err, result) {
|
|
37
39
|
if (err) return cb(err, null);
|
|
38
40
|
return cb(null, result);
|
|
39
41
|
});
|
|
@@ -107,7 +109,7 @@ var mergeSourceIntoTarget = function mergeEntities(target, source, cb) {
|
|
|
107
109
|
_.each(sourceSources, function(sourceSource) {
|
|
108
110
|
|
|
109
111
|
var match = _.find(targetSources, function(targetSource) {
|
|
110
|
-
return targetSource.customer.toString() === sourceSource.customer.toString() && targetSource.person.toString() === sourceSource.person.toString();
|
|
112
|
+
return sourceSource.customer && sourceSource.person && targetSource.customer && targetSource.person && targetSource.customer.toString() === sourceSource.customer.toString() && targetSource.person.toString() === sourceSource.person.toString();
|
|
111
113
|
});
|
|
112
114
|
|
|
113
115
|
if (!match) { targetSources.push(sourceSource); }
|
|
@@ -147,6 +149,7 @@ var updateReferences = function updateReferences(context, target, source, merged
|
|
|
147
149
|
|
|
148
150
|
console.log('Updating references...');
|
|
149
151
|
|
|
152
|
+
|
|
150
153
|
// validate parameters
|
|
151
154
|
if (!context) return cb(new Error('context is required'), null);
|
|
152
155
|
if (!target) return cb(new Error('target is required'), null);
|
|
@@ -156,8 +159,8 @@ var updateReferences = function updateReferences(context, target, source, merged
|
|
|
156
159
|
var oldPersonId = ObjectId(source.id);
|
|
157
160
|
var newPersonId = ObjectId(target.id);
|
|
158
161
|
|
|
159
|
-
console.log(' Target:', newPersonId
|
|
160
|
-
console.log(' Source:', oldPersonId
|
|
162
|
+
console.log(' Target:', newPersonId);
|
|
163
|
+
console.log(' Source:', oldPersonId);
|
|
161
164
|
|
|
162
165
|
// mergedBy can be either an account or a username
|
|
163
166
|
var username = mergedBy.username ? mergedBy.username : mergedBy;
|
|
@@ -223,7 +226,7 @@ var updateDeals = function updateDeals(newPersonId, oldPersonId, user, cb) {
|
|
|
223
226
|
console.log(' Found ' + tasks.length + ' deal references to update');
|
|
224
227
|
|
|
225
228
|
var queue = async.queue(function(task, callback) {
|
|
226
|
-
self.Deal.modifyById(task.id, task.update, function(err, result) {
|
|
229
|
+
self.Deal.modifyById(task.id, task.update, {}, function(err, result) {
|
|
227
230
|
if (err) { return callback(err, null); }
|
|
228
231
|
else if (result) { updated.push(result); }
|
|
229
232
|
return callback(null, result);
|
|
@@ -270,7 +273,7 @@ var updateDocuments = function updateDocuments(newPersonId, oldPersonId, user, c
|
|
|
270
273
|
console.log(' Found ' + tasks.length + ' doc references to update');
|
|
271
274
|
|
|
272
275
|
var queue = async.queue(function(task, callback) {
|
|
273
|
-
self.Document.modifyById(task.id, task.update, function(err, result) {
|
|
276
|
+
self.Document.modifyById(task.id, task.update, {}, function(err, result) {
|
|
274
277
|
if (err) { return callback(err, null); }
|
|
275
278
|
else if (result) { updated.push(result); }
|
|
276
279
|
return callback(null, result);
|
|
@@ -575,7 +578,7 @@ var updateNotes = function updateNotes(newPersonId, oldPersonId, user, cb) {
|
|
|
575
578
|
console.log(' Found ' + tasks.length + ' note references to update');
|
|
576
579
|
|
|
577
580
|
var queue = async.queue(function(task, callback) {
|
|
578
|
-
self.Note.modifyById(task.id, task.update, function(err, result) {
|
|
581
|
+
self.Note.modifyById(task.id, task.update, {}, function(err, result) {
|
|
579
582
|
if (err) { return callback(err, null); }
|
|
580
583
|
else if (result) { updated.push(result); }
|
|
581
584
|
return callback(null, result);
|
package/package.json
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dhyasama/totem-merge",
|
|
3
|
-
"version": "6.0
|
|
4
|
-
"license": "UNLICENSED",
|
|
3
|
+
"version": "6.2.0",
|
|
5
4
|
"description": "Org and person merging package",
|
|
6
5
|
"main": "index.js",
|
|
7
|
-
"engines": {
|
|
8
|
-
"node": "12.13.1"
|
|
9
|
-
},
|
|
10
6
|
"scripts": {
|
|
11
7
|
"prestart": "node ./lib/changeBSON",
|
|
12
8
|
"start": "NODE_ENV=test node ./cli",
|
|
@@ -17,16 +13,15 @@
|
|
|
17
13
|
},
|
|
18
14
|
"author": "Jason Reynolds",
|
|
19
15
|
"dependencies": {
|
|
20
|
-
"@dhyasama/totem-logger": "^2.0
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"commander": "^2.20.3",
|
|
16
|
+
"@dhyasama/totem-logger": "^1.2.0",
|
|
17
|
+
"async": "^2.0.0-rc.3",
|
|
18
|
+
"commander": "^2.14.1",
|
|
24
19
|
"mongoose": "~4.5.7",
|
|
25
20
|
"phone-formatter": "0.0.2",
|
|
26
21
|
"underscore": "^1.8.3"
|
|
27
22
|
},
|
|
28
23
|
"devDependencies": {
|
|
29
|
-
"@dhyasama/totem-models": "^
|
|
24
|
+
"@dhyasama/totem-models": "^6.0.0",
|
|
30
25
|
"mocha": "^5.2.0",
|
|
31
26
|
"mocha-mongoose": "^1.1.1",
|
|
32
27
|
"should": "^8.2.2"
|
package/test/config.js
CHANGED
|
@@ -7,7 +7,7 @@ module.exports = {
|
|
|
7
7
|
LPS_ENABLED: false,
|
|
8
8
|
|
|
9
9
|
db: {
|
|
10
|
-
uri: 'mongodb://
|
|
10
|
+
uri: 'mongodb://ffvc:ytnn5m7A9snIJSOLRqwo7Bpo2QkyYx6q@ds043952.mongolab.com:43952/ff-platform-test'
|
|
11
11
|
},
|
|
12
12
|
|
|
13
13
|
crypto: {
|
package/test/index.js
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var config = require('./config');
|
|
4
|
-
var dbUri = config.db.uri;
|
|
5
|
-
|
|
6
|
-
if (dbUri.indexOf('@test-shard-') === -1) {
|
|
7
|
-
console.log('Not a test db. Quitting...');
|
|
8
|
-
process.exit();
|
|
9
|
-
}
|
|
10
|
-
|
|
11
3
|
var should = require("should");
|
|
12
4
|
var mongoose = require('mongoose');
|
|
5
|
+
var config = require('./config');
|
|
13
6
|
var models = require('@dhyasama/totem-models')(mongoose, config);
|
|
14
7
|
var clearDB = require('mocha-mongoose')(config.db.uri, {noClear: true});
|
|
15
8
|
var Merge = require('../index.js');
|
|
@@ -39,34 +32,9 @@ describe('Merge', function() {
|
|
|
39
32
|
clearDB(done);
|
|
40
33
|
});
|
|
41
34
|
|
|
42
|
-
// Customer prep
|
|
43
|
-
before(function(done) {
|
|
44
|
-
|
|
45
|
-
customer = new Organization();
|
|
46
|
-
customer.name = 'HUGE VC';
|
|
47
|
-
customer.slug = 'huge-vc';
|
|
48
|
-
|
|
49
|
-
Organization.upsert(customer, 'test', function(err, result) {
|
|
50
|
-
|
|
51
|
-
should.not.exist(err);
|
|
52
|
-
should.exist(result);
|
|
53
|
-
|
|
54
|
-
customer = result;
|
|
55
|
-
|
|
56
|
-
return done();
|
|
57
|
-
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
});
|
|
61
|
-
|
|
62
35
|
// People prep
|
|
63
36
|
before(function(done) {
|
|
64
37
|
|
|
65
|
-
var p3 = new Person();
|
|
66
|
-
p3.name.first = 'Toni';
|
|
67
|
-
p3.name.last = 'Braxton';
|
|
68
|
-
p3.slug = 'toni-braxton';
|
|
69
|
-
|
|
70
38
|
var p1 = new Person();
|
|
71
39
|
p1.name.first = 'George';
|
|
72
40
|
p1.name.last = 'Miller';
|
|
@@ -74,8 +42,8 @@ describe('Merge', function() {
|
|
|
74
42
|
p1.bio = 'Hello World!';
|
|
75
43
|
p1.aliases.push('G-Money');
|
|
76
44
|
p1.sources.push({
|
|
77
|
-
person:
|
|
78
|
-
customer:
|
|
45
|
+
person: new mongoose.Types.ObjectId(),
|
|
46
|
+
customer: config.CUSTOMER_ID
|
|
79
47
|
});
|
|
80
48
|
|
|
81
49
|
var p2 = new Person();
|
|
@@ -84,6 +52,11 @@ describe('Merge', function() {
|
|
|
84
52
|
p2.slug = 'braxton-miller';
|
|
85
53
|
p2.sources.push(p1.sources[0]);
|
|
86
54
|
|
|
55
|
+
var p3 = new Person();
|
|
56
|
+
p3.name.first = 'Toni';
|
|
57
|
+
p3.name.last = 'Braxton';
|
|
58
|
+
p3.slug = 'toni-braxton';
|
|
59
|
+
|
|
87
60
|
Person.upsert(p1, 'test', function(err, newPerson1) {
|
|
88
61
|
|
|
89
62
|
should.not.exist(err);
|
|
@@ -180,7 +153,7 @@ describe('Merge', function() {
|
|
|
180
153
|
should.exist(newOrg1);
|
|
181
154
|
|
|
182
155
|
// getbyid to populate investedIn
|
|
183
|
-
Organization.getById(newOrg1.id, {
|
|
156
|
+
Organization.getById(newOrg1.id, { role: 'none' }, function(err, result1) {
|
|
184
157
|
|
|
185
158
|
should.not.exist(err);
|
|
186
159
|
should.exist(result1);
|
|
@@ -192,7 +165,7 @@ describe('Merge', function() {
|
|
|
192
165
|
should.not.exist(err);
|
|
193
166
|
should.exist(newOrg2);
|
|
194
167
|
|
|
195
|
-
Organization.getById(newOrg2.id, {
|
|
168
|
+
Organization.getById(newOrg2.id, { role: 'none' }, function(err, result2) {
|
|
196
169
|
|
|
197
170
|
should.not.exist(err);
|
|
198
171
|
should.exist(result2);
|
|
@@ -204,7 +177,7 @@ describe('Merge', function() {
|
|
|
204
177
|
should.not.exist(err);
|
|
205
178
|
should.exist(newOrg3);
|
|
206
179
|
|
|
207
|
-
Organization.getById(newOrg3.id, {
|
|
180
|
+
Organization.getById(newOrg3.id, { role: 'none' }, function(err, result3) {
|
|
208
181
|
|
|
209
182
|
should.not.exist(err);
|
|
210
183
|
should.exist(result3);
|
|
@@ -216,7 +189,7 @@ describe('Merge', function() {
|
|
|
216
189
|
should.not.exist(err);
|
|
217
190
|
should.exist(newOrg4);
|
|
218
191
|
|
|
219
|
-
Organization.getById(newOrg4.id, {
|
|
192
|
+
Organization.getById(newOrg4.id, { role: 'none' }, function(err, result4) {
|
|
220
193
|
|
|
221
194
|
should.not.exist(err);
|
|
222
195
|
should.exist(result4);
|
|
@@ -228,7 +201,7 @@ describe('Merge', function() {
|
|
|
228
201
|
should.not.exist(err);
|
|
229
202
|
should.exist(newOrg5);
|
|
230
203
|
|
|
231
|
-
Organization.getById(newOrg5.id, {
|
|
204
|
+
Organization.getById(newOrg5.id, { role: 'none' }, function(err, result5) {
|
|
232
205
|
|
|
233
206
|
should.not.exist(err);
|
|
234
207
|
should.exist(result5);
|
|
@@ -240,7 +213,7 @@ describe('Merge', function() {
|
|
|
240
213
|
should.not.exist(err);
|
|
241
214
|
should.exist(newOrg6);
|
|
242
215
|
|
|
243
|
-
Organization.getById(newOrg6.id, {
|
|
216
|
+
Organization.getById(newOrg6.id, { role: 'none' }, function(err, result6) {
|
|
244
217
|
|
|
245
218
|
should.not.exist(err);
|
|
246
219
|
should.exist(result6);
|
|
@@ -278,7 +251,7 @@ describe('Merge', function() {
|
|
|
278
251
|
// List prep
|
|
279
252
|
before(function(done) {
|
|
280
253
|
|
|
281
|
-
List.createList('Test List', { organizations:[org1], people: [person1] }, person1,
|
|
254
|
+
List.createList('Test List', { organizations:[org1], people: [person1] }, person1, function(err, list) {
|
|
282
255
|
should.not.exist(err);
|
|
283
256
|
should.exist(list);
|
|
284
257
|
return done();
|
|
@@ -311,7 +284,7 @@ describe('Merge', function() {
|
|
|
311
284
|
var interaction = new Interaction({
|
|
312
285
|
calendarEventId: new mongoose.Types.ObjectId(),
|
|
313
286
|
providerEventId: 'ABC123',
|
|
314
|
-
totemCustomerId:
|
|
287
|
+
totemCustomerId: config.CUSTOMER_ID,
|
|
315
288
|
summary: 'Test',
|
|
316
289
|
startTime: new Date(),
|
|
317
290
|
recurring: false,
|
|
@@ -329,6 +302,28 @@ describe('Merge', function() {
|
|
|
329
302
|
|
|
330
303
|
});
|
|
331
304
|
|
|
305
|
+
// Customer prep
|
|
306
|
+
before(function(done) {
|
|
307
|
+
|
|
308
|
+
customer = new Organization();
|
|
309
|
+
customer.name = 'HUGE VC';
|
|
310
|
+
customer.slug = 'huge-vc';
|
|
311
|
+
|
|
312
|
+
Organization.upsert(customer, 'test', function(err, result) {
|
|
313
|
+
|
|
314
|
+
should.not.exist(err);
|
|
315
|
+
should.exist(result);
|
|
316
|
+
|
|
317
|
+
customer = result;
|
|
318
|
+
|
|
319
|
+
config.CUSTOMER_ID = customer._id.toString();
|
|
320
|
+
|
|
321
|
+
return done();
|
|
322
|
+
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
});
|
|
326
|
+
|
|
332
327
|
describe('Orgs', function() {
|
|
333
328
|
|
|
334
329
|
it('Flags organization to be merged', function (done) {
|
|
@@ -336,7 +331,7 @@ describe('Merge', function() {
|
|
|
336
331
|
config.flag = true;
|
|
337
332
|
merge = new Merge(mongoose, config);
|
|
338
333
|
|
|
339
|
-
merge.organizations(org2, org1, 'testy',
|
|
334
|
+
merge.organizations(org2, org1, 'testy', function(err, result) {
|
|
340
335
|
should.not.exist(err);
|
|
341
336
|
should.exist(result);
|
|
342
337
|
result.addedTo.flags.length.should.equal(1);
|
|
@@ -358,7 +353,7 @@ describe('Merge', function() {
|
|
|
358
353
|
should.not.exist(err);
|
|
359
354
|
should.exist(result);
|
|
360
355
|
|
|
361
|
-
merge.organizationsById(org2._id, org1._id, 'testy',
|
|
356
|
+
merge.organizationsById(org2._id, org1._id, 'testy', function(err, result) {
|
|
362
357
|
|
|
363
358
|
should.not.exist(err);
|
|
364
359
|
should.exist(result);
|
|
@@ -417,7 +412,7 @@ describe('Merge', function() {
|
|
|
417
412
|
should.not.exist(err);
|
|
418
413
|
should.exist(result);
|
|
419
414
|
|
|
420
|
-
merge.organizationsById(org5._id, org4._id, 'testy',
|
|
415
|
+
merge.organizationsById(org5._id, org4._id, 'testy', function(err, result) {
|
|
421
416
|
should.not.exist(err);
|
|
422
417
|
should.exist(result);
|
|
423
418
|
result.people.length.should.equal(2);
|
|
@@ -436,9 +431,11 @@ describe('Merge', function() {
|
|
|
436
431
|
config.flag = false;
|
|
437
432
|
merge = new Merge(mongoose, config);
|
|
438
433
|
|
|
434
|
+
var pid = new mongoose.Types.ObjectId();
|
|
435
|
+
|
|
439
436
|
org2.people = [];
|
|
440
437
|
org2.people.push({
|
|
441
|
-
person:
|
|
438
|
+
person: pid,
|
|
442
439
|
roles: [{
|
|
443
440
|
role: 'test 1'
|
|
444
441
|
}]
|
|
@@ -446,7 +443,7 @@ describe('Merge', function() {
|
|
|
446
443
|
|
|
447
444
|
org5.people = [];
|
|
448
445
|
org5.people.push({
|
|
449
|
-
person:
|
|
446
|
+
person: pid,
|
|
450
447
|
roles: [{
|
|
451
448
|
role: 'test 2'
|
|
452
449
|
}]
|
|
@@ -466,7 +463,7 @@ describe('Merge', function() {
|
|
|
466
463
|
|
|
467
464
|
org5 = result;
|
|
468
465
|
|
|
469
|
-
merge.organizationsById(org5._id, org2._id, 'testy',
|
|
466
|
+
merge.organizationsById(org5._id, org2._id, 'testy', function(err, result) {
|
|
470
467
|
should.not.exist(err);
|
|
471
468
|
should.exist(result);
|
|
472
469
|
result.people.length.should.equal(1);
|
|
@@ -491,19 +488,19 @@ describe('Merge', function() {
|
|
|
491
488
|
stage: 'New'
|
|
492
489
|
});
|
|
493
490
|
|
|
494
|
-
Deal.upsert(deal,
|
|
491
|
+
Deal.upsert(deal, new mongoose.Types.ObjectId(), function(err, result1) {
|
|
495
492
|
|
|
496
493
|
should.not.exist(err);
|
|
497
494
|
should.exist(result1);
|
|
498
495
|
|
|
499
|
-
merge.organizationsById(org6._id, org5._id, new mongoose.Types.ObjectId(),
|
|
496
|
+
merge.organizationsById(org6._id, org5._id, new mongoose.Types.ObjectId(), function(err, result2) {
|
|
500
497
|
|
|
501
498
|
should.not.exist(err);
|
|
502
499
|
should.exist(result2);
|
|
503
500
|
|
|
504
501
|
org6 = result2;
|
|
505
502
|
|
|
506
|
-
Deal.getById(deal.id,
|
|
503
|
+
Deal.getById(deal.id, function(err, result3) {
|
|
507
504
|
|
|
508
505
|
should.not.exist(err);
|
|
509
506
|
should.exist(result3);
|
|
@@ -539,14 +536,14 @@ describe('Merge', function() {
|
|
|
539
536
|
should.not.exist(err);
|
|
540
537
|
should.exist(result1);
|
|
541
538
|
|
|
542
|
-
merge.organizationsById(org6._id, org3._id, new mongoose.Types.ObjectId(),
|
|
539
|
+
merge.organizationsById(org6._id, org3._id, new mongoose.Types.ObjectId(), function(err, result2) {
|
|
543
540
|
|
|
544
541
|
should.not.exist(err);
|
|
545
542
|
should.exist(result2);
|
|
546
543
|
|
|
547
544
|
org6 = result2;
|
|
548
545
|
|
|
549
|
-
List.getById(list.id,
|
|
546
|
+
List.getById(list.id, function(err, result3) {
|
|
550
547
|
|
|
551
548
|
should.not.exist(err);
|
|
552
549
|
should.exist(result3);
|
|
@@ -595,14 +592,14 @@ describe('Merge', function() {
|
|
|
595
592
|
should.not.exist(err);
|
|
596
593
|
should.exist(result1);
|
|
597
594
|
|
|
598
|
-
merge.organizationsById(org6._id, newOrg._id, new mongoose.Types.ObjectId(),
|
|
595
|
+
merge.organizationsById(org6._id, newOrg._id, new mongoose.Types.ObjectId(), function(err, result2) {
|
|
599
596
|
|
|
600
597
|
should.not.exist(err);
|
|
601
598
|
should.exist(result2);
|
|
602
599
|
|
|
603
600
|
org6 = result2;
|
|
604
601
|
|
|
605
|
-
Message.getById(message.id,
|
|
602
|
+
Message.getById(message.id, function(err, result3) {
|
|
606
603
|
|
|
607
604
|
should.not.exist(err);
|
|
608
605
|
should.exist(result3);
|
|
@@ -649,19 +646,19 @@ describe('Merge', function() {
|
|
|
649
646
|
should.not.exist(err);
|
|
650
647
|
should.exist(result1);
|
|
651
648
|
|
|
652
|
-
merge.organizationsById(org6._id, newOrg._id, new mongoose.Types.ObjectId(),
|
|
649
|
+
merge.organizationsById(org6._id, newOrg._id, new mongoose.Types.ObjectId(), function(err, result2) {
|
|
653
650
|
|
|
654
651
|
should.not.exist(err);
|
|
655
652
|
should.exist(result2);
|
|
656
653
|
|
|
657
654
|
org6 = result2;
|
|
658
655
|
|
|
659
|
-
News.
|
|
656
|
+
News.getById(news.id, function(err, result3) {
|
|
660
657
|
|
|
661
658
|
should.not.exist(err);
|
|
662
659
|
should.exist(result3);
|
|
663
660
|
|
|
664
|
-
result3.org.toString().should.equal(org6._id.toString());
|
|
661
|
+
result3.org._id.toString().should.equal(org6._id.toString());
|
|
665
662
|
|
|
666
663
|
return done();
|
|
667
664
|
|
|
@@ -696,7 +693,7 @@ describe('Merge', function() {
|
|
|
696
693
|
should.not.exist(err);
|
|
697
694
|
should.exist(result);
|
|
698
695
|
|
|
699
|
-
merge.organizationsById(org6._id, newOrg._id, 'testy',
|
|
696
|
+
merge.organizationsById(org6._id, newOrg._id, 'testy', function(err, result) {
|
|
700
697
|
should.exist(err);
|
|
701
698
|
should.not.exist(result);
|
|
702
699
|
return done();
|
|
@@ -717,7 +714,7 @@ describe('Merge', function() {
|
|
|
717
714
|
config.flag = true;
|
|
718
715
|
merge = new Merge(mongoose, config);
|
|
719
716
|
|
|
720
|
-
merge.people(person2, person1, 'testy',
|
|
717
|
+
merge.people(person2, person1, 'testy', function(err, result) {
|
|
721
718
|
should.not.exist(err);
|
|
722
719
|
should.exist(result);
|
|
723
720
|
result.addedTo.flags.length.should.equal(1);
|
|
@@ -732,7 +729,9 @@ describe('Merge', function() {
|
|
|
732
729
|
config.flag = false;
|
|
733
730
|
merge = new Merge(mongoose, config);
|
|
734
731
|
|
|
735
|
-
|
|
732
|
+
config.CUSTOMER_ID = 'GLOBAL_PROCESS';
|
|
733
|
+
|
|
734
|
+
merge.peopleById(person2.id, person1.id, 'testy', function(err, result) {
|
|
736
735
|
|
|
737
736
|
should.not.exist(err);
|
|
738
737
|
should.exist(result);
|
|
@@ -742,7 +741,12 @@ describe('Merge', function() {
|
|
|
742
741
|
result.aliases.should.containEql(person1.name.full);
|
|
743
742
|
result.sources.length.should.equal(1);
|
|
744
743
|
|
|
745
|
-
|
|
744
|
+
List.getByPerson(person1, function(err, result) {
|
|
745
|
+
should.not.exist(err);
|
|
746
|
+
should.exist(result);
|
|
747
|
+
result.length.should.equal(0);
|
|
748
|
+
return done();
|
|
749
|
+
});
|
|
746
750
|
|
|
747
751
|
});
|
|
748
752
|
|
|
@@ -754,7 +758,7 @@ describe('Merge', function() {
|
|
|
754
758
|
config.flag = false;
|
|
755
759
|
merge = new Merge(mongoose, config);
|
|
756
760
|
|
|
757
|
-
Person.getById(person2._id,
|
|
761
|
+
Person.getById(person2._id, function(err, result) {
|
|
758
762
|
|
|
759
763
|
should.not.exist(err);
|
|
760
764
|
should.exist(result);
|
|
@@ -789,7 +793,7 @@ describe('Merge', function() {
|
|
|
789
793
|
should.exist(result);
|
|
790
794
|
newPerson = result;
|
|
791
795
|
|
|
792
|
-
merge.peopleById(person2.id, newPerson.id, 'testy',
|
|
796
|
+
merge.peopleById(person2.id, newPerson.id, 'testy', function(err, result) {
|
|
793
797
|
should.not.exist(err);
|
|
794
798
|
should.exist(result);
|
|
795
799
|
result.contact.phone.length.should.equal(2);
|
|
@@ -806,7 +810,7 @@ describe('Merge', function() {
|
|
|
806
810
|
|
|
807
811
|
it('Merges people with same phone number', function (done) {
|
|
808
812
|
|
|
809
|
-
Person.getById(person2._id,
|
|
813
|
+
Person.getById(person2._id, function(err, result) {
|
|
810
814
|
|
|
811
815
|
should.not.exist(err);
|
|
812
816
|
should.exist(result);
|
|
@@ -841,7 +845,7 @@ describe('Merge', function() {
|
|
|
841
845
|
should.exist(result);
|
|
842
846
|
newPerson = result;
|
|
843
847
|
|
|
844
|
-
merge.peopleById(person2.id, newPerson.id, 'testy',
|
|
848
|
+
merge.peopleById(person2.id, newPerson.id, 'testy', function(err, result) {
|
|
845
849
|
should.not.exist(err);
|
|
846
850
|
should.exist(result);
|
|
847
851
|
result.contact.phone.length.should.equal(1);
|
|
@@ -862,6 +866,8 @@ describe('Merge', function() {
|
|
|
862
866
|
config.flag = false;
|
|
863
867
|
merge = new Merge(mongoose, config);
|
|
864
868
|
|
|
869
|
+
config.CUSTOMER_ID = 'GLOBAL_PROCESS';
|
|
870
|
+
|
|
865
871
|
var myNewPerson1 = new Person();
|
|
866
872
|
myNewPerson1.name = { first:'jason', last:'reynolds'};
|
|
867
873
|
myNewPerson1.slug = 'jason-reynolds';
|
|
@@ -892,12 +898,12 @@ describe('Merge', function() {
|
|
|
892
898
|
should.not.exist(err);
|
|
893
899
|
should.exist(result);
|
|
894
900
|
|
|
895
|
-
merge.peopleById(newPerson2.id, newPerson1.id, 'testy',
|
|
901
|
+
merge.peopleById(newPerson2.id, newPerson1.id, 'testy', function(err, merged) {
|
|
896
902
|
|
|
897
903
|
should.not.exist(err);
|
|
898
904
|
should.exist(merged);
|
|
899
905
|
|
|
900
|
-
Organization.getById(result.id, {
|
|
906
|
+
Organization.getById(result.id, { role: 'none' }, function(err, finalResult) {
|
|
901
907
|
|
|
902
908
|
should.not.exist(err);
|
|
903
909
|
should.exist(finalResult);
|
|
@@ -953,12 +959,12 @@ describe('Merge', function() {
|
|
|
953
959
|
result.people.length.should.equal(1);
|
|
954
960
|
result.people[0].person.toString().should.equal(newPerson1._id.toString()); // source
|
|
955
961
|
|
|
956
|
-
merge.peopleById(newPerson2.id, newPerson1.id, 'testy',
|
|
962
|
+
merge.peopleById(newPerson2.id, newPerson1.id, 'testy', function(err, merged) {
|
|
957
963
|
|
|
958
964
|
should.not.exist(err);
|
|
959
965
|
should.exist(merged);
|
|
960
966
|
|
|
961
|
-
Organization.getById(result.id, {
|
|
967
|
+
Organization.getById(result.id, { role: 'none' }, function(err, finalResult) {
|
|
962
968
|
|
|
963
969
|
should.not.exist(err);
|
|
964
970
|
should.exist(finalResult);
|
|
@@ -986,13 +992,17 @@ describe('Merge', function() {
|
|
|
986
992
|
config.flag = false;
|
|
987
993
|
merge = new Merge(mongoose, config);
|
|
988
994
|
|
|
995
|
+
var source1 = new mongoose.Types.ObjectId();
|
|
996
|
+
var source2 = new mongoose.Types.ObjectId();
|
|
997
|
+
var customer1 = new mongoose.Types.ObjectId();
|
|
998
|
+
|
|
989
999
|
var newPerson1 = new Person();
|
|
990
1000
|
newPerson1.name.first = 'New';
|
|
991
1001
|
newPerson1.name.last = 'Person';
|
|
992
1002
|
newPerson1.slug = 'new-person-1';
|
|
993
1003
|
newPerson1.sources = [{
|
|
994
|
-
person:
|
|
995
|
-
customer:
|
|
1004
|
+
person: source2,
|
|
1005
|
+
customer: customer1
|
|
996
1006
|
}];
|
|
997
1007
|
|
|
998
1008
|
var newPerson2 = new Person();
|
|
@@ -1000,8 +1010,8 @@ describe('Merge', function() {
|
|
|
1000
1010
|
newPerson2.name.last = 'Person';
|
|
1001
1011
|
newPerson2.slug = 'new-person-2';
|
|
1002
1012
|
newPerson2.sources = [{
|
|
1003
|
-
person:
|
|
1004
|
-
customer:
|
|
1013
|
+
person: source1,
|
|
1014
|
+
customer: customer1
|
|
1005
1015
|
}];
|
|
1006
1016
|
|
|
1007
1017
|
Person.upsert(newPerson1, 'test', function(err, result) {
|
|
@@ -1016,16 +1026,16 @@ describe('Merge', function() {
|
|
|
1016
1026
|
should.exist(result);
|
|
1017
1027
|
newPerson2 = result;
|
|
1018
1028
|
|
|
1019
|
-
merge.peopleById(newPerson2.id, newPerson1.id, 'testy',
|
|
1029
|
+
merge.peopleById(newPerson2.id, newPerson1.id, 'testy', function(err, result) {
|
|
1020
1030
|
|
|
1021
1031
|
should.not.exist(err);
|
|
1022
1032
|
should.exist(result);
|
|
1023
1033
|
|
|
1024
1034
|
result.sources.length.should.equal(2);
|
|
1025
|
-
result.sources[0].person.
|
|
1026
|
-
result.sources[0].customer.toString().should.equal(
|
|
1027
|
-
result.sources[1].person.
|
|
1028
|
-
result.sources[1].customer.toString().should.equal(
|
|
1035
|
+
result.sources[0].person.toString().should.equal(source1.toString());
|
|
1036
|
+
result.sources[0].customer.toString().should.equal(customer1.toString());
|
|
1037
|
+
result.sources[1].person.toString().should.equal(source2.toString());
|
|
1038
|
+
result.sources[1].customer.toString().should.equal(customer1.toString());
|
|
1029
1039
|
|
|
1030
1040
|
|
|
1031
1041
|
return done();
|
|
@@ -1044,13 +1054,17 @@ describe('Merge', function() {
|
|
|
1044
1054
|
config.flag = false;
|
|
1045
1055
|
merge = new Merge(mongoose, config);
|
|
1046
1056
|
|
|
1057
|
+
var source1 = new mongoose.Types.ObjectId();
|
|
1058
|
+
var customer1 = new mongoose.Types.ObjectId();
|
|
1059
|
+
var customer2 = new mongoose.Types.ObjectId();
|
|
1060
|
+
|
|
1047
1061
|
var newPerson1 = new Person();
|
|
1048
1062
|
newPerson1.name.first = 'New';
|
|
1049
1063
|
newPerson1.name.last = 'Person';
|
|
1050
1064
|
newPerson1.slug = 'new-person-1';
|
|
1051
1065
|
newPerson1.sources = [{
|
|
1052
|
-
person:
|
|
1053
|
-
customer:
|
|
1066
|
+
person: source1,
|
|
1067
|
+
customer: customer1
|
|
1054
1068
|
}];
|
|
1055
1069
|
|
|
1056
1070
|
var newPerson2 = new Person();
|
|
@@ -1058,8 +1072,8 @@ describe('Merge', function() {
|
|
|
1058
1072
|
newPerson2.name.last = 'Person';
|
|
1059
1073
|
newPerson2.slug = 'new-person-2';
|
|
1060
1074
|
newPerson2.sources = [{
|
|
1061
|
-
person:
|
|
1062
|
-
customer:
|
|
1075
|
+
person: source1,
|
|
1076
|
+
customer: customer2
|
|
1063
1077
|
}];
|
|
1064
1078
|
|
|
1065
1079
|
Person.upsert(newPerson1, 'test', function(err, result) {
|
|
@@ -1074,16 +1088,16 @@ describe('Merge', function() {
|
|
|
1074
1088
|
should.exist(result);
|
|
1075
1089
|
newPerson2 = result;
|
|
1076
1090
|
|
|
1077
|
-
merge.peopleById(newPerson2.id, newPerson1.id, 'testy',
|
|
1091
|
+
merge.peopleById(newPerson2.id, newPerson1.id, 'testy', function(err, result) {
|
|
1078
1092
|
|
|
1079
1093
|
should.not.exist(err);
|
|
1080
1094
|
should.exist(result);
|
|
1081
1095
|
|
|
1082
1096
|
result.sources.length.should.equal(2);
|
|
1083
|
-
result.sources[0].person.
|
|
1084
|
-
result.sources[0].customer.toString().should.equal(
|
|
1085
|
-
result.sources[1].person.
|
|
1086
|
-
result.sources[1].customer.toString().should.equal(
|
|
1097
|
+
result.sources[0].person.toString().should.equal(source1.toString());
|
|
1098
|
+
result.sources[0].customer.toString().should.equal(customer2.toString());
|
|
1099
|
+
result.sources[1].person.toString().should.equal(source1.toString());
|
|
1100
|
+
result.sources[1].customer.toString().should.equal(customer1.toString());
|
|
1087
1101
|
|
|
1088
1102
|
|
|
1089
1103
|
return done();
|
|
@@ -1102,13 +1116,18 @@ describe('Merge', function() {
|
|
|
1102
1116
|
config.flag = false;
|
|
1103
1117
|
merge = new Merge(mongoose, config);
|
|
1104
1118
|
|
|
1119
|
+
var source1 = new mongoose.Types.ObjectId();
|
|
1120
|
+
var source2 = new mongoose.Types.ObjectId();
|
|
1121
|
+
var customer1 = new mongoose.Types.ObjectId();
|
|
1122
|
+
var customer2 = new mongoose.Types.ObjectId();
|
|
1123
|
+
|
|
1105
1124
|
var newPerson1 = new Person();
|
|
1106
1125
|
newPerson1.name.first = 'New';
|
|
1107
1126
|
newPerson1.name.last = 'Person';
|
|
1108
1127
|
newPerson1.slug = 'new-person-1';
|
|
1109
1128
|
newPerson1.sources = [{
|
|
1110
|
-
person:
|
|
1111
|
-
customer:
|
|
1129
|
+
person: source1,
|
|
1130
|
+
customer: customer1
|
|
1112
1131
|
}];
|
|
1113
1132
|
|
|
1114
1133
|
var newPerson2 = new Person();
|
|
@@ -1116,8 +1135,8 @@ describe('Merge', function() {
|
|
|
1116
1135
|
newPerson2.name.last = 'Person';
|
|
1117
1136
|
newPerson2.slug = 'new-person-2';
|
|
1118
1137
|
newPerson2.sources = [{
|
|
1119
|
-
person:
|
|
1120
|
-
customer:
|
|
1138
|
+
person: source2,
|
|
1139
|
+
customer: customer2
|
|
1121
1140
|
}];
|
|
1122
1141
|
|
|
1123
1142
|
Person.upsert(newPerson1, 'test', function(err, result) {
|
|
@@ -1132,17 +1151,89 @@ describe('Merge', function() {
|
|
|
1132
1151
|
should.exist(result);
|
|
1133
1152
|
newPerson2 = result;
|
|
1134
1153
|
|
|
1135
|
-
merge.peopleById(newPerson2.id, newPerson1.id, 'testy',
|
|
1154
|
+
merge.peopleById(newPerson2.id, newPerson1.id, 'testy', function(err, result) {
|
|
1136
1155
|
|
|
1137
1156
|
should.not.exist(err);
|
|
1138
1157
|
should.exist(result);
|
|
1139
1158
|
|
|
1140
1159
|
result.sources.length.should.equal(2);
|
|
1141
|
-
result.sources[0].person.
|
|
1142
|
-
result.sources[0].customer.toString().should.equal(
|
|
1143
|
-
result.sources[1].person.
|
|
1144
|
-
result.sources[1].customer.toString().should.equal(
|
|
1160
|
+
result.sources[0].person.toString().should.equal(source2.toString());
|
|
1161
|
+
result.sources[0].customer.toString().should.equal(customer2.toString());
|
|
1162
|
+
result.sources[1].person.toString().should.equal(source1.toString());
|
|
1163
|
+
result.sources[1].customer.toString().should.equal(customer1.toString());
|
|
1164
|
+
|
|
1165
|
+
|
|
1166
|
+
return done();
|
|
1167
|
+
|
|
1168
|
+
});
|
|
1169
|
+
|
|
1170
|
+
});
|
|
1171
|
+
|
|
1172
|
+
});
|
|
1173
|
+
|
|
1174
|
+
});
|
|
1175
|
+
|
|
1176
|
+
it('Merges four sources for two customers', function(done) {
|
|
1177
|
+
|
|
1178
|
+
// reset to not flag
|
|
1179
|
+
config.flag = false;
|
|
1180
|
+
merge = new Merge(mongoose, config);
|
|
1181
|
+
|
|
1182
|
+
var source1 = new mongoose.Types.ObjectId();
|
|
1183
|
+
var source2 = new mongoose.Types.ObjectId();
|
|
1184
|
+
var source3 = new mongoose.Types.ObjectId();
|
|
1185
|
+
var source4 = new mongoose.Types.ObjectId();
|
|
1186
|
+
var customer1 = new mongoose.Types.ObjectId();
|
|
1187
|
+
var customer2 = new mongoose.Types.ObjectId();
|
|
1188
|
+
|
|
1189
|
+
var newPerson1 = new Person();
|
|
1190
|
+
newPerson1.name.first = 'New';
|
|
1191
|
+
newPerson1.name.last = 'Person';
|
|
1192
|
+
newPerson1.slug = 'new-person-1';
|
|
1193
|
+
newPerson1.sources = [{
|
|
1194
|
+
person: source1,
|
|
1195
|
+
customer: customer1
|
|
1196
|
+
}, {
|
|
1197
|
+
person: source2,
|
|
1198
|
+
customer: customer1
|
|
1199
|
+
}, {
|
|
1200
|
+
person: source2,
|
|
1201
|
+
customer: customer2
|
|
1202
|
+
}];
|
|
1203
|
+
|
|
1204
|
+
var newPerson2 = new Person();
|
|
1205
|
+
newPerson2.name.first = 'Newer';
|
|
1206
|
+
newPerson2.name.last = 'Person';
|
|
1207
|
+
newPerson2.slug = 'new-person-2';
|
|
1208
|
+
newPerson2.sources = [{
|
|
1209
|
+
person: source2,
|
|
1210
|
+
customer: customer2
|
|
1211
|
+
},{
|
|
1212
|
+
person: source3,
|
|
1213
|
+
customer: customer1
|
|
1214
|
+
},{
|
|
1215
|
+
person: source4,
|
|
1216
|
+
customer: customer2
|
|
1217
|
+
}];
|
|
1218
|
+
|
|
1219
|
+
Person.upsert(newPerson1, 'test', function(err, result) {
|
|
1220
|
+
|
|
1221
|
+
should.not.exist(err);
|
|
1222
|
+
should.exist(result);
|
|
1223
|
+
newPerson1 = result;
|
|
1224
|
+
|
|
1225
|
+
Person.upsert(newPerson2, 'test', function(err, result) {
|
|
1226
|
+
|
|
1227
|
+
should.not.exist(err);
|
|
1228
|
+
should.exist(result);
|
|
1229
|
+
newPerson2 = result;
|
|
1230
|
+
|
|
1231
|
+
merge.peopleById(newPerson2.id, newPerson1.id, 'testy', function(err, result) {
|
|
1232
|
+
|
|
1233
|
+
should.not.exist(err);
|
|
1234
|
+
should.exist(result);
|
|
1145
1235
|
|
|
1236
|
+
result.sources.length.should.equal(5);
|
|
1146
1237
|
|
|
1147
1238
|
return done();
|
|
1148
1239
|
|