@dhyasama/totem-models 7.57.0 → 8.0.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/test/List.js CHANGED
@@ -39,15 +39,15 @@ describe('List', function() {
39
39
 
40
40
  before(function(done) {
41
41
 
42
- lp = new LimitedPartner();
43
- lp.name = 'Big LP';
44
- lp.slug = 'big-lp';
42
+ org = new Organization();
43
+ org.name = 'Big Org';
44
+ org.slug = 'big-org';
45
45
 
46
- LimitedPartner.upsert(lp, 'test', 'lp-full', function(err, result) {
46
+ Organization.upsert(org, 'test', function(err, result) {
47
47
 
48
48
  should.not.exist(err);
49
49
  should.exist(result);
50
- lp = result;
50
+ org = result;
51
51
 
52
52
  return done();
53
53
 
@@ -57,15 +57,16 @@ describe('List', function() {
57
57
 
58
58
  before(function(done) {
59
59
 
60
- org = new Organization();
61
- org.name = 'Big Org';
62
- org.slug = 'big-org';
60
+ lp = new LimitedPartner();
61
+ lp.name = 'Big LP';
62
+ lp.slug = 'big-lp';
63
+ lp.customer = org;
63
64
 
64
- Organization.upsert(org, 'test', function(err, result) {
65
+ LimitedPartner.upsert(lp, 'test', { role: 'lp-full' }, function(err, result) {
65
66
 
66
67
  should.not.exist(err);
67
68
  should.exist(result);
68
- org = result;
69
+ lp = result;
69
70
 
70
71
  return done();
71
72
 
@@ -118,7 +119,7 @@ describe('List', function() {
118
119
 
119
120
  it('creates an empty list', function(done) {
120
121
 
121
- List.createList('My Awesome List', {}, creator, function(err, result) {
122
+ List.createList('My Awesome List', {}, creator, { CUSTOMER_ID: org._id }, function(err, result) {
122
123
  should.not.exist(err);
123
124
  should.exist(result);
124
125
  myAwesomeList = result;
@@ -130,10 +131,7 @@ describe('List', function() {
130
131
 
131
132
  it('creates an empty list for another customer', function(done) {
132
133
 
133
- var previousCustomerId = config.CUSTOMER_ID;
134
- config.CUSTOMER_ID = secondCustomerId;
135
-
136
- List.createList('All the News', {}, creator, function(err, result) {
134
+ List.createList('All the News', {}, creator, { CUSTOMER_ID: secondCustomerId }, function(err, result) {
137
135
 
138
136
  should.not.exist(err);
139
137
  should.exist(result);
@@ -141,9 +139,6 @@ describe('List', function() {
141
139
  secondCustomerList = result;
142
140
  secondCustomerList.toJSON().toString().length.should.be.above(0);
143
141
 
144
- // Restore original value
145
- config.CUSTOMER_ID = previousCustomerId;
146
-
147
142
  return done();
148
143
 
149
144
  });
@@ -151,7 +146,7 @@ describe('List', function() {
151
146
  });
152
147
 
153
148
  it('adds an lp', function(done) {
154
- List.addItem(myAwesomeList.id, lp.id, 'limitedPartners', function(err, result) {
149
+ List.addItem(myAwesomeList.id, lp.id, 'limitedPartners', { CUSTOMER_ID: org._id }, function(err, result) {
155
150
  should.not.exist(err);
156
151
  should.exist(result);
157
152
  result.limitedPartners.length.should.equal(1);
@@ -162,7 +157,7 @@ describe('List', function() {
162
157
  });
163
158
 
164
159
  it('adds an organization', function(done) {
165
- List.addItem(myAwesomeList.id, org.id, 'organizations', function(err, result) {
160
+ List.addItem(myAwesomeList.id, org.id, 'organizations', { CUSTOMER_ID: org._id }, function(err, result) {
166
161
  should.not.exist(err);
167
162
  should.exist(result);
168
163
  result.organizations.length.should.equal(1);
@@ -173,7 +168,7 @@ describe('List', function() {
173
168
  });
174
169
 
175
170
  it('adds a person', function(done) {
176
- List.addItem(myAwesomeList.id, person.id, 'people', function(err, result) {
171
+ List.addItem(myAwesomeList.id, person.id, 'people', { CUSTOMER_ID: org._id }, function(err, result) {
177
172
  should.not.exist(err);
178
173
  should.exist(result);
179
174
  result.people.length.should.equal(1);
@@ -184,7 +179,7 @@ describe('List', function() {
184
179
  });
185
180
 
186
181
  it('adds a person again and dedupes', function(done) {
187
- List.addItem(myAwesomeList.id, person.id, 'people', function(err, result) {
182
+ List.addItem(myAwesomeList.id, person.id, 'people', { CUSTOMER_ID: org._id }, function(err, result) {
188
183
  should.not.exist(err);
189
184
  should.exist(result);
190
185
  result.people.length.should.equal(1);
@@ -195,7 +190,7 @@ describe('List', function() {
195
190
  });
196
191
 
197
192
  it('removes an lp', function(done) {
198
- List.removeItem(myAwesomeList.id, myAwesomeList.limitedPartners[0], 'limitedPartners', function(err, result) {
193
+ List.removeItem(myAwesomeList.id, myAwesomeList.limitedPartners[0], 'limitedPartners', { CUSTOMER_ID: org._id }, function(err, result) {
199
194
  should.not.exist(err);
200
195
  should.exist(result);
201
196
  result.limitedPartners.length.should.equal(0);
@@ -206,7 +201,7 @@ describe('List', function() {
206
201
  });
207
202
 
208
203
  it('gets a list by id', function(done) {
209
- List.getById(myAwesomeList.id, function(err, result) {
204
+ List.getById(myAwesomeList.id, { CUSTOMER_ID: org._id }, function(err, result) {
210
205
 
211
206
  should.not.exist(err);
212
207
  should.exist(result);
@@ -226,7 +221,7 @@ describe('List', function() {
226
221
  });
227
222
 
228
223
  it('tries to get a list belonging to a different customer', function(done) {
229
- List.getById(secondCustomerList.id, function(err, result) {
224
+ List.getById(secondCustomerList.id, { CUSTOMER_ID: org._id }, function(err, result) {
230
225
  should.not.exist(err);
231
226
  should.not.exist(result);
232
227
  return done();
@@ -234,7 +229,7 @@ describe('List', function() {
234
229
  });
235
230
 
236
231
  it('aggregates items in a list', function(done) {
237
- List.getById(myAwesomeList.id, function(err, result) {
232
+ List.getById(myAwesomeList.id, { CUSTOMER_ID: org._id }, function(err, result) {
238
233
 
239
234
  should.not.exist(err);
240
235
  should.exist(result);
@@ -253,7 +248,7 @@ describe('List', function() {
253
248
  });
254
249
 
255
250
  it('gets all lists for a customer', function(done) {
256
- List.getLists(function(err, result) {
251
+ List.getLists({ CUSTOMER_ID: org._id }, function(err, result) {
257
252
  should.not.exist(err);
258
253
  should.exist(result);
259
254
  result.length.should.equal(1);
@@ -264,7 +259,7 @@ describe('List', function() {
264
259
 
265
260
  it('modifies a list by id', function (done) {
266
261
 
267
- List.getById(myAwesomeList.id, function(err, list) {
262
+ List.getById(myAwesomeList.id, { CUSTOMER_ID: org._id }, function(err, list) {
268
263
 
269
264
  should.not.exist(err);
270
265
  should.exist(list);
@@ -299,7 +294,7 @@ describe('List', function() {
299
294
 
300
295
  it('deletes a list', function(done) {
301
296
 
302
- List.remove(myAwesomeList.id, function(err, result) {
297
+ List.remove(myAwesomeList.id, { CUSTOMER_ID: org._id }, function(err, result) {
303
298
 
304
299
  should.not.exist(err);
305
300
  should.exist(result);
package/test/Message.js CHANGED
@@ -86,10 +86,8 @@ describe('Message', function() {
86
86
 
87
87
  it('creates a document for a message', function(done) {
88
88
 
89
- config.CUSTOMER_ID = totemCustomerId1;
90
-
91
89
  Document.createForModel({
92
- customer: config.CUSTOMER_ID,
90
+ customer: totemCustomerId1,
93
91
  createdBy: new mongoose.Types.ObjectId(),
94
92
  name: 'plain.txt',
95
93
  contentType: 'text/plain',
@@ -115,11 +113,10 @@ describe('Message', function() {
115
113
 
116
114
  it('creates a note for a message', function(done) {
117
115
 
118
- config.CUSTOMER_ID = totemCustomerId1;
119
-
120
116
  Note.createForModel({
121
117
  createdBy: new mongoose.Types.ObjectId(),
122
- text: 'Best note ever!'
118
+ text: 'Best note ever!',
119
+ customer: totemCustomerId1
123
120
  }, Message, messageOne._id, function(err, result) {
124
121
 
125
122
  should.not.exist(err);
@@ -136,9 +133,7 @@ describe('Message', function() {
136
133
 
137
134
  it('gets a message by id', function(done) {
138
135
 
139
- config.CUSTOMER_ID = totemCustomerId1;
140
-
141
- Message.getById(messageOne.id, function(err, result) {
136
+ Message.getById(messageOne.id, { CUSTOMER_ID: totemCustomerId1 }, function(err, result) {
142
137
  should.not.exist(err);
143
138
  should.exist(result);
144
139
  result.subject.should.equal('Message one');
@@ -151,9 +146,7 @@ describe('Message', function() {
151
146
 
152
147
  it('gets messages for a person', function(done) {
153
148
 
154
- config.CUSTOMER_ID = totemCustomerId1;
155
-
156
- Message.getForPeople([externalAttendee1], { before: moment().add(1, 'hour').toISOString()}, function(err, result) {
149
+ Message.getForPeople([externalAttendee1], { CUSTOMER_ID: totemCustomerId1, before: moment().add(1, 'hour').toISOString()}, function(err, result) {
157
150
  should.not.exist(err);
158
151
  should.exist(result);
159
152
  result.length.should.equal(1);
@@ -165,9 +158,7 @@ describe('Message', function() {
165
158
 
166
159
  it('gets messages for an org', function(done) {
167
160
 
168
- config.CUSTOMER_ID = totemCustomerId1;
169
-
170
- Message.getForOrg(orgId1, { before: moment().add(1, 'hour').toISOString()}, function(err, result) {
161
+ Message.getForOrg(orgId1, { CUSTOMER_ID: totemCustomerId1, before: moment().add(1, 'hour').toISOString()}, function(err, result) {
171
162
  should.not.exist(err);
172
163
  should.exist(result);
173
164
  result.length.should.equal(1);
@@ -177,36 +168,8 @@ describe('Message', function() {
177
168
 
178
169
  });
179
170
 
180
- it('tries to get messages for a person as an admin process', function(done) {
181
-
182
- config.CUSTOMER_ID = 'GLOBAL_PROCESS';
183
-
184
- Message.getForPeople([externalAttendee1], { before: moment().add(1, 'hour').toISOString()}, function(err, result) {
185
- should.exist(err);
186
- should.not.exist(result);
187
- done();
188
- });
189
-
190
- });
191
-
192
- it('gets messages for a person as an admin process', function(done) {
193
-
194
- config.CUSTOMER_ID = totemCustomerId2;
195
-
196
- Message.getForPeople([externalAttendee2], { before: moment().add(1, 'hour').toISOString()}, function(err, result) {
197
- should.not.exist(err);
198
- should.exist(result);
199
- result.length.should.equal(1);
200
- result[0].subject.should.equal('Message two');
201
- done();
202
- });
203
-
204
- });
205
-
206
171
  it('gets messages for a customer', function(done) {
207
172
 
208
- config.CUSTOMER_ID = totemCustomerId2;
209
-
210
173
  var message = new Message({
211
174
  webhook: new mongoose.Types.ObjectId(),
212
175
  customer: totemCustomerId2,
@@ -245,9 +208,7 @@ describe('Message', function() {
245
208
 
246
209
  it('tries to get a message belonging to another customer', function(done) {
247
210
 
248
- config.CUSTOMER_ID = totemCustomerId2;
249
-
250
- Message.getById(messageOne.id, function(err, result) {
211
+ Message.getById(messageOne.id, { CUSTOMER_ID: totemCustomerId2 }, function(err, result) {
251
212
  should.not.exist(err);
252
213
  should.not.exist(result);
253
214
  done();
package/test/News.js CHANGED
@@ -1,18 +1,15 @@
1
1
  "use strict";
2
2
 
3
- var
3
+ let
4
4
 
5
5
  should = require("should"),
6
6
  config = require('./config')['test'],
7
7
  mongoose = require('mongoose'),
8
8
  clearDB = require('mocha-mongoose')(config.db.uri, {noClear: true}),
9
9
  News = mongoose.model('News'),
10
- news = new News(),
11
- //fund._id = new mongoose.Types.ObjectId();
12
- Fund = mongoose.model('Fund'),
13
- fund = new Fund();
14
-
10
+ news = new News();
15
11
 
12
+ let companyId = new mongoose.Types.ObjectId();
16
13
 
17
14
  describe('News', function() {
18
15
 
@@ -44,9 +41,9 @@ describe('News', function() {
44
41
 
45
42
  it('updates a news item', function(done) {
46
43
 
47
- news.excerpt = 'Amazing new search portal';
44
+ let update = { $set: { org: companyId } };
48
45
 
49
- News.upsert(news, function(err, item) {
46
+ News.modifyById(news._id, update, function(err, item) {
50
47
  should.not.exist(err);
51
48
  should.exist(item);
52
49
  news = item;
@@ -55,29 +52,15 @@ describe('News', function() {
55
52
 
56
53
  });
57
54
 
58
- it('gets a news item by id', function(done) {
59
- News.getById(news.id, function(err, item) {
60
- should.not.exist(err);
61
- should.exist(item);
62
- item.id.should.equal(news.id);
63
- done();
64
- });
65
- });
55
+ it('gets news items for a company', function(done) {
66
56
 
67
- it('lists all news items', function(done) {
68
- News.list(function(err, items) {
69
- should.not.exist(err);
70
- should.exist(items);
71
- items.length.should.equal(1);
72
- done();
73
- });
74
- });
57
+ News.listForCompany(news._id, function(err, items) {
58
+ should.not.exist(err);
59
+ should.exist(items);
60
+ done();
61
+ });
75
62
 
76
- it('deletes a news item', function(done) {
77
- News.delete(news.id, function(err, item) {
78
- should.not.exist(err);
79
- done();
80
- });
81
63
  });
82
64
 
65
+
83
66
  });
package/test/Note.js CHANGED
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
 
3
- var
3
+ let
4
4
 
5
5
  should = require("should"),
6
6
  config = require('./config')['test'],
7
- _ = require('underscore'),
8
7
  mongoose = require('mongoose'),
9
8
  clearDB = require('mocha-mongoose')(config.db.uri, {noClear: true}),
10
9
  LimitedPartner = mongoose.model('LimitedPartner'),
@@ -12,9 +11,7 @@ var
12
11
  Organization = mongoose.model('Organization'),
13
12
  Person = mongoose.model('Person');
14
13
 
15
- var lp, org, person, person2, person3, person4, noteCreator;
16
- var accountId = new mongoose.Types.ObjectId();
17
- var noteId, groupNoteId;
14
+ let lp, org, person, person2, person3, person4, noteCreator, noteId;
18
15
 
19
16
  describe('Note', function() {
20
17
 
@@ -29,15 +26,15 @@ describe('Note', function() {
29
26
 
30
27
  before(function(done) {
31
28
 
32
- lp = new LimitedPartner();
33
- lp.name = 'Big LP';
34
- lp.slug = 'big-lp';
29
+ org = new Organization();
30
+ org.name = 'Big Org';
31
+ org.slug = 'big-org';
35
32
 
36
- LimitedPartner.upsert(lp, 'test', 'lp-full', function(err, result) {
33
+ Organization.upsert(org, 'test', function(err, result) {
37
34
 
38
35
  should.not.exist(err);
39
36
  should.exist(result);
40
- lp = result;
37
+ org = result;
41
38
 
42
39
  return done();
43
40
 
@@ -47,15 +44,16 @@ describe('Note', function() {
47
44
 
48
45
  before(function(done) {
49
46
 
50
- org = new Organization();
51
- org.name = 'Big Org';
52
- org.slug = 'big-org';
47
+ lp = new LimitedPartner();
48
+ lp.name = 'Big LP';
49
+ lp.slug = 'big-lp';
50
+ lp.customer = org;
53
51
 
54
- Organization.upsert(org, 'test', function(err, result) {
52
+ LimitedPartner.upsert(lp, 'test', { role: 'lp-full' }, function(err, result) {
55
53
 
56
54
  should.not.exist(err);
57
55
  should.exist(result);
58
- org = result;
56
+ lp = result;
59
57
 
60
58
  return done();
61
59
 
@@ -172,7 +170,8 @@ describe('Note', function() {
172
170
 
173
171
  Note.createForModel({
174
172
  createdBy: noteCreator,
175
- text: 'Best note ever!'
173
+ text: 'Best note ever!',
174
+ customer: org
176
175
  }, Organization, org._id, function(err, result) {
177
176
 
178
177
  should.not.exist(err);
@@ -193,7 +192,8 @@ describe('Note', function() {
193
192
 
194
193
  Note.createForModel({
195
194
  createdBy: noteCreator,
196
- text: 'Best note ever!'
195
+ text: 'Best note ever!',
196
+ customer: org
197
197
  }, LimitedPartner, lp._id, function(err, result) {
198
198
 
199
199
  should.not.exist(err);
@@ -212,7 +212,8 @@ describe('Note', function() {
212
212
 
213
213
  Note.createForModel({
214
214
  createdBy: noteCreator,
215
- text: 'Best note ever!'
215
+ text: 'Best note ever!',
216
+ customer: org
216
217
  }, Person, person._id, function(err, result) {
217
218
 
218
219
  should.not.exist(err);
@@ -228,7 +229,7 @@ describe('Note', function() {
228
229
  });
229
230
 
230
231
  it('gets a note by id', function(done) {
231
- Note.getById(noteId, function(err, result) {
232
+ Note.getById(noteId, { CUSTOMER_ID: org._id }, function(err, result) {
232
233
  should.not.exist(err);
233
234
  should.exist(result);
234
235
  result.text.should.equal('Best note ever!');
@@ -238,7 +239,7 @@ describe('Note', function() {
238
239
 
239
240
  it('modifies a note by id', function (done) {
240
241
 
241
- Note.getById(noteId, function(err, note) {
242
+ Note.getById(noteId, { CUSTOMER_ID: org._id }, function(err, note) {
242
243
 
243
244
  should.not.exist(err);
244
245
  should.exist(note);
@@ -252,7 +253,7 @@ describe('Note', function() {
252
253
  }
253
254
  };
254
255
 
255
- Note.modifyById(noteId, update, function (err, result) {
256
+ Note.modifyById(noteId, update, { CUSTOMER_ID: org._id }, function (err, result) {
256
257
  should.not.exist(err);
257
258
  should.exist(result);
258
259
  result.createdBy.toString().should.equal(newCreatedBy.toString());
@@ -264,7 +265,7 @@ describe('Note', function() {
264
265
  });
265
266
 
266
267
  it('deletes a note', function(done) {
267
- Note.delete(noteId, function(err, result) {
268
+ Note.delete(noteId, org._id, function(err, result) {
268
269
  should.not.exist(err);
269
270
  should.exist(result);
270
271
  //result.id.should.equal(noteId.toString());