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