@dhyasama/totem-models 3.3.1 → 3.4.1
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/lib/Account.js +6 -5
- package/lib/Message.js +25 -0
- package/lib/Organization.js +12 -0
- package/package-lock.json +1184 -0
- package/package.json +1 -1
- package/test/Account.js +10 -0
- package/test/Document.js +2 -0
- package/test/Message.js +88 -1
package/package.json
CHANGED
package/test/Account.js
CHANGED
|
@@ -93,6 +93,16 @@ describe('Account', function() {
|
|
|
93
93
|
|
|
94
94
|
});
|
|
95
95
|
|
|
96
|
+
it('finds by uppercase email', function(done) {
|
|
97
|
+
|
|
98
|
+
Account.findByEmail('TEST@TOTEMVC.COM', function(err, account) {
|
|
99
|
+
should.not.exist(err);
|
|
100
|
+
should.exist(account);
|
|
101
|
+
done();
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
});
|
|
105
|
+
|
|
96
106
|
it('lists all active accounts', function(done) {
|
|
97
107
|
|
|
98
108
|
Account.listAllAccounts(function(err, result) {
|
package/test/Document.js
CHANGED
package/test/Message.js
CHANGED
|
@@ -8,13 +8,17 @@ var
|
|
|
8
8
|
moment = require('moment'),
|
|
9
9
|
mongoose = require('mongoose'),
|
|
10
10
|
clearDB = require('mocha-mongoose')(config.db.uri, {noClear: true}),
|
|
11
|
-
|
|
11
|
+
Document = mongoose.model('Document'),
|
|
12
|
+
Message = mongoose.model('Message'),
|
|
13
|
+
Note = mongoose.model('Note');
|
|
12
14
|
|
|
13
15
|
var totemCustomerId1 = new mongoose.Types.ObjectId();
|
|
14
16
|
var totemCustomerId2 = new mongoose.Types.ObjectId();
|
|
15
17
|
var externalAttendee1 = new mongoose.Types.ObjectId();
|
|
16
18
|
var externalAttendee2 = new mongoose.Types.ObjectId();
|
|
17
19
|
|
|
20
|
+
var messageOne;
|
|
21
|
+
|
|
18
22
|
describe('Message', function() {
|
|
19
23
|
|
|
20
24
|
before(function(done) {
|
|
@@ -32,6 +36,8 @@ describe('Message', function() {
|
|
|
32
36
|
webhook: new mongoose.Types.ObjectId(),
|
|
33
37
|
customer: totemCustomerId1,
|
|
34
38
|
subject: 'Message one',
|
|
39
|
+
type: 'email',
|
|
40
|
+
subtype: 'boards',
|
|
35
41
|
recipients: {
|
|
36
42
|
external: [externalAttendee1]
|
|
37
43
|
},
|
|
@@ -41,6 +47,7 @@ describe('Message', function() {
|
|
|
41
47
|
Message.upsert(message, function(err, result) {
|
|
42
48
|
should.not.exist(err);
|
|
43
49
|
should.exist(result);
|
|
50
|
+
messageOne = result;
|
|
44
51
|
done();
|
|
45
52
|
});
|
|
46
53
|
|
|
@@ -52,6 +59,8 @@ describe('Message', function() {
|
|
|
52
59
|
webhook: new mongoose.Types.ObjectId(),
|
|
53
60
|
customer: totemCustomerId2,
|
|
54
61
|
subject: 'Message two',
|
|
62
|
+
type: 'email',
|
|
63
|
+
subtype: 'boards',
|
|
55
64
|
recipients: {
|
|
56
65
|
external: [externalAttendee2]
|
|
57
66
|
},
|
|
@@ -66,6 +75,70 @@ describe('Message', function() {
|
|
|
66
75
|
|
|
67
76
|
});
|
|
68
77
|
|
|
78
|
+
it('creates a document for a message', function(done) {
|
|
79
|
+
|
|
80
|
+
config.CUSTOMER_ID = totemCustomerId1;
|
|
81
|
+
|
|
82
|
+
Document.createForModel({
|
|
83
|
+
customer: config.CUSTOMER_ID,
|
|
84
|
+
createdBy: new mongoose.Types.ObjectId(),
|
|
85
|
+
name: 'plain.txt',
|
|
86
|
+
contentType: 'text/plain',
|
|
87
|
+
contentLength: 124,
|
|
88
|
+
s3: {
|
|
89
|
+
bucket: 'totem',
|
|
90
|
+
key: 'docs'
|
|
91
|
+
}
|
|
92
|
+
}, Message, messageOne._id, function(err, result) {
|
|
93
|
+
|
|
94
|
+
should.not.exist(err);
|
|
95
|
+
should.exist(result);
|
|
96
|
+
should.exist(result.document);
|
|
97
|
+
should.exist(result.addedTo);
|
|
98
|
+
result.addedTo.documents.length.should.equal(1);
|
|
99
|
+
|
|
100
|
+
return done();
|
|
101
|
+
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('creates a note for a message', function(done) {
|
|
107
|
+
|
|
108
|
+
config.CUSTOMER_ID = totemCustomerId1;
|
|
109
|
+
|
|
110
|
+
Note.createForModel({
|
|
111
|
+
createdBy: new mongoose.Types.ObjectId(),
|
|
112
|
+
text: 'Best note ever!'
|
|
113
|
+
}, Message, messageOne._id, function(err, result) {
|
|
114
|
+
|
|
115
|
+
should.not.exist(err);
|
|
116
|
+
should.exist(result);
|
|
117
|
+
should.exist(result.note);
|
|
118
|
+
should.exist(result.addedTo);
|
|
119
|
+
result.addedTo.notes.length.should.equal(1);
|
|
120
|
+
|
|
121
|
+
return done();
|
|
122
|
+
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('gets a message by id', function(done) {
|
|
128
|
+
|
|
129
|
+
config.CUSTOMER_ID = totemCustomerId1;
|
|
130
|
+
|
|
131
|
+
Message.getById(messageOne.id, function(err, result) {
|
|
132
|
+
should.not.exist(err);
|
|
133
|
+
should.exist(result);
|
|
134
|
+
result.subject.should.equal('Message one');
|
|
135
|
+
result.documents.length.should.equal(1);
|
|
136
|
+
result.notes.length.should.equal(1);
|
|
137
|
+
done();
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
});
|
|
141
|
+
|
|
69
142
|
it('gets messages for a person', function(done) {
|
|
70
143
|
|
|
71
144
|
config.CUSTOMER_ID = totemCustomerId1;
|
|
@@ -114,6 +187,8 @@ describe('Message', function() {
|
|
|
114
187
|
webhook: new mongoose.Types.ObjectId(),
|
|
115
188
|
customer: totemCustomerId2,
|
|
116
189
|
subject: 'test 3',
|
|
190
|
+
type: 'email',
|
|
191
|
+
subtype: 'boards',
|
|
117
192
|
recipients: {
|
|
118
193
|
external: [new mongoose.Types.ObjectId()]
|
|
119
194
|
},
|
|
@@ -144,4 +219,16 @@ describe('Message', function() {
|
|
|
144
219
|
|
|
145
220
|
});
|
|
146
221
|
|
|
222
|
+
it('tries to get a message belonging to another customer', function(done) {
|
|
223
|
+
|
|
224
|
+
config.CUSTOMER_ID = totemCustomerId2;
|
|
225
|
+
|
|
226
|
+
Message.getById(messageOne.id, function(err, result) {
|
|
227
|
+
should.not.exist(err);
|
|
228
|
+
should.not.exist(result);
|
|
229
|
+
done();
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
});
|
|
233
|
+
|
|
147
234
|
});
|