@dhyasama/totem-models 3.0.0 → 3.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/.npmignore +14 -0
- package/index.js +2 -0
- package/lib/Document.js +65 -285
- package/lib/Interaction.js +2 -1
- package/lib/LimitedPartner.js +2 -1
- package/lib/Message.js +209 -0
- package/lib/Organization.js +13 -7
- package/lib/Person.js +2 -0
- package/package-lock.json +1168 -0
- package/package.json +1 -1
- package/test/Document.js +236 -0
- package/test/Message.js +144 -0
- package/test/Organization.js +1 -1
package/package.json
CHANGED
package/test/Document.js
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var
|
|
4
|
+
|
|
5
|
+
should = require("should"),
|
|
6
|
+
config = require('./config')['test'],
|
|
7
|
+
_ = require('underscore'),
|
|
8
|
+
mongoose = require('mongoose'),
|
|
9
|
+
clearDB = require('mocha-mongoose')(config.db.uri, {noClear: true}),
|
|
10
|
+
Document = mongoose.model('Document'),
|
|
11
|
+
Interaction = mongoose.model('Interaction'),
|
|
12
|
+
Message = mongoose.model('Message'),
|
|
13
|
+
Organization = mongoose.model('Organization'),
|
|
14
|
+
Person = mongoose.model('Person');
|
|
15
|
+
|
|
16
|
+
var interaction, message, org, person, documentCreator, documentId;
|
|
17
|
+
|
|
18
|
+
describe('Document', function() {
|
|
19
|
+
|
|
20
|
+
before(function(done) {
|
|
21
|
+
if (mongoose.connection.db) return done();
|
|
22
|
+
mongoose.connect(config.db.uri, done);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
before(function(done) {
|
|
26
|
+
clearDB(done);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
before(function(done) {
|
|
30
|
+
|
|
31
|
+
interaction = new Interaction({
|
|
32
|
+
calendarEventId: new mongoose.Types.ObjectId(),
|
|
33
|
+
providerEventId: 'abc123',
|
|
34
|
+
totemCustomerId: config.CUSTOMER_ID,
|
|
35
|
+
summary: 'Test'
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
Interaction.upsert(interaction, function(err, result) {
|
|
39
|
+
|
|
40
|
+
should.not.exist(err);
|
|
41
|
+
should.exist(result);
|
|
42
|
+
interaction = result;
|
|
43
|
+
|
|
44
|
+
return done();
|
|
45
|
+
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
before(function(done) {
|
|
51
|
+
|
|
52
|
+
message = new Message({
|
|
53
|
+
webhook: new mongoose.Types.ObjectId(),
|
|
54
|
+
customer: config.CUSTOMER_ID
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
Message.upsert(message, function(err, result) {
|
|
58
|
+
|
|
59
|
+
should.not.exist(err);
|
|
60
|
+
should.exist(result);
|
|
61
|
+
message = result;
|
|
62
|
+
|
|
63
|
+
return done();
|
|
64
|
+
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
before(function(done) {
|
|
70
|
+
|
|
71
|
+
org = new Organization();
|
|
72
|
+
org.name = 'Big Org';
|
|
73
|
+
org.slug = 'big-org';
|
|
74
|
+
|
|
75
|
+
Organization.upsert(org, 'test', function(err, result) {
|
|
76
|
+
|
|
77
|
+
should.not.exist(err);
|
|
78
|
+
should.exist(result);
|
|
79
|
+
org = result;
|
|
80
|
+
|
|
81
|
+
return done();
|
|
82
|
+
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
before(function(done) {
|
|
88
|
+
|
|
89
|
+
person = new Person();
|
|
90
|
+
person.name = {
|
|
91
|
+
'first': 'Big',
|
|
92
|
+
'last': 'Person'
|
|
93
|
+
};
|
|
94
|
+
person.slug = 'big-person';
|
|
95
|
+
|
|
96
|
+
Person.upsert(person, 'test', function(err, result) {
|
|
97
|
+
|
|
98
|
+
should.not.exist(err);
|
|
99
|
+
should.exist(result);
|
|
100
|
+
person = result;
|
|
101
|
+
|
|
102
|
+
return done();
|
|
103
|
+
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
before(function(done) {
|
|
109
|
+
|
|
110
|
+
documentCreator = new Person();
|
|
111
|
+
documentCreator.name = {
|
|
112
|
+
'first': 'George',
|
|
113
|
+
'last': 'Michael'
|
|
114
|
+
};
|
|
115
|
+
documentCreator.slug = 'george-michael';
|
|
116
|
+
|
|
117
|
+
Person.upsert(documentCreator, 'test', function(err, result) {
|
|
118
|
+
|
|
119
|
+
should.not.exist(err);
|
|
120
|
+
should.exist(result);
|
|
121
|
+
documentCreator = result;
|
|
122
|
+
|
|
123
|
+
return done();
|
|
124
|
+
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('creates a document for an interaction', function(done) {
|
|
130
|
+
|
|
131
|
+
Document.createForModel({
|
|
132
|
+
createdBy: documentCreator,
|
|
133
|
+
name: 'your_mom.doc',
|
|
134
|
+
contentType: 'application/doc',
|
|
135
|
+
contentLength: 1248,
|
|
136
|
+
s3key: '/totem/docs'
|
|
137
|
+
}, Interaction, interaction._id, function(err, result) {
|
|
138
|
+
|
|
139
|
+
should.not.exist(err);
|
|
140
|
+
should.exist(result);
|
|
141
|
+
should.exist(result.document);
|
|
142
|
+
should.exist(result.addedTo);
|
|
143
|
+
result.addedTo.documents.length.should.equal(1);
|
|
144
|
+
|
|
145
|
+
return done();
|
|
146
|
+
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('creates a document for a message', function(done) {
|
|
152
|
+
|
|
153
|
+
Document.createForModel({
|
|
154
|
+
createdBy: documentCreator,
|
|
155
|
+
name: 'plain.txt',
|
|
156
|
+
contentType: 'text/plain',
|
|
157
|
+
contentLength: 124,
|
|
158
|
+
s3key: '/totem/doculate'
|
|
159
|
+
}, Message, message._id, function(err, result) {
|
|
160
|
+
|
|
161
|
+
should.not.exist(err);
|
|
162
|
+
should.exist(result);
|
|
163
|
+
should.exist(result.document);
|
|
164
|
+
should.exist(result.addedTo);
|
|
165
|
+
result.addedTo.documents.length.should.equal(1);
|
|
166
|
+
|
|
167
|
+
return done();
|
|
168
|
+
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('creates a document for an organization', function(done) {
|
|
174
|
+
|
|
175
|
+
Document.createForModel({
|
|
176
|
+
createdBy: documentCreator,
|
|
177
|
+
name: 'test_file.jpg',
|
|
178
|
+
contentType: 'image/jpeg',
|
|
179
|
+
contentLength: 12345,
|
|
180
|
+
s3key: '/totem/documents'
|
|
181
|
+
}, Organization, org._id, function(err, result) {
|
|
182
|
+
|
|
183
|
+
should.not.exist(err);
|
|
184
|
+
should.exist(result);
|
|
185
|
+
should.exist(result.document);
|
|
186
|
+
should.exist(result.addedTo);
|
|
187
|
+
result.addedTo.documents.length.should.equal(1);
|
|
188
|
+
|
|
189
|
+
documentId = result.addedTo.documents[0];
|
|
190
|
+
|
|
191
|
+
return done();
|
|
192
|
+
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('creates a document for a person', function(done) {
|
|
198
|
+
|
|
199
|
+
Document.createForModel({
|
|
200
|
+
createdBy: documentCreator,
|
|
201
|
+
name: 'test.pdf',
|
|
202
|
+
contentType: 'application/pdf',
|
|
203
|
+
contentLength: 54321,
|
|
204
|
+
s3key: '/documents/totem'
|
|
205
|
+
}, Person, person._id, function(err, result) {
|
|
206
|
+
|
|
207
|
+
should.not.exist(err);
|
|
208
|
+
should.exist(result);
|
|
209
|
+
should.exist(result.document);
|
|
210
|
+
should.exist(result.addedTo);
|
|
211
|
+
result.addedTo.documents.length.should.equal(1);
|
|
212
|
+
|
|
213
|
+
return done();
|
|
214
|
+
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('gets a document by id', function(done) {
|
|
220
|
+
Document.getById(documentId, function(err, result) {
|
|
221
|
+
should.not.exist(err);
|
|
222
|
+
should.exist(result);
|
|
223
|
+
result.name.should.equal('test_file.jpg');
|
|
224
|
+
return done();
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it('deletes a document', function(done) {
|
|
229
|
+
Document.delete(documentId, function(err, result) {
|
|
230
|
+
should.not.exist(err);
|
|
231
|
+
should.exist(result);
|
|
232
|
+
return done();
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
});
|
package/test/Message.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var
|
|
4
|
+
|
|
5
|
+
should = require("should"),
|
|
6
|
+
config = require('./config')['test'],
|
|
7
|
+
_ = require('underscore'),
|
|
8
|
+
moment = require('moment'),
|
|
9
|
+
mongoose = require('mongoose'),
|
|
10
|
+
clearDB = require('mocha-mongoose')(config.db.uri, {noClear: true}),
|
|
11
|
+
Message = mongoose.model('Message');
|
|
12
|
+
|
|
13
|
+
var totemCustomerId1 = new mongoose.Types.ObjectId();
|
|
14
|
+
var totemCustomerId2 = new mongoose.Types.ObjectId();
|
|
15
|
+
var externalAttendee1 = new mongoose.Types.ObjectId();
|
|
16
|
+
var externalAttendee2 = new mongoose.Types.ObjectId();
|
|
17
|
+
|
|
18
|
+
describe('Message', function() {
|
|
19
|
+
|
|
20
|
+
before(function(done) {
|
|
21
|
+
if (mongoose.connection.db) return done();
|
|
22
|
+
mongoose.connect(config.db.uri, done);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
before(function(done) {
|
|
26
|
+
clearDB(done);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('creates a message', function(done) {
|
|
30
|
+
|
|
31
|
+
var message = new Message({
|
|
32
|
+
webhook: new mongoose.Types.ObjectId(),
|
|
33
|
+
customer: totemCustomerId1,
|
|
34
|
+
subject: 'Message one',
|
|
35
|
+
recipients: {
|
|
36
|
+
external: [externalAttendee1]
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
Message.upsert(message, function(err, result) {
|
|
41
|
+
should.not.exist(err);
|
|
42
|
+
should.exist(result);
|
|
43
|
+
done();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('creates another message', function(done) {
|
|
49
|
+
|
|
50
|
+
var message = new Message({
|
|
51
|
+
webhook: new mongoose.Types.ObjectId(),
|
|
52
|
+
customer: totemCustomerId2,
|
|
53
|
+
subject: 'Message two',
|
|
54
|
+
recipients: {
|
|
55
|
+
external: [externalAttendee2]
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
Message.upsert(message, function(err, result) {
|
|
60
|
+
should.not.exist(err);
|
|
61
|
+
should.exist(result);
|
|
62
|
+
done();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('gets messages for a person', function(done) {
|
|
68
|
+
|
|
69
|
+
config.CUSTOMER_ID = totemCustomerId1;
|
|
70
|
+
|
|
71
|
+
Message.getForPeople([externalAttendee1], { before: moment().add(1, 'hour').toISOString()}, function(err, result) {
|
|
72
|
+
should.not.exist(err);
|
|
73
|
+
should.exist(result);
|
|
74
|
+
result.length.should.equal(1);
|
|
75
|
+
result[0].subject.should.equal('Message one');
|
|
76
|
+
done();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('tries to get messages for a person as an admin process', function(done) {
|
|
82
|
+
|
|
83
|
+
config.CUSTOMER_ID = 'GLOBAL_PROCESS';
|
|
84
|
+
|
|
85
|
+
Message.getForPeople([externalAttendee1], { before: moment().add(1, 'hour').toISOString()}, function(err, result) {
|
|
86
|
+
should.exist(err);
|
|
87
|
+
should.not.exist(result);
|
|
88
|
+
done();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('gets messages for a person as an admin process', function(done) {
|
|
94
|
+
|
|
95
|
+
config.CUSTOMER_ID = totemCustomerId2;
|
|
96
|
+
|
|
97
|
+
Message.getForPeople([externalAttendee2], { before: moment().add(1, 'hour').toISOString()}, function(err, result) {
|
|
98
|
+
should.not.exist(err);
|
|
99
|
+
should.exist(result);
|
|
100
|
+
result.length.should.equal(1);
|
|
101
|
+
result[0].subject.should.equal('Message two');
|
|
102
|
+
done();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('gets messages for a customer', function(done) {
|
|
108
|
+
|
|
109
|
+
config.CUSTOMER_ID = totemCustomerId2;
|
|
110
|
+
|
|
111
|
+
var message = new Message({
|
|
112
|
+
webhook: new mongoose.Types.ObjectId(),
|
|
113
|
+
customer: totemCustomerId2,
|
|
114
|
+
subject: 'test 3',
|
|
115
|
+
recipients: {
|
|
116
|
+
external: [new mongoose.Types.ObjectId()]
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
Message.upsert(message, function(err, result) {
|
|
121
|
+
|
|
122
|
+
should.not.exist(err);
|
|
123
|
+
should.exist(result);
|
|
124
|
+
|
|
125
|
+
Message.getForCustomer(totemCustomerId2, function(err, result) {
|
|
126
|
+
|
|
127
|
+
should.not.exist(err);
|
|
128
|
+
should.exist(result);
|
|
129
|
+
result.length.should.equal(2);
|
|
130
|
+
|
|
131
|
+
Message.getForCustomer(totemCustomerId1, function(err, result) {
|
|
132
|
+
should.not.exist(err);
|
|
133
|
+
should.exist(result);
|
|
134
|
+
result.length.should.equal(1);
|
|
135
|
+
done();
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
});
|
package/test/Organization.js
CHANGED