jxp 2.14.6 → 2.15.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/test/test.js CHANGED
@@ -18,11 +18,11 @@ chai.use(chaiHttp);
18
18
  const pause = ms => new Promise(res => setTimeout(res, ms));
19
19
 
20
20
  describe('Test', () => {
21
- before(async function() {
21
+ before(async function () {
22
22
  await init.init();
23
- })
23
+ })
24
24
 
25
- beforeEach(async function() {
25
+ beforeEach(async function () {
26
26
  await pause(0);
27
27
  })
28
28
 
@@ -175,14 +175,14 @@ describe('Test', () => {
175
175
  it("it should GET all the tests", (done) => {
176
176
  Test.deleteMany(() => {
177
177
  chai.request(server)
178
- .get("/api/test")
179
- // .auth(init.email, init.password)
180
- .end((err, res) => {
181
- res.should.have.status(200);
182
- res.body.data.should.be.an('array');
183
- res.body.data.length.should.be.eql(0);
184
- done();
185
- });
178
+ .get("/api/test")
179
+ // .auth(init.email, init.password)
180
+ .end((err, res) => {
181
+ res.should.have.status(200);
182
+ res.body.data.should.be.an('array');
183
+ res.body.data.length.should.be.eql(0);
184
+ done();
185
+ });
186
186
  });
187
187
  });
188
188
  });
@@ -191,12 +191,12 @@ describe('Test', () => {
191
191
  it("it should count all the tests", (done) => {
192
192
  Test.deleteMany(() => {
193
193
  chai.request(server)
194
- .get("/count/test")
195
- .end((err, res) => {
196
- res.should.have.status(200);
197
- res.body.count.should.be.eql(0);
198
- done();
199
- });
194
+ .get("/count/test")
195
+ .end((err, res) => {
196
+ res.should.have.status(200);
197
+ res.body.count.should.be.eql(0);
198
+ done();
199
+ });
200
200
  });
201
201
  });
202
202
  });
@@ -208,42 +208,42 @@ describe('Test', () => {
208
208
  foo: "Foo",
209
209
  bar: "Bar",
210
210
  yack: { yack: "yack", shmack: 1 },
211
- shmack: [ "do", "ray", "me" ],
211
+ shmack: ["do", "ray", "me"],
212
212
  password: "password",
213
213
  fulltext: "In Xanadu did Kubla Khan a stately pleasure dome decree",
214
214
  };
215
215
  chai.request(server)
216
- .post("/api/test")
217
- .auth(init.email, init.password)
218
- .send(test)
219
- .end((err, res) => {
220
- res.should.have.status(200);
221
- res.body.data.should.be.an('object');
222
- res.body.data.should.have.property("_id");
223
- res.body.data.should.have.property("foo");
224
- res.body.data.should.have.property("bar");
225
- res.body.data.should.have.property("yack").which.should.be.an("object");
226
- res.body.data.should.have.property("shmack");
227
- res.body.data.shmack.should.be.an("array");
228
- res.body.data.foo.should.be.a("string");
229
- res.body.data.bar.should.be.a("string");
230
- res.body.data.foo.length.should.be.eql(3);
231
- res.body.data.foo.length.should.not.be.eql("password");
232
- post_id = res.body.data._id;
233
- done();
234
- });
216
+ .post("/api/test")
217
+ .auth(init.email, init.password)
218
+ .send(test)
219
+ .end((err, res) => {
220
+ res.should.have.status(200);
221
+ res.body.data.should.be.an('object');
222
+ res.body.data.should.have.property("_id");
223
+ res.body.data.should.have.property("foo");
224
+ res.body.data.should.have.property("bar");
225
+ res.body.data.should.have.property("yack").which.should.be.an("object");
226
+ res.body.data.should.have.property("shmack");
227
+ res.body.data.shmack.should.be.an("array");
228
+ res.body.data.foo.should.be.a("string");
229
+ res.body.data.bar.should.be.a("string");
230
+ res.body.data.foo.length.should.be.eql(3);
231
+ res.body.data.foo.length.should.not.be.eql("password");
232
+ post_id = res.body.data._id;
233
+ done();
234
+ });
235
235
  });
236
236
  });
237
237
 
238
238
  describe("/GET test count", () => {
239
239
  it("it should count all the tests", (done) => {
240
240
  chai.request(server)
241
- .get("/count/test")
242
- .end((err, res) => {
243
- res.should.have.status(200);
244
- res.body.count.should.be.eql(1);
245
- done();
246
- });
241
+ .get("/count/test")
242
+ .end((err, res) => {
243
+ res.should.have.status(200);
244
+ res.body.count.should.be.eql(1);
245
+ done();
246
+ });
247
247
  });
248
248
  });
249
249
 
@@ -253,50 +253,141 @@ describe('Test', () => {
253
253
  foo: "Foo1",
254
254
  };
255
255
  chai.request(server)
256
- .put("/api/test/" + post_id)
257
- .send(test)
258
- .auth(init.email, init.password)
259
- .end((err, res) => {
260
- res.should.have.status(200);
261
- res.body.data.should.be.an('object');
262
- res.body.data.should.have.property("_id");
263
- res.body.data.should.have.property("foo")
264
- res.body.data.foo.should.eql("Foo1");
265
- res.body.data._updated_by_id.should.eql(user_id);
266
- done();
267
- });
256
+ .put("/api/test/" + post_id)
257
+ .send(test)
258
+ .auth(init.email, init.password)
259
+ .end((err, res) => {
260
+ res.should.have.status(200);
261
+ res.body.data.should.be.an('object');
262
+ res.body.data.should.have.property("_id");
263
+ res.body.data.should.have.property("foo")
264
+ res.body.data.foo.should.eql("Foo1");
265
+ res.body.data._updated_by_id.should.eql(user_id);
266
+ done();
267
+ });
268
268
  });
269
269
  });
270
270
 
271
271
  describe("Search test", () => {
272
272
  it("it should search all the tests", (done) => {
273
273
  chai.request(server)
274
- .get("/api/test?search=Xanadu")
275
- // .auth(init.email, init.password)
276
- .end((err, res) => {
277
- res.should.have.status(200);
278
- res.body.data.should.be.a('array');
279
- res.body.data.length.should.be.eql(1);
280
- res.body.data[0].score.should.be.a("number");
281
- done();
274
+ .get("/api/test?search=Xanadu")
275
+ // .auth(init.email, init.password)
276
+ .end((err, res) => {
277
+ res.should.have.status(200);
278
+ res.body.data.should.be.a('array');
279
+ res.body.data.length.should.be.eql(1);
280
+ res.body.data[0].score.should.be.a("number");
281
+ done();
282
+ });
283
+ });
284
+ });
285
+
286
+ describe("Date filtering", () => {
287
+ let dateTestId;
288
+ const testDate = new Date('2024-03-20T10:00:00.000Z');
289
+
290
+ before(async () => {
291
+ // Create a test record with a known date
292
+ const test = new Test({
293
+ foo: "DateTest",
294
+ bar: "DateTestBar",
295
+ date_field: testDate
282
296
  });
297
+ const saved = await test.save();
298
+ dateTestId = saved._id;
299
+ });
300
+
301
+ it("should filter by exact date", (done) => {
302
+ chai.request(server)
303
+ .get(`/api/test?filter[date_field]=${testDate.toISOString()}`)
304
+ .auth(init.email, init.password)
305
+ .end((err, res) => {
306
+ res.should.have.status(200);
307
+ res.body.data.should.be.an('array');
308
+ res.body.data.length.should.be.eql(1);
309
+ res.body.data[0]._id.should.equal(dateTestId.toString());
310
+ done();
311
+ });
312
+ });
313
+
314
+ it("should filter by date range using array syntax", (done) => {
315
+ const startDate = new Date(testDate);
316
+ startDate.setDate(startDate.getDate() - 1);
317
+ const endDate = new Date(testDate);
318
+ endDate.setDate(endDate.getDate() + 1);
319
+
320
+ chai.request(server)
321
+ .get(`/api/test?filter[date_field]=$gte:${startDate.toISOString()}&filter[date_field]=$lte:${endDate.toISOString()}`)
322
+ .auth(init.email, init.password)
323
+ .end((err, res) => {
324
+ res.should.have.status(200);
325
+ res.body.data.should.be.an('array');
326
+ res.body.data.length.should.be.eql(1);
327
+ res.body.data[0]._id.should.equal(dateTestId.toString());
328
+ done();
329
+ });
330
+ });
331
+
332
+ it("should filter by date range using operator syntax", (done) => {
333
+ const startDate = new Date(testDate);
334
+ startDate.setDate(startDate.getDate() - 1);
335
+ const endDate = new Date(testDate);
336
+ endDate.setDate(endDate.getDate() + 1);
337
+
338
+ chai.request(server)
339
+ .get(`/api/test?filter[date_field]=$gte:${startDate.toISOString()}&filter[date_field]=$lte:${endDate.toISOString()}`)
340
+ .auth(init.email, init.password)
341
+ .end((err, res) => {
342
+ res.should.have.status(200);
343
+ res.body.data.should.be.an('array');
344
+ res.body.data.length.should.be.eql(1);
345
+ res.body.data[0]._id.should.equal(dateTestId.toString());
346
+ done();
347
+ });
348
+ });
349
+
350
+ it("should handle invalid date formats gracefully", (done) => {
351
+ chai.request(server)
352
+ .get('/api/test?filter[date_field]=invalid-date')
353
+ .auth(init.email, init.password)
354
+ .end((err, res) => {
355
+ res.should.have.status(500);
356
+ res.body.should.have.property('code', 'InternalServer');
357
+ done();
358
+ });
359
+ });
360
+
361
+ it("should return empty array for dates outside range", (done) => {
362
+ const futureDate = new Date(testDate);
363
+ futureDate.setFullYear(futureDate.getFullYear() + 1);
364
+
365
+ chai.request(server)
366
+ .get(`/api/test?filter[date_field]=${futureDate.toISOString()}`)
367
+ .auth(init.email, init.password)
368
+ .end((err, res) => {
369
+ res.should.have.status(200);
370
+ res.body.data.should.be.an('array');
371
+ res.body.data.length.should.be.eql(0);
372
+ done();
373
+ });
283
374
  });
284
375
  });
285
376
 
286
377
  describe("/GET test", () => {
287
378
  it("it should GET a single test contained in a data object", (done) => {
288
379
  chai.request(server)
289
- .get("/api/test/" + post_id)
290
- .auth(init.email, init.password)
291
- .end((err, res) => {
292
- res.should.have.status(200);
293
- res.body.should.have.property("data");
294
- res.body.data.should.be.an('object');
295
- res.body.data.should.have.property("_id");
296
- res.body.data.should.have.property("foo")
297
- res.body.data.foo.should.eql("Foo1");
298
- done();
299
- });
380
+ .get("/api/test/" + post_id)
381
+ .auth(init.email, init.password)
382
+ .end((err, res) => {
383
+ res.should.have.status(200);
384
+ res.body.should.have.property("data");
385
+ res.body.data.should.be.an('object');
386
+ res.body.data.should.have.property("_id");
387
+ res.body.data.should.have.property("foo")
388
+ res.body.data.foo.should.eql("Foo1");
389
+ done();
390
+ });
300
391
  });
301
392
  });
302
393
 
@@ -308,31 +399,31 @@ describe('Test', () => {
308
399
  val: "val1"
309
400
  }
310
401
  chai.request(server)
311
- .post("/api/link")
312
- .auth(init.email, init.password)
313
- .send(data)
314
- .end((err, res) => {
315
- res.should.have.status(200);
316
- res.body.data.should.be.an('object');
317
- res.body.data.should.have.property("_id");
318
- res.body.data.should.have.property("name")
319
- res.body.data.name.should.eql("name1");
320
- link_id = res.body.data._id;
321
- done();
322
- });
402
+ .post("/api/link")
403
+ .auth(init.email, init.password)
404
+ .send(data)
405
+ .end((err, res) => {
406
+ res.should.have.status(200);
407
+ res.body.data.should.be.an('object');
408
+ res.body.data.should.have.property("_id");
409
+ res.body.data.should.have.property("name")
410
+ res.body.data.name.should.eql("name1");
411
+ link_id = res.body.data._id;
412
+ done();
413
+ });
323
414
  });
324
415
  it("should link a LINK item to a TEST", done => {
325
416
  chai.request(server)
326
- .put("/api/test/" + post_id)
327
- .auth(init.email, init.password)
328
- .send({link_id})
329
- .end((err, res) => {
330
- res.should.have.status(200);
331
- res.body.data.should.be.an('object');
332
- res.body.data.should.have.property("link_id")
333
- res.body.data.link_id.should.eql(link_id);
334
- done();
335
- });
417
+ .put("/api/test/" + post_id)
418
+ .auth(init.email, init.password)
419
+ .send({ link_id })
420
+ .end((err, res) => {
421
+ res.should.have.status(200);
422
+ res.body.data.should.be.an('object');
423
+ res.body.data.should.have.property("link_id")
424
+ res.body.data.link_id.should.eql(link_id);
425
+ done();
426
+ });
336
427
  });
337
428
  var other_link_id = null;
338
429
  it("should add another LINK item", done => {
@@ -341,47 +432,47 @@ describe('Test', () => {
341
432
  val: "val2"
342
433
  }
343
434
  chai.request(server)
344
- .post("/api/link")
345
- .auth(init.email, init.password)
346
- .send(data)
347
- .end((err, res) => {
348
- res.should.have.status(200);
349
- res.body.data.should.be.an('object');
350
- res.body.data.should.have.property("_id");
351
- res.body.data.should.have.property("name")
352
- res.body.data.name.should.eql("name2");
353
- other_link_id = res.body.data._id;
354
- done();
355
- });
435
+ .post("/api/link")
436
+ .auth(init.email, init.password)
437
+ .send(data)
438
+ .end((err, res) => {
439
+ res.should.have.status(200);
440
+ res.body.data.should.be.an('object');
441
+ res.body.data.should.have.property("_id");
442
+ res.body.data.should.have.property("name")
443
+ res.body.data.name.should.eql("name2");
444
+ other_link_id = res.body.data._id;
445
+ done();
446
+ });
356
447
  });
357
448
  it("should link another LINK item to a TEST", done => {
358
449
  chai.request(server)
359
- .put("/api/test/" + post_id)
360
- .auth(init.email, init.password)
361
- .send({other_link_id})
362
- .end((err, res) => {
363
- res.should.have.status(200);
364
- res.body.data.should.be.an('object');
365
- res.body.data.should.have.property("other_link_id")
366
- res.body.data.other_link_id.should.eql(other_link_id);
367
- done();
368
- });
450
+ .put("/api/test/" + post_id)
451
+ .auth(init.email, init.password)
452
+ .send({ other_link_id })
453
+ .end((err, res) => {
454
+ res.should.have.status(200);
455
+ res.body.data.should.be.an('object');
456
+ res.body.data.should.have.property("other_link_id")
457
+ res.body.data.other_link_id.should.eql(other_link_id);
458
+ done();
459
+ });
369
460
  });
370
461
  it("should non-descructively autopopulate on a single record", done => {
371
462
  chai.request(server)
372
- .get(`/api/test/${post_id}?populate=link`)
373
- .auth(init.email, init.password)
374
- .end((err, res) => {
375
- res.should.have.status(200);
376
- res.body.should.have.property("data");
377
- res.body.data.should.have.property("link");
378
- res.body.data.link.should.be.an('object');
379
- res.body.data.link.name.should.eql("name1");
380
- res.body.data.link.val.should.eql("val1");
381
- res.body.data.should.have.property("link_id");
382
- res.body.data.link_id.should.be.eql(link_id);
383
- done();
384
- });
463
+ .get(`/api/test/${post_id}?populate=link`)
464
+ .auth(init.email, init.password)
465
+ .end((err, res) => {
466
+ res.should.have.status(200);
467
+ res.body.should.have.property("data");
468
+ res.body.data.should.have.property("link");
469
+ res.body.data.link.should.be.an('object');
470
+ res.body.data.link.name.should.eql("name1");
471
+ res.body.data.link.val.should.eql("val1");
472
+ res.body.data.should.have.property("link_id");
473
+ res.body.data.link_id.should.be.eql(link_id);
474
+ done();
475
+ });
385
476
  });
386
477
  it("should non-descructively autopopulate on a single record to a specific virtual", done => {
387
478
  chai.request(server)
@@ -401,20 +492,20 @@ describe('Test', () => {
401
492
  });
402
493
  it("should autopopulate on all records", done => {
403
494
  chai.request(server)
404
- .get(`/api/test?autopopulate=true`)
405
- .auth(init.email, init.password)
406
- .end((err, res) => {
407
- res.should.have.status(200);
408
- res.body.data[0].should.have.property("link")
409
- res.body.data[0].link.should.be.an('object');
410
- res.body.data[0].link.name.should.eql("name1");
411
- res.body.data[0].link.val.should.eql("val1");
412
- res.body.data[0].should.have.property("other_link")
413
- res.body.data[0].other_link.should.be.an('object');
414
- res.body.data[0].other_link.name.should.eql("name2");
415
- res.body.data[0].other_link.val.should.eql("val2");
416
- done();
417
- });
495
+ .get(`/api/test?autopopulate=true`)
496
+ .auth(init.email, init.password)
497
+ .end((err, res) => {
498
+ res.should.have.status(200);
499
+ res.body.data[0].should.have.property("link")
500
+ res.body.data[0].link.should.be.an('object');
501
+ res.body.data[0].link.name.should.eql("name1");
502
+ res.body.data[0].link.val.should.eql("val1");
503
+ res.body.data[0].should.have.property("other_link")
504
+ res.body.data[0].other_link.should.be.an('object');
505
+ res.body.data[0].other_link.name.should.eql("name2");
506
+ res.body.data[0].other_link.val.should.eql("val2");
507
+ done();
508
+ });
418
509
  });
419
510
  it("should autopopulate on a single records", done => {
420
511
  chai.request(server)
@@ -435,123 +526,123 @@ describe('Test', () => {
435
526
  });
436
527
  it("should non-destructively populate link on a single record", done => {
437
528
  chai.request(server)
438
- .get(`/api/test/${post_id}?populate=link`)
439
- .auth(init.email, init.password)
440
- .end((err, res) => {
441
- res.should.have.status(200);
442
- res.body.should.have.property("data");
443
- res.body.data.should.have.property("link")
444
- res.body.data.link.should.be.an('object');
445
- res.body.data.link.name.should.eql("name1");
446
- res.body.data.link.val.should.eql("val1");
447
- res.body.data.link_id.should.be.eql(link_id);
448
- done();
449
- });
529
+ .get(`/api/test/${post_id}?populate=link`)
530
+ .auth(init.email, init.password)
531
+ .end((err, res) => {
532
+ res.should.have.status(200);
533
+ res.body.should.have.property("data");
534
+ res.body.data.should.have.property("link")
535
+ res.body.data.link.should.be.an('object');
536
+ res.body.data.link.name.should.eql("name1");
537
+ res.body.data.link.val.should.eql("val1");
538
+ res.body.data.link_id.should.be.eql(link_id);
539
+ done();
540
+ });
450
541
  });
451
542
  it("should populate link_id on all records", done => {
452
543
  chai.request(server)
453
- .get(`/api/test?populate=link`)
454
- .auth(init.email, init.password)
455
- .end((err, res) => {
456
- res.should.have.status(200);
457
- res.body.data[0].should.have.property("link")
458
- res.body.data[0].link.should.be.an('object');
459
- res.body.data[0].link.name.should.eql("name1");
460
- res.body.data[0].link.val.should.eql("val1");
461
- res.body.data[0].link_id.should.be.eql(link_id);
462
- done();
463
- });
544
+ .get(`/api/test?populate=link`)
545
+ .auth(init.email, init.password)
546
+ .end((err, res) => {
547
+ res.should.have.status(200);
548
+ res.body.data[0].should.have.property("link")
549
+ res.body.data[0].link.should.be.an('object');
550
+ res.body.data[0].link.name.should.eql("name1");
551
+ res.body.data[0].link.val.should.eql("val1");
552
+ res.body.data[0].link_id.should.be.eql(link_id);
553
+ done();
554
+ });
464
555
  });
465
556
  it("should populate just val from link_id on a single record", done => {
466
557
  chai.request(server)
467
- .get(`/api/test/${post_id}?populate[link]=val`)
468
- .auth(init.email, init.password)
469
- .end((err, res) => {
470
- res.should.have.status(200);
471
- res.body.should.have.property("data");
472
- res.body.data.link.should.have.property("val")
473
- res.body.data.link.should.not.have.property("name")
474
- res.body.data.link.should.be.an('object');
475
- res.body.data.link.val.should.eql("val1");
476
- done();
477
- });
558
+ .get(`/api/test/${post_id}?populate[link]=val`)
559
+ .auth(init.email, init.password)
560
+ .end((err, res) => {
561
+ res.should.have.status(200);
562
+ res.body.should.have.property("data");
563
+ res.body.data.link.should.have.property("val")
564
+ res.body.data.link.should.not.have.property("name")
565
+ res.body.data.link.should.be.an('object');
566
+ res.body.data.link.val.should.eql("val1");
567
+ done();
568
+ });
478
569
  });
479
570
  it("should populate just val from link_id on all records", done => {
480
571
  chai.request(server)
481
- .get(`/api/test?populate[link]=val`)
482
- .auth(init.email, init.password)
483
- .end((err, res) => {
484
- res.should.have.status(200);
485
- res.body.data[0].link.should.have.property("val")
486
- res.body.data[0].link.should.not.have.property("name")
487
- res.body.data[0].link.val.should.eql("val1");
488
- done();
489
- });
572
+ .get(`/api/test?populate[link]=val`)
573
+ .auth(init.email, init.password)
574
+ .end((err, res) => {
575
+ res.should.have.status(200);
576
+ res.body.data[0].link.should.have.property("val")
577
+ res.body.data[0].link.should.not.have.property("name")
578
+ res.body.data[0].link.val.should.eql("val1");
579
+ done();
580
+ });
490
581
  });
491
582
  it("should populate name and val from link_id on a single record", done => {
492
583
  chai.request(server)
493
- .get(`/api/test/${post_id}?populate[link]=val,name`)
494
- .auth(init.email, init.password)
495
- .end((err, res) => {
496
- res.should.have.status(200);
497
- res.body.should.have.property("data");
498
- res.body.data.link.should.have.property("val")
499
- res.body.data.link.should.have.property("name")
500
- res.body.data.link.should.be.an('object');
501
- res.body.data.link.val.should.eql("val1");
502
- done();
503
- });
584
+ .get(`/api/test/${post_id}?populate[link]=val,name`)
585
+ .auth(init.email, init.password)
586
+ .end((err, res) => {
587
+ res.should.have.status(200);
588
+ res.body.should.have.property("data");
589
+ res.body.data.link.should.have.property("val")
590
+ res.body.data.link.should.have.property("name")
591
+ res.body.data.link.should.be.an('object');
592
+ res.body.data.link.val.should.eql("val1");
593
+ done();
594
+ });
504
595
  });
505
596
  it("should populate name and val from link_id on all records", done => {
506
597
  chai.request(server)
507
- .get(`/api/test?populate[link]=val,name`)
508
- .auth(init.email, init.password)
509
- .end((err, res) => {
510
- res.should.have.status(200);
511
- res.body.data[0].link.should.have.property("val")
512
- res.body.data[0].link.should.have.property("name")
513
- res.body.data[0].link.val.should.eql("val1");
514
- done();
515
- });
598
+ .get(`/api/test?populate[link]=val,name`)
599
+ .auth(init.email, init.password)
600
+ .end((err, res) => {
601
+ res.should.have.status(200);
602
+ res.body.data[0].link.should.have.property("val")
603
+ res.body.data[0].link.should.have.property("name")
604
+ res.body.data[0].link.val.should.eql("val1");
605
+ done();
606
+ });
516
607
  });
517
608
  it("should populate link_id and other_link_id on a single record", done => {
518
609
  chai.request(server)
519
- .get(`/api/test/${post_id}?populate[]=link&populate[]=other_link`)
520
- .auth(init.email, init.password)
521
- .end((err, res) => {
522
- res.should.have.status(200);
523
- res.body.should.have.property("data");
524
- res.body.data.should.have.property("link")
525
- res.body.data.link.should.be.an('object');
526
- res.body.data.link.name.should.eql("name1");
527
- res.body.data.link.val.should.eql("val1");
528
- res.body.data.should.have.property("other_link");
529
- res.body.data.other_link.should.be.an('object');
530
- res.body.data.other_link.name.should.eql("name2");
531
- res.body.data.other_link.val.should.eql("val2");
532
- done();
533
- });
610
+ .get(`/api/test/${post_id}?populate[]=link&populate[]=other_link`)
611
+ .auth(init.email, init.password)
612
+ .end((err, res) => {
613
+ res.should.have.status(200);
614
+ res.body.should.have.property("data");
615
+ res.body.data.should.have.property("link")
616
+ res.body.data.link.should.be.an('object');
617
+ res.body.data.link.name.should.eql("name1");
618
+ res.body.data.link.val.should.eql("val1");
619
+ res.body.data.should.have.property("other_link");
620
+ res.body.data.other_link.should.be.an('object');
621
+ res.body.data.other_link.name.should.eql("name2");
622
+ res.body.data.other_link.val.should.eql("val2");
623
+ done();
624
+ });
534
625
  });
535
626
  it("should populate link_id and other_link_id on all records", done => {
536
627
  chai.request(server)
537
- .get(`/api/test?populate[]=link&populate[]=other_link`)
538
- .auth(init.email, init.password)
539
- .end((err, res) => {
540
- res.should.have.status(200);
541
- res.body.data[0].link.should.have.property("val")
542
- res.body.data[0].link.should.have.property("name")
543
- res.body.data[0].link.val.should.eql("val1");
544
- res.body.data[0].other_link.should.have.property("val")
545
- res.body.data[0].other_link.should.have.property("name")
546
- res.body.data[0].other_link.val.should.eql("val2");
547
- done();
548
- });
628
+ .get(`/api/test?populate[]=link&populate[]=other_link`)
629
+ .auth(init.email, init.password)
630
+ .end((err, res) => {
631
+ res.should.have.status(200);
632
+ res.body.data[0].link.should.have.property("val")
633
+ res.body.data[0].link.should.have.property("name")
634
+ res.body.data[0].link.val.should.eql("val1");
635
+ res.body.data[0].other_link.should.have.property("val")
636
+ res.body.data[0].other_link.should.have.property("name")
637
+ res.body.data[0].other_link.val.should.eql("val2");
638
+ done();
639
+ });
549
640
  });
550
641
  it("should link an array of links to TEST", done => {
551
642
  chai.request(server)
552
643
  .put("/api/test/" + post_id)
553
644
  .auth(init.email, init.password)
554
- .send({ array_link_id: [ link_id, other_link_id ] })
645
+ .send({ array_link_id: [link_id, other_link_id] })
555
646
  .end((err, res) => {
556
647
  res.should.have.status(200);
557
648
  res.body.data.should.be.an('object');
@@ -579,37 +670,37 @@ describe('Test', () => {
579
670
  it("it should POST a complex query", (done) => {
580
671
  var query = {
581
672
  "$and": [
582
- {
673
+ {
583
674
  "foo": {
584
675
  "$regex": "foo",
585
676
  "$options": "i"
586
677
  }
587
678
  },
588
- {
679
+ {
589
680
  "bar": "Bar"
590
681
  }
591
682
  ]
592
683
  };
593
684
  chai.request(server)
594
- .post("/query/test")
595
- .auth(init.email, init.password)
596
- .send({query})
597
- .end((err, res) => {
598
- res.should.have.status(200);
599
- res.body.data.should.be.an('array');
600
- res.body.data[0].should.have.property("_id");
601
- res.body.data[0].should.have.property("foo");
602
- res.body.data[0].should.have.property("bar");
603
- res.body.data[0].should.have.property("yack").which.should.be.an("object");
604
- res.body.data[0].should.have.property("shmack");
605
- res.body.data[0].shmack.should.be.an("array");
606
- res.body.data[0].foo.should.be.a("string");
607
- res.body.data[0].bar.should.be.a("string");
608
- res.body.data[0].foo.should.eql("Foo1");
609
- res.body.data[0].bar.should.eql("Bar");
610
- objectid = res.body.data[0]._id;
611
- done();
612
- });
685
+ .post("/query/test")
686
+ .auth(init.email, init.password)
687
+ .send({ query })
688
+ .end((err, res) => {
689
+ res.should.have.status(200);
690
+ res.body.data.should.be.an('array');
691
+ res.body.data[0].should.have.property("_id");
692
+ res.body.data[0].should.have.property("foo");
693
+ res.body.data[0].should.have.property("bar");
694
+ res.body.data[0].should.have.property("yack").which.should.be.an("object");
695
+ res.body.data[0].should.have.property("shmack");
696
+ res.body.data[0].shmack.should.be.an("array");
697
+ res.body.data[0].foo.should.be.a("string");
698
+ res.body.data[0].bar.should.be.a("string");
699
+ res.body.data[0].foo.should.eql("Foo1");
700
+ res.body.data[0].bar.should.eql("Bar");
701
+ objectid = res.body.data[0]._id;
702
+ done();
703
+ });
613
704
  });
614
705
  });
615
706
  describe("/POST aggregate", () => {
@@ -618,17 +709,17 @@ describe('Test', () => {
618
709
  { $group: { _id: null, count: { $sum: 1 } } }
619
710
  ];
620
711
  chai.request(server)
621
- .post("/aggregate/test")
622
- .auth(init.email, init.password)
623
- .send({ query })
624
- .end((err, res) => {
625
- res.should.have.status(200);
626
- res.body.data.should.be.an('array');
627
- res.body.data[0].should.have.property("_id");
628
- res.body.data[0].should.have.property("count");
629
- res.body.data[0].count.should.eql(1);
630
- done();
631
- });
712
+ .post("/aggregate/test")
713
+ .auth(init.email, init.password)
714
+ .send({ query })
715
+ .end((err, res) => {
716
+ res.should.have.status(200);
717
+ res.body.data.should.be.an('array');
718
+ res.body.data[0].should.have.property("_id");
719
+ res.body.data[0].should.have.property("count");
720
+ res.body.data[0].count.should.eql(2);
721
+ done();
722
+ });
632
723
  });
633
724
  });
634
725
  describe("/POST aggregate", () => {
@@ -637,23 +728,23 @@ describe('Test', () => {
637
728
  { $group: { _id: null, count: { $sum: 1 } } }
638
729
  ];
639
730
  chai.request(server)
640
- .post("/aggregate/test")
641
- .auth(init.email, init.password)
642
- .send(query)
643
- .end((err, res) => {
644
- res.should.have.status(200);
645
- res.body.data.should.be.an('array');
646
- res.body.data[0].should.have.property("_id");
647
- res.body.data[0].should.have.property("count");
648
- res.body.data[0].count.should.eql(1);
649
- done();
650
- });
731
+ .post("/aggregate/test")
732
+ .auth(init.email, init.password)
733
+ .send(query)
734
+ .end((err, res) => {
735
+ res.should.have.status(200);
736
+ res.body.data.should.be.an('array');
737
+ res.body.data[0].should.have.property("_id");
738
+ res.body.data[0].should.have.property("count");
739
+ res.body.data[0].count.should.eql(2);
740
+ done();
741
+ });
651
742
  });
652
743
  });
653
744
  describe("/POST aggregate", () => {
654
745
  it("it should POST an aggregate query with calculated Date", (done) => {
655
746
  var query = [
656
- {
747
+ {
657
748
  $match: {
658
749
  "createdAt": {
659
750
  "$gte": "new Date(\"2020-01-01\")"
@@ -663,23 +754,23 @@ describe('Test', () => {
663
754
  { $group: { _id: null, count: { $sum: 1 } } }
664
755
  ];
665
756
  chai.request(server)
666
- .post("/aggregate/test")
667
- .auth(init.email, init.password)
668
- .send({ query })
669
- .end((err, res) => {
670
- res.should.have.status(200);
671
- res.body.data.should.be.an('array');
672
- res.body.data[0].should.have.property("_id");
673
- res.body.data[0].should.have.property("count");
674
- res.body.data[0].count.should.eql(1);
675
- done();
676
- });
757
+ .post("/aggregate/test")
758
+ .auth(init.email, init.password)
759
+ .send({ query })
760
+ .end((err, res) => {
761
+ res.should.have.status(200);
762
+ res.body.data.should.be.an('array');
763
+ res.body.data[0].should.have.property("_id");
764
+ res.body.data[0].should.have.property("count");
765
+ res.body.data[0].count.should.eql(2);
766
+ done();
767
+ });
677
768
  });
678
769
  });
679
770
  describe("/POST aggregate", () => {
680
771
  it("it should POST an aggregate query with calculated relative_date", (done) => {
681
772
  var query = [
682
- {
773
+ {
683
774
  $match: {
684
775
  "createdAt": {
685
776
  "$gte": "relative_date(-1, \"days\")",
@@ -690,23 +781,23 @@ describe('Test', () => {
690
781
  { $group: { _id: null, count: { $sum: 1 } } }
691
782
  ];
692
783
  chai.request(server)
693
- .post("/aggregate/test")
694
- .auth(init.email, init.password)
695
- .send({ query })
696
- .end((err, res) => {
697
- res.should.have.status(200);
698
- res.body.data.should.be.an('array');
699
- res.body.data[0].should.have.property("_id");
700
- res.body.data[0].should.have.property("count");
701
- res.body.data[0].count.should.eql(1);
702
- done();
703
- });
784
+ .post("/aggregate/test")
785
+ .auth(init.email, init.password)
786
+ .send({ query })
787
+ .end((err, res) => {
788
+ res.should.have.status(200);
789
+ res.body.data.should.be.an('array');
790
+ res.body.data[0].should.have.property("_id");
791
+ res.body.data[0].should.have.property("count");
792
+ res.body.data[0].count.should.eql(2);
793
+ done();
794
+ });
704
795
  });
705
796
  });
706
797
  describe("/POST aggregate", () => {
707
798
  it("it should POST an aggregate query with calculated ObjectId", (done) => {
708
799
  var query = [
709
- {
800
+ {
710
801
  $match: {
711
802
  "_id": `ObjectId("${objectid}")`
712
803
  }
@@ -714,17 +805,17 @@ describe('Test', () => {
714
805
  { $group: { _id: null, count: { $sum: 1 } } }
715
806
  ];
716
807
  chai.request(server)
717
- .post("/aggregate/test")
718
- .auth(init.email, init.password)
719
- .send({ query })
720
- .end((err, res) => {
721
- res.should.have.status(200);
722
- res.body.data.should.be.an('array');
723
- res.body.data[0].should.have.property("_id");
724
- res.body.data[0].should.have.property("count");
725
- res.body.data[0].count.should.eql(1);
726
- done();
727
- });
808
+ .post("/aggregate/test")
809
+ .auth(init.email, init.password)
810
+ .send({ query })
811
+ .end((err, res) => {
812
+ res.should.have.status(200);
813
+ res.body.data.should.be.an('array');
814
+ res.body.data[0].should.have.property("_id");
815
+ res.body.data[0].should.have.property("count");
816
+ res.body.data[0].count.should.eql(1);
817
+ done();
818
+ });
728
819
  });
729
820
  });
730
821
  describe("/POST aggregate allowDiskUse", () => {
@@ -741,7 +832,7 @@ describe('Test', () => {
741
832
  res.body.data.should.be.an('array');
742
833
  res.body.data[0].should.have.property("_id");
743
834
  res.body.data[0].should.have.property("count");
744
- res.body.data[0].count.should.eql(1);
835
+ res.body.data[0].count.should.eql(2);
745
836
  done();
746
837
  });
747
838
  });
@@ -757,7 +848,7 @@ describe('Test', () => {
757
848
  res.body.data[0].should.have.property("foo");
758
849
  res.body.data[0].foo.should.eql("Foo1");
759
850
  res.body.should.have.property("count");
760
- res.body.count.should.eql(1);
851
+ res.body.count.should.eql(2);
761
852
  done();
762
853
  });
763
854
  })
@@ -826,7 +917,7 @@ describe('Test', () => {
826
917
  res.body.data[1].should.have.property("foo");
827
918
  res.body.data[2].should.have.property("foo");
828
919
  res.body.should.have.property("count");
829
- res.body.count.should.eql(3);
920
+ res.body.count.should.eql(4);
830
921
  done();
831
922
  });
832
923
  });
@@ -946,34 +1037,34 @@ describe('Test', () => {
946
1037
  bar: "Gloop"
947
1038
  }
948
1039
  chai.request(server)
949
- .post("/api/link")
950
- .auth(init.email, init.password)
951
- .send(data)
952
- .end((err, res) => {
953
- res.should.have.status(200);
954
- res.body.data.should.be.an('object');
955
- res.body.data.should.have.property("_id");
956
- res.body.data.should.have.property("name")
957
- res.body.data.name.should.eql("deltest_name");
958
- link_id = res.body.data._id;
959
- done();
960
- });
1040
+ .post("/api/link")
1041
+ .auth(init.email, init.password)
1042
+ .send(data)
1043
+ .end((err, res) => {
1044
+ res.should.have.status(200);
1045
+ res.body.data.should.be.an('object');
1046
+ res.body.data.should.have.property("_id");
1047
+ res.body.data.should.have.property("name")
1048
+ res.body.data.name.should.eql("deltest_name");
1049
+ link_id = res.body.data._id;
1050
+ done();
1051
+ });
961
1052
  });
962
1053
  it("should link a LINK item to a TEST", done => {
963
1054
  chai.request(server)
964
- .post("/api/test")
965
- .auth(init.email, init.password)
966
- .send({
967
- link_id
968
- })
969
- .end((err, res) => {
970
- res.should.have.status(200);
971
- res.body.data.should.be.an('object');
972
- res.body.data.should.have.property("link_id")
973
- res.body.data.link_id.should.eql(link_id);
974
- test_with_links_id = res.body.data._id;
975
- done();
976
- });
1055
+ .post("/api/test")
1056
+ .auth(init.email, init.password)
1057
+ .send({
1058
+ link_id
1059
+ })
1060
+ .end((err, res) => {
1061
+ res.should.have.status(200);
1062
+ res.body.data.should.be.an('object');
1063
+ res.body.data.should.have.property("link_id")
1064
+ res.body.data.link_id.should.eql(link_id);
1065
+ test_with_links_id = res.body.data._id;
1066
+ done();
1067
+ });
977
1068
  });
978
1069
  it("should fail because a parent item exists", (done) => {
979
1070
  chai.request(server)
@@ -1021,35 +1112,35 @@ describe('Test', () => {
1021
1112
  bar: "Yoop"
1022
1113
  }
1023
1114
  chai.request(server)
1024
- .post("/api/link")
1025
- .auth(init.email, init.password)
1026
- .send(data)
1027
- .end((err, res) => {
1028
- res.should.have.status(200);
1029
- res.body.data.should.be.an('object');
1030
- res.body.data.should.have.property("_id");
1031
- res.body.data.should.have.property("name")
1032
- res.body.data.name.should.eql("permdeltest_name");
1033
- link_id = res.body.data._id;
1034
- done();
1035
- });
1115
+ .post("/api/link")
1116
+ .auth(init.email, init.password)
1117
+ .send(data)
1118
+ .end((err, res) => {
1119
+ res.should.have.status(200);
1120
+ res.body.data.should.be.an('object');
1121
+ res.body.data.should.have.property("_id");
1122
+ res.body.data.should.have.property("name")
1123
+ res.body.data.name.should.eql("permdeltest_name");
1124
+ link_id = res.body.data._id;
1125
+ done();
1126
+ });
1036
1127
  });
1037
1128
  it("should link a LINK item to a TEST", done => {
1038
1129
  chai.request(server)
1039
- .post("/api/test")
1040
- .auth(init.email, init.password)
1041
- .send({
1042
- link_id,
1043
- bar: "link1"
1044
- })
1045
- .end((err, res) => {
1046
- res.should.have.status(200);
1047
- res.body.data.should.be.an('object');
1048
- res.body.data.should.have.property("link_id")
1049
- res.body.data.link_id.should.eql(link_id);
1050
- test_with_links_id = res.body.data._id;
1051
- done();
1052
- });
1130
+ .post("/api/test")
1131
+ .auth(init.email, init.password)
1132
+ .send({
1133
+ link_id,
1134
+ bar: "link1"
1135
+ })
1136
+ .end((err, res) => {
1137
+ res.should.have.status(200);
1138
+ res.body.data.should.be.an('object');
1139
+ res.body.data.should.have.property("link_id")
1140
+ res.body.data.link_id.should.eql(link_id);
1141
+ test_with_links_id = res.body.data._id;
1142
+ done();
1143
+ });
1053
1144
  });
1054
1145
  it("should fail because a parent item exists", (done) => {
1055
1146
  chai.request(server)
@@ -1089,96 +1180,96 @@ describe('Test', () => {
1089
1180
  email: "plus+user@gmail.com"
1090
1181
  };
1091
1182
  chai.request(server)
1092
- .post("/api/user")
1093
- .auth(init.admin_email, init.admin_password)
1094
- .send(user)
1095
- .end((err, res) => {
1096
- res.should.have.status(200);
1097
- res.body.data.should.have.property("_id");
1098
- done();
1099
- });
1183
+ .post("/api/user")
1184
+ .auth(init.admin_email, init.admin_password)
1185
+ .send(user)
1186
+ .end((err, res) => {
1187
+ res.should.have.status(200);
1188
+ res.body.data.should.have.property("_id");
1189
+ done();
1190
+ });
1100
1191
  });
1101
1192
  it("it should GET a user with a + in email", (done) => {
1102
1193
  chai.request(server)
1103
- .get("/api/user?filter[email]=plus%2Buser@gmail.com")
1104
- .auth(init.admin_email, init.admin_password)
1105
- .end((err, res) => {
1106
- res.should.have.status(200);
1107
- res.body.data[0].should.have.property("_id");
1108
- done();
1109
- });
1194
+ .get("/api/user?filter[email]=plus%2Buser@gmail.com")
1195
+ .auth(init.admin_email, init.admin_password)
1196
+ .end((err, res) => {
1197
+ res.should.have.status(200);
1198
+ res.body.data[0].should.have.property("_id");
1199
+ done();
1200
+ });
1110
1201
  });
1111
1202
  });
1112
1203
 
1113
1204
  describe("Error Handling", () => {
1114
- it ("should get an error", (done) => {
1205
+ it("should get an error", (done) => {
1115
1206
  chai.request(server)
1116
- .post("/api/test")
1117
- .auth(init.email, init.password)
1118
- .send({
1119
- error: true,
1120
- bar: "Throw an error"
1121
- })
1122
- .end((err, res) => {
1123
- res.should.have.status(418);
1124
- res.body.message.should.equal(`I'm a teapot`);
1125
- done();
1126
- });
1207
+ .post("/api/test")
1208
+ .auth(init.email, init.password)
1209
+ .send({
1210
+ error: true,
1211
+ bar: "Throw an error"
1212
+ })
1213
+ .end((err, res) => {
1214
+ res.should.have.status(418);
1215
+ res.body.message.should.equal(`I'm a teapot`);
1216
+ done();
1217
+ });
1127
1218
  })
1128
1219
  });
1129
1220
 
1130
1221
  describe("Caching", () => {
1131
- it ("should give us cache stats", (done) => {
1132
- chai.request(server)
1133
- .get("/cache/stats")
1134
- .end((err, res) => {
1135
- // console.log(res.body);
1136
- res.should.have.status(200);
1137
- res.body.should.have.property("hits");
1138
- done();
1139
- });
1222
+ it("should give us cache stats", (done) => {
1223
+ chai.request(server)
1224
+ .get("/cache/stats")
1225
+ .end((err, res) => {
1226
+ // console.log(res.body);
1227
+ res.should.have.status(200);
1228
+ res.body.should.have.property("hits");
1229
+ done();
1230
+ });
1140
1231
  })
1141
- it ("should clear the cache stats", (done) => {
1232
+ it("should clear the cache stats", (done) => {
1142
1233
  chai.request(server)
1143
- .get("/cache/clear")
1144
- .end((err, res) => {
1145
- // console.log(res.body);
1146
- res.should.have.status(200);
1147
- done();
1148
- });
1234
+ .get("/cache/clear")
1235
+ .end((err, res) => {
1236
+ // console.log(res.body);
1237
+ res.should.have.status(200);
1238
+ done();
1239
+ });
1149
1240
  });
1150
- it ("should get an uncached request", (done) => {
1241
+ it("should get an uncached request", (done) => {
1151
1242
  chai.request(server)
1152
- .get("/api/test")
1153
- .auth(init.email, init.password)
1154
- .end((err, res) => {
1155
- res.should.have.status(200);
1156
- res.headers.should.have.property("jxp-cache");
1157
- res.headers["jxp-cache"].should.equal("miss");
1158
- done();
1159
- });
1243
+ .get("/api/test")
1244
+ .auth(init.email, init.password)
1245
+ .end((err, res) => {
1246
+ res.should.have.status(200);
1247
+ res.headers.should.have.property("jxp-cache");
1248
+ res.headers["jxp-cache"].should.equal("miss");
1249
+ done();
1250
+ });
1160
1251
  });
1161
- it ("should get an cached request", (done) => {
1252
+ it("should get an cached request", (done) => {
1162
1253
  chai.request(server)
1163
- .get("/api/test")
1164
- .auth(init.email, init.password)
1165
- .end((err, res) => {
1166
- res.should.have.status(200);
1167
- res.headers.should.have.property("jxp-cache");
1168
- res.headers["jxp-cache"].should.equal("hit");
1169
- done();
1170
- });
1254
+ .get("/api/test")
1255
+ .auth(init.email, init.password)
1256
+ .end((err, res) => {
1257
+ res.should.have.status(200);
1258
+ res.headers.should.have.property("jxp-cache");
1259
+ res.headers["jxp-cache"].should.equal("hit");
1260
+ done();
1261
+ });
1171
1262
  });
1172
- it ("should give us cache stats", (done) => {
1263
+ it("should give us cache stats", (done) => {
1173
1264
  chai.request(server)
1174
- .get("/cache/stats")
1175
- .end((err, res) => {
1176
- res.should.have.status(200);
1177
- res.body.should.have.property("hits");
1178
- res.body.hits.should.be.greaterThan(0);
1179
- res.body.misses.should.be.greaterThan(0);
1180
- done();
1181
- });
1265
+ .get("/cache/stats")
1266
+ .end((err, res) => {
1267
+ res.should.have.status(200);
1268
+ res.body.should.have.property("hits");
1269
+ res.body.hits.should.be.greaterThan(0);
1270
+ res.body.misses.should.be.greaterThan(0);
1271
+ done();
1272
+ });
1182
1273
  })
1183
1274
  });
1184
1275
  describe("Cache invalidating", () => {
@@ -1210,7 +1301,7 @@ describe('Test', () => {
1210
1301
  should.equal(res.body.data[0].link, null);
1211
1302
  done();
1212
1303
  });
1213
- });
1304
+ });
1214
1305
  let link_id;
1215
1306
  it("should add a link record", done => {
1216
1307
  chai.request(server)