jxp 2.15.0 → 2.16.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/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,65 @@ 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
+ });
236
+
237
+ it("it should POST a test with string_array", (done) => {
238
+ var test = {
239
+ foo: "FooArray",
240
+ bar: "BarArray",
241
+ string_array: ["one", "two", "three"]
242
+ };
243
+ chai.request(server)
244
+ .post("/api/test")
245
+ .auth(init.email, init.password)
246
+ .send(test)
247
+ .end((err, res) => {
248
+ res.should.have.status(200);
249
+ res.body.data.should.be.an('object');
250
+ res.body.data.should.have.property("string_array");
251
+ res.body.data.string_array.should.be.an("array");
252
+ res.body.data.string_array.should.have.length(3);
253
+ res.body.data.string_array[0].should.equal("one");
254
+ res.body.data.string_array[1].should.equal("two");
255
+ res.body.data.string_array[2].should.equal("three");
256
+ done();
257
+ });
235
258
  });
236
259
  });
237
260
 
238
261
  describe("/GET test count", () => {
239
262
  it("it should count all the tests", (done) => {
240
263
  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
- });
264
+ .get("/count/test")
265
+ .end((err, res) => {
266
+ res.should.have.status(200);
267
+ res.body.count.should.be.eql(2);
268
+ done();
269
+ });
247
270
  });
248
271
  });
249
272
 
@@ -253,50 +276,141 @@ describe('Test', () => {
253
276
  foo: "Foo1",
254
277
  };
255
278
  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
- });
279
+ .put("/api/test/" + post_id)
280
+ .send(test)
281
+ .auth(init.email, init.password)
282
+ .end((err, res) => {
283
+ res.should.have.status(200);
284
+ res.body.data.should.be.an('object');
285
+ res.body.data.should.have.property("_id");
286
+ res.body.data.should.have.property("foo")
287
+ res.body.data.foo.should.eql("Foo1");
288
+ res.body.data._updated_by_id.should.eql(user_id);
289
+ done();
290
+ });
268
291
  });
269
292
  });
270
293
 
271
294
  describe("Search test", () => {
272
295
  it("it should search all the tests", (done) => {
273
296
  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();
297
+ .get("/api/test?search=Xanadu")
298
+ // .auth(init.email, init.password)
299
+ .end((err, res) => {
300
+ res.should.have.status(200);
301
+ res.body.data.should.be.a('array');
302
+ res.body.data.length.should.be.eql(1);
303
+ res.body.data[0].score.should.be.a("number");
304
+ done();
305
+ });
306
+ });
307
+ });
308
+
309
+ describe("Date filtering", () => {
310
+ let dateTestId;
311
+ const testDate = new Date('2024-03-20T10:00:00.000Z');
312
+
313
+ before(async () => {
314
+ // Create a test record with a known date
315
+ const test = new Test({
316
+ foo: "DateTest",
317
+ bar: "DateTestBar",
318
+ date_field: testDate
282
319
  });
320
+ const saved = await test.save();
321
+ dateTestId = saved._id;
322
+ });
323
+
324
+ it("should filter by exact date", (done) => {
325
+ chai.request(server)
326
+ .get(`/api/test?filter[date_field]=${testDate.toISOString()}`)
327
+ .auth(init.email, init.password)
328
+ .end((err, res) => {
329
+ res.should.have.status(200);
330
+ res.body.data.should.be.an('array');
331
+ res.body.data.length.should.be.eql(1);
332
+ res.body.data[0]._id.should.equal(dateTestId.toString());
333
+ done();
334
+ });
335
+ });
336
+
337
+ it("should filter by date range using array syntax", (done) => {
338
+ const startDate = new Date(testDate);
339
+ startDate.setDate(startDate.getDate() - 1);
340
+ const endDate = new Date(testDate);
341
+ endDate.setDate(endDate.getDate() + 1);
342
+
343
+ chai.request(server)
344
+ .get(`/api/test?filter[date_field]=$gte:${startDate.toISOString()}&filter[date_field]=$lte:${endDate.toISOString()}`)
345
+ .auth(init.email, init.password)
346
+ .end((err, res) => {
347
+ res.should.have.status(200);
348
+ res.body.data.should.be.an('array');
349
+ res.body.data.length.should.be.eql(1);
350
+ res.body.data[0]._id.should.equal(dateTestId.toString());
351
+ done();
352
+ });
353
+ });
354
+
355
+ it("should filter by date range using operator syntax", (done) => {
356
+ const startDate = new Date(testDate);
357
+ startDate.setDate(startDate.getDate() - 1);
358
+ const endDate = new Date(testDate);
359
+ endDate.setDate(endDate.getDate() + 1);
360
+
361
+ chai.request(server)
362
+ .get(`/api/test?filter[date_field]=$gte:${startDate.toISOString()}&filter[date_field]=$lte:${endDate.toISOString()}`)
363
+ .auth(init.email, init.password)
364
+ .end((err, res) => {
365
+ res.should.have.status(200);
366
+ res.body.data.should.be.an('array');
367
+ res.body.data.length.should.be.eql(1);
368
+ res.body.data[0]._id.should.equal(dateTestId.toString());
369
+ done();
370
+ });
371
+ });
372
+
373
+ it("should handle invalid date formats gracefully", (done) => {
374
+ chai.request(server)
375
+ .get('/api/test?filter[date_field]=invalid-date')
376
+ .auth(init.email, init.password)
377
+ .end((err, res) => {
378
+ res.should.have.status(500);
379
+ res.body.should.have.property('code', 'InternalServer');
380
+ done();
381
+ });
382
+ });
383
+
384
+ it("should return empty array for dates outside range", (done) => {
385
+ const futureDate = new Date(testDate);
386
+ futureDate.setFullYear(futureDate.getFullYear() + 1);
387
+
388
+ chai.request(server)
389
+ .get(`/api/test?filter[date_field]=${futureDate.toISOString()}`)
390
+ .auth(init.email, init.password)
391
+ .end((err, res) => {
392
+ res.should.have.status(200);
393
+ res.body.data.should.be.an('array');
394
+ res.body.data.length.should.be.eql(0);
395
+ done();
396
+ });
283
397
  });
284
398
  });
285
399
 
286
400
  describe("/GET test", () => {
287
401
  it("it should GET a single test contained in a data object", (done) => {
288
402
  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
- });
403
+ .get("/api/test/" + post_id)
404
+ .auth(init.email, init.password)
405
+ .end((err, res) => {
406
+ res.should.have.status(200);
407
+ res.body.should.have.property("data");
408
+ res.body.data.should.be.an('object');
409
+ res.body.data.should.have.property("_id");
410
+ res.body.data.should.have.property("foo")
411
+ res.body.data.foo.should.eql("Foo1");
412
+ done();
413
+ });
300
414
  });
301
415
  });
302
416
 
@@ -308,31 +422,31 @@ describe('Test', () => {
308
422
  val: "val1"
309
423
  }
310
424
  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
- });
425
+ .post("/api/link")
426
+ .auth(init.email, init.password)
427
+ .send(data)
428
+ .end((err, res) => {
429
+ res.should.have.status(200);
430
+ res.body.data.should.be.an('object');
431
+ res.body.data.should.have.property("_id");
432
+ res.body.data.should.have.property("name")
433
+ res.body.data.name.should.eql("name1");
434
+ link_id = res.body.data._id;
435
+ done();
436
+ });
323
437
  });
324
438
  it("should link a LINK item to a TEST", done => {
325
439
  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
- });
440
+ .put("/api/test/" + post_id)
441
+ .auth(init.email, init.password)
442
+ .send({ link_id })
443
+ .end((err, res) => {
444
+ res.should.have.status(200);
445
+ res.body.data.should.be.an('object');
446
+ res.body.data.should.have.property("link_id")
447
+ res.body.data.link_id.should.eql(link_id);
448
+ done();
449
+ });
336
450
  });
337
451
  var other_link_id = null;
338
452
  it("should add another LINK item", done => {
@@ -341,47 +455,47 @@ describe('Test', () => {
341
455
  val: "val2"
342
456
  }
343
457
  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
- });
458
+ .post("/api/link")
459
+ .auth(init.email, init.password)
460
+ .send(data)
461
+ .end((err, res) => {
462
+ res.should.have.status(200);
463
+ res.body.data.should.be.an('object');
464
+ res.body.data.should.have.property("_id");
465
+ res.body.data.should.have.property("name")
466
+ res.body.data.name.should.eql("name2");
467
+ other_link_id = res.body.data._id;
468
+ done();
469
+ });
356
470
  });
357
471
  it("should link another LINK item to a TEST", done => {
358
472
  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
- });
473
+ .put("/api/test/" + post_id)
474
+ .auth(init.email, init.password)
475
+ .send({ other_link_id })
476
+ .end((err, res) => {
477
+ res.should.have.status(200);
478
+ res.body.data.should.be.an('object');
479
+ res.body.data.should.have.property("other_link_id")
480
+ res.body.data.other_link_id.should.eql(other_link_id);
481
+ done();
482
+ });
369
483
  });
370
484
  it("should non-descructively autopopulate on a single record", done => {
371
485
  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
- });
486
+ .get(`/api/test/${post_id}?populate=link`)
487
+ .auth(init.email, init.password)
488
+ .end((err, res) => {
489
+ res.should.have.status(200);
490
+ res.body.should.have.property("data");
491
+ res.body.data.should.have.property("link");
492
+ res.body.data.link.should.be.an('object');
493
+ res.body.data.link.name.should.eql("name1");
494
+ res.body.data.link.val.should.eql("val1");
495
+ res.body.data.should.have.property("link_id");
496
+ res.body.data.link_id.should.be.eql(link_id);
497
+ done();
498
+ });
385
499
  });
386
500
  it("should non-descructively autopopulate on a single record to a specific virtual", done => {
387
501
  chai.request(server)
@@ -401,20 +515,20 @@ describe('Test', () => {
401
515
  });
402
516
  it("should autopopulate on all records", done => {
403
517
  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
- });
518
+ .get(`/api/test?autopopulate=true`)
519
+ .auth(init.email, init.password)
520
+ .end((err, res) => {
521
+ res.should.have.status(200);
522
+ res.body.data[0].should.have.property("link")
523
+ res.body.data[0].link.should.be.an('object');
524
+ res.body.data[0].link.name.should.eql("name1");
525
+ res.body.data[0].link.val.should.eql("val1");
526
+ res.body.data[0].should.have.property("other_link")
527
+ res.body.data[0].other_link.should.be.an('object');
528
+ res.body.data[0].other_link.name.should.eql("name2");
529
+ res.body.data[0].other_link.val.should.eql("val2");
530
+ done();
531
+ });
418
532
  });
419
533
  it("should autopopulate on a single records", done => {
420
534
  chai.request(server)
@@ -435,123 +549,123 @@ describe('Test', () => {
435
549
  });
436
550
  it("should non-destructively populate link on a single record", done => {
437
551
  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
- });
552
+ .get(`/api/test/${post_id}?populate=link`)
553
+ .auth(init.email, init.password)
554
+ .end((err, res) => {
555
+ res.should.have.status(200);
556
+ res.body.should.have.property("data");
557
+ res.body.data.should.have.property("link")
558
+ res.body.data.link.should.be.an('object');
559
+ res.body.data.link.name.should.eql("name1");
560
+ res.body.data.link.val.should.eql("val1");
561
+ res.body.data.link_id.should.be.eql(link_id);
562
+ done();
563
+ });
450
564
  });
451
565
  it("should populate link_id on all records", done => {
452
566
  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
- });
567
+ .get(`/api/test?populate=link`)
568
+ .auth(init.email, init.password)
569
+ .end((err, res) => {
570
+ res.should.have.status(200);
571
+ res.body.data[0].should.have.property("link")
572
+ res.body.data[0].link.should.be.an('object');
573
+ res.body.data[0].link.name.should.eql("name1");
574
+ res.body.data[0].link.val.should.eql("val1");
575
+ res.body.data[0].link_id.should.be.eql(link_id);
576
+ done();
577
+ });
464
578
  });
465
579
  it("should populate just val from link_id on a single record", done => {
466
580
  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
- });
581
+ .get(`/api/test/${post_id}?populate[link]=val`)
582
+ .auth(init.email, init.password)
583
+ .end((err, res) => {
584
+ res.should.have.status(200);
585
+ res.body.should.have.property("data");
586
+ res.body.data.link.should.have.property("val")
587
+ res.body.data.link.should.not.have.property("name")
588
+ res.body.data.link.should.be.an('object');
589
+ res.body.data.link.val.should.eql("val1");
590
+ done();
591
+ });
478
592
  });
479
593
  it("should populate just val from link_id on all records", done => {
480
594
  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
- });
595
+ .get(`/api/test?populate[link]=val`)
596
+ .auth(init.email, init.password)
597
+ .end((err, res) => {
598
+ res.should.have.status(200);
599
+ res.body.data[0].link.should.have.property("val")
600
+ res.body.data[0].link.should.not.have.property("name")
601
+ res.body.data[0].link.val.should.eql("val1");
602
+ done();
603
+ });
490
604
  });
491
605
  it("should populate name and val from link_id on a single record", done => {
492
606
  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
- });
607
+ .get(`/api/test/${post_id}?populate[link]=val,name`)
608
+ .auth(init.email, init.password)
609
+ .end((err, res) => {
610
+ res.should.have.status(200);
611
+ res.body.should.have.property("data");
612
+ res.body.data.link.should.have.property("val")
613
+ res.body.data.link.should.have.property("name")
614
+ res.body.data.link.should.be.an('object');
615
+ res.body.data.link.val.should.eql("val1");
616
+ done();
617
+ });
504
618
  });
505
619
  it("should populate name and val from link_id on all records", done => {
506
620
  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
- });
621
+ .get(`/api/test?populate[link]=val,name`)
622
+ .auth(init.email, init.password)
623
+ .end((err, res) => {
624
+ res.should.have.status(200);
625
+ res.body.data[0].link.should.have.property("val")
626
+ res.body.data[0].link.should.have.property("name")
627
+ res.body.data[0].link.val.should.eql("val1");
628
+ done();
629
+ });
516
630
  });
517
631
  it("should populate link_id and other_link_id on a single record", done => {
518
632
  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
- });
633
+ .get(`/api/test/${post_id}?populate[]=link&populate[]=other_link`)
634
+ .auth(init.email, init.password)
635
+ .end((err, res) => {
636
+ res.should.have.status(200);
637
+ res.body.should.have.property("data");
638
+ res.body.data.should.have.property("link")
639
+ res.body.data.link.should.be.an('object');
640
+ res.body.data.link.name.should.eql("name1");
641
+ res.body.data.link.val.should.eql("val1");
642
+ res.body.data.should.have.property("other_link");
643
+ res.body.data.other_link.should.be.an('object');
644
+ res.body.data.other_link.name.should.eql("name2");
645
+ res.body.data.other_link.val.should.eql("val2");
646
+ done();
647
+ });
534
648
  });
535
649
  it("should populate link_id and other_link_id on all records", done => {
536
650
  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
- });
651
+ .get(`/api/test?populate[]=link&populate[]=other_link`)
652
+ .auth(init.email, init.password)
653
+ .end((err, res) => {
654
+ res.should.have.status(200);
655
+ res.body.data[0].link.should.have.property("val")
656
+ res.body.data[0].link.should.have.property("name")
657
+ res.body.data[0].link.val.should.eql("val1");
658
+ res.body.data[0].other_link.should.have.property("val")
659
+ res.body.data[0].other_link.should.have.property("name")
660
+ res.body.data[0].other_link.val.should.eql("val2");
661
+ done();
662
+ });
549
663
  });
550
664
  it("should link an array of links to TEST", done => {
551
665
  chai.request(server)
552
666
  .put("/api/test/" + post_id)
553
667
  .auth(init.email, init.password)
554
- .send({ array_link_id: [ link_id, other_link_id ] })
668
+ .send({ array_link_id: [link_id, other_link_id] })
555
669
  .end((err, res) => {
556
670
  res.should.have.status(200);
557
671
  res.body.data.should.be.an('object');
@@ -579,37 +693,37 @@ describe('Test', () => {
579
693
  it("it should POST a complex query", (done) => {
580
694
  var query = {
581
695
  "$and": [
582
- {
696
+ {
583
697
  "foo": {
584
698
  "$regex": "foo",
585
699
  "$options": "i"
586
700
  }
587
701
  },
588
- {
702
+ {
589
703
  "bar": "Bar"
590
704
  }
591
705
  ]
592
706
  };
593
707
  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
- });
708
+ .post("/query/test")
709
+ .auth(init.email, init.password)
710
+ .send({ query })
711
+ .end((err, res) => {
712
+ res.should.have.status(200);
713
+ res.body.data.should.be.an('array');
714
+ res.body.data[0].should.have.property("_id");
715
+ res.body.data[0].should.have.property("foo");
716
+ res.body.data[0].should.have.property("bar");
717
+ res.body.data[0].should.have.property("yack").which.should.be.an("object");
718
+ res.body.data[0].should.have.property("shmack");
719
+ res.body.data[0].shmack.should.be.an("array");
720
+ res.body.data[0].foo.should.be.a("string");
721
+ res.body.data[0].bar.should.be.a("string");
722
+ res.body.data[0].foo.should.eql("Foo1");
723
+ res.body.data[0].bar.should.eql("Bar");
724
+ objectid = res.body.data[0]._id;
725
+ done();
726
+ });
613
727
  });
614
728
  });
615
729
  describe("/POST aggregate", () => {
@@ -618,17 +732,17 @@ describe('Test', () => {
618
732
  { $group: { _id: null, count: { $sum: 1 } } }
619
733
  ];
620
734
  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
- });
735
+ .post("/aggregate/test")
736
+ .auth(init.email, init.password)
737
+ .send({ query })
738
+ .end((err, res) => {
739
+ res.should.have.status(200);
740
+ res.body.data.should.be.an('array');
741
+ res.body.data[0].should.have.property("_id");
742
+ res.body.data[0].should.have.property("count");
743
+ res.body.data[0].count.should.eql(3);
744
+ done();
745
+ });
632
746
  });
633
747
  });
634
748
  describe("/POST aggregate", () => {
@@ -637,23 +751,23 @@ describe('Test', () => {
637
751
  { $group: { _id: null, count: { $sum: 1 } } }
638
752
  ];
639
753
  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
- });
754
+ .post("/aggregate/test")
755
+ .auth(init.email, init.password)
756
+ .send(query)
757
+ .end((err, res) => {
758
+ res.should.have.status(200);
759
+ res.body.data.should.be.an('array');
760
+ res.body.data[0].should.have.property("_id");
761
+ res.body.data[0].should.have.property("count");
762
+ res.body.data[0].count.should.eql(3);
763
+ done();
764
+ });
651
765
  });
652
766
  });
653
767
  describe("/POST aggregate", () => {
654
768
  it("it should POST an aggregate query with calculated Date", (done) => {
655
769
  var query = [
656
- {
770
+ {
657
771
  $match: {
658
772
  "createdAt": {
659
773
  "$gte": "new Date(\"2020-01-01\")"
@@ -663,23 +777,23 @@ describe('Test', () => {
663
777
  { $group: { _id: null, count: { $sum: 1 } } }
664
778
  ];
665
779
  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
- });
780
+ .post("/aggregate/test")
781
+ .auth(init.email, init.password)
782
+ .send({ query })
783
+ .end((err, res) => {
784
+ res.should.have.status(200);
785
+ res.body.data.should.be.an('array');
786
+ res.body.data[0].should.have.property("_id");
787
+ res.body.data[0].should.have.property("count");
788
+ res.body.data[0].count.should.eql(3);
789
+ done();
790
+ });
677
791
  });
678
792
  });
679
793
  describe("/POST aggregate", () => {
680
794
  it("it should POST an aggregate query with calculated relative_date", (done) => {
681
795
  var query = [
682
- {
796
+ {
683
797
  $match: {
684
798
  "createdAt": {
685
799
  "$gte": "relative_date(-1, \"days\")",
@@ -690,23 +804,23 @@ describe('Test', () => {
690
804
  { $group: { _id: null, count: { $sum: 1 } } }
691
805
  ];
692
806
  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
- });
807
+ .post("/aggregate/test")
808
+ .auth(init.email, init.password)
809
+ .send({ query })
810
+ .end((err, res) => {
811
+ res.should.have.status(200);
812
+ res.body.data.should.be.an('array');
813
+ res.body.data[0].should.have.property("_id");
814
+ res.body.data[0].should.have.property("count");
815
+ res.body.data[0].count.should.eql(3);
816
+ done();
817
+ });
704
818
  });
705
819
  });
706
820
  describe("/POST aggregate", () => {
707
821
  it("it should POST an aggregate query with calculated ObjectId", (done) => {
708
822
  var query = [
709
- {
823
+ {
710
824
  $match: {
711
825
  "_id": `ObjectId("${objectid}")`
712
826
  }
@@ -714,17 +828,17 @@ describe('Test', () => {
714
828
  { $group: { _id: null, count: { $sum: 1 } } }
715
829
  ];
716
830
  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
- });
831
+ .post("/aggregate/test")
832
+ .auth(init.email, init.password)
833
+ .send({ query })
834
+ .end((err, res) => {
835
+ res.should.have.status(200);
836
+ res.body.data.should.be.an('array');
837
+ res.body.data[0].should.have.property("_id");
838
+ res.body.data[0].should.have.property("count");
839
+ res.body.data[0].count.should.eql(1);
840
+ done();
841
+ });
728
842
  });
729
843
  });
730
844
  describe("/POST aggregate allowDiskUse", () => {
@@ -741,7 +855,7 @@ describe('Test', () => {
741
855
  res.body.data.should.be.an('array');
742
856
  res.body.data[0].should.have.property("_id");
743
857
  res.body.data[0].should.have.property("count");
744
- res.body.data[0].count.should.eql(1);
858
+ res.body.data[0].count.should.eql(3);
745
859
  done();
746
860
  });
747
861
  });
@@ -757,7 +871,7 @@ describe('Test', () => {
757
871
  res.body.data[0].should.have.property("foo");
758
872
  res.body.data[0].foo.should.eql("Foo1");
759
873
  res.body.should.have.property("count");
760
- res.body.count.should.eql(1);
874
+ res.body.count.should.eql(3);
761
875
  done();
762
876
  });
763
877
  })
@@ -826,7 +940,7 @@ describe('Test', () => {
826
940
  res.body.data[1].should.have.property("foo");
827
941
  res.body.data[2].should.have.property("foo");
828
942
  res.body.should.have.property("count");
829
- res.body.count.should.eql(3);
943
+ res.body.count.should.eql(5);
830
944
  done();
831
945
  });
832
946
  });
@@ -861,6 +975,123 @@ describe('Test', () => {
861
975
  });
862
976
  });
863
977
 
978
+ describe("Mixed Array Tests", () => {
979
+ it("should save complex objects in mixed_array", (done) => {
980
+ const complexData = {
981
+ foo: "MixedArrayTest",
982
+ bar: "MixedArrayBar",
983
+ mixed_array: [
984
+ {
985
+ nested: {
986
+ prop1: "value1",
987
+ prop2: 123,
988
+ prop3: true
989
+ },
990
+ array: [1, 2, 3],
991
+ date: new Date("2024-03-20T10:00:00Z")
992
+ },
993
+ ["array", "of", "strings"],
994
+ 42,
995
+ { simple: "object" },
996
+ null,
997
+ new Date("2024-03-21"),
998
+ [
999
+ {
1000
+ foo: "bar",
1001
+ bar: "foo"
1002
+ },
1003
+ {
1004
+ foo: "baz",
1005
+ bar: "baz"
1006
+ }
1007
+ ]
1008
+ ]
1009
+ };
1010
+
1011
+ chai.request(server)
1012
+ .post("/api/test")
1013
+ .auth(init.email, init.password)
1014
+ .send(complexData)
1015
+ .end((err, res) => {
1016
+ res.should.have.status(200);
1017
+ res.body.data.should.be.an('object');
1018
+ res.body.data.should.have.property("mixed_array");
1019
+ res.body.data.mixed_array.should.be.an("array");
1020
+ res.body.data.mixed_array.should.have.length(7);
1021
+
1022
+ // Verify first object with nested properties
1023
+ res.body.data.mixed_array[0].should.have.property("nested");
1024
+ res.body.data.mixed_array[0].nested.prop1.should.equal("value1");
1025
+ res.body.data.mixed_array[0].nested.prop2.should.equal(123);
1026
+ res.body.data.mixed_array[0].nested.prop3.should.equal(true);
1027
+ res.body.data.mixed_array[0].array.should.deep.equal([1, 2, 3]);
1028
+
1029
+ // Verify array of strings
1030
+ res.body.data.mixed_array[1].should.deep.equal(["array", "of", "strings"]);
1031
+
1032
+ // Verify number
1033
+ res.body.data.mixed_array[2].should.equal(42);
1034
+
1035
+ // Verify simple object
1036
+ res.body.data.mixed_array[3].should.have.property("simple");
1037
+ res.body.data.mixed_array[3].simple.should.equal("object");
1038
+
1039
+ // Verify null
1040
+ should.equal(res.body.data.mixed_array[4], null);
1041
+
1042
+ // Verify dates are stored as ISO strings
1043
+ res.body.data.mixed_array[0].date.should.be.a("string");
1044
+ res.body.data.mixed_array[5].should.be.a("string");
1045
+ res.body.data.mixed_array[6].should.be.a("array");
1046
+ res.body.data.mixed_array[6][0].should.have.property("foo");
1047
+ res.body.data.mixed_array[6][0].foo.should.equal("bar");
1048
+ res.body.data.mixed_array[6][1].should.have.property("foo");
1049
+ res.body.data.mixed_array[6][1].foo.should.equal("baz");
1050
+ done();
1051
+ });
1052
+ });
1053
+
1054
+ it("should retrieve and maintain complex objects in mixed_array", (done) => {
1055
+ // First create a test document
1056
+ const testData = {
1057
+ foo: "MixedArrayRetrieveTest",
1058
+ bar: "RetrieveBar",
1059
+ mixed_array: [
1060
+ {
1061
+ deep: { nested: { object: true } },
1062
+ array: [[1, 2], [3, 4]],
1063
+ },
1064
+ Buffer.from("Hello World").toString("base64"),
1065
+ new RegExp("test").toString()
1066
+ ]
1067
+ };
1068
+
1069
+ let testId;
1070
+
1071
+ chai.request(server)
1072
+ .post("/api/test")
1073
+ .auth(init.email, init.password)
1074
+ .send(testData)
1075
+ .end((err, res) => {
1076
+ res.should.have.status(200);
1077
+ testId = res.body.data._id;
1078
+
1079
+ // Now retrieve and verify
1080
+ chai.request(server)
1081
+ .get(`/api/test/${testId}`)
1082
+ .auth(init.email, init.password)
1083
+ .end((err, res) => {
1084
+ res.should.have.status(200);
1085
+ res.body.data.mixed_array[0].deep.nested.object.should.equal(true);
1086
+ res.body.data.mixed_array[0].array.should.deep.equal([[1, 2], [3, 4]]);
1087
+ res.body.data.mixed_array[1].should.be.a("string");
1088
+ res.body.data.mixed_array[2].should.equal("/test/");
1089
+ done();
1090
+ });
1091
+ });
1092
+ });
1093
+ });
1094
+
864
1095
  describe("Delete", () => {
865
1096
  it("should soft-delete an item", (done) => {
866
1097
  chai.request(server)
@@ -946,34 +1177,34 @@ describe('Test', () => {
946
1177
  bar: "Gloop"
947
1178
  }
948
1179
  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
- });
1180
+ .post("/api/link")
1181
+ .auth(init.email, init.password)
1182
+ .send(data)
1183
+ .end((err, res) => {
1184
+ res.should.have.status(200);
1185
+ res.body.data.should.be.an('object');
1186
+ res.body.data.should.have.property("_id");
1187
+ res.body.data.should.have.property("name")
1188
+ res.body.data.name.should.eql("deltest_name");
1189
+ link_id = res.body.data._id;
1190
+ done();
1191
+ });
961
1192
  });
962
1193
  it("should link a LINK item to a TEST", done => {
963
1194
  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
- });
1195
+ .post("/api/test")
1196
+ .auth(init.email, init.password)
1197
+ .send({
1198
+ link_id
1199
+ })
1200
+ .end((err, res) => {
1201
+ res.should.have.status(200);
1202
+ res.body.data.should.be.an('object');
1203
+ res.body.data.should.have.property("link_id")
1204
+ res.body.data.link_id.should.eql(link_id);
1205
+ test_with_links_id = res.body.data._id;
1206
+ done();
1207
+ });
977
1208
  });
978
1209
  it("should fail because a parent item exists", (done) => {
979
1210
  chai.request(server)
@@ -1021,35 +1252,35 @@ describe('Test', () => {
1021
1252
  bar: "Yoop"
1022
1253
  }
1023
1254
  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
- });
1255
+ .post("/api/link")
1256
+ .auth(init.email, init.password)
1257
+ .send(data)
1258
+ .end((err, res) => {
1259
+ res.should.have.status(200);
1260
+ res.body.data.should.be.an('object');
1261
+ res.body.data.should.have.property("_id");
1262
+ res.body.data.should.have.property("name")
1263
+ res.body.data.name.should.eql("permdeltest_name");
1264
+ link_id = res.body.data._id;
1265
+ done();
1266
+ });
1036
1267
  });
1037
1268
  it("should link a LINK item to a TEST", done => {
1038
1269
  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
- });
1270
+ .post("/api/test")
1271
+ .auth(init.email, init.password)
1272
+ .send({
1273
+ link_id,
1274
+ bar: "link1"
1275
+ })
1276
+ .end((err, res) => {
1277
+ res.should.have.status(200);
1278
+ res.body.data.should.be.an('object');
1279
+ res.body.data.should.have.property("link_id")
1280
+ res.body.data.link_id.should.eql(link_id);
1281
+ test_with_links_id = res.body.data._id;
1282
+ done();
1283
+ });
1053
1284
  });
1054
1285
  it("should fail because a parent item exists", (done) => {
1055
1286
  chai.request(server)
@@ -1089,96 +1320,96 @@ describe('Test', () => {
1089
1320
  email: "plus+user@gmail.com"
1090
1321
  };
1091
1322
  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
- });
1323
+ .post("/api/user")
1324
+ .auth(init.admin_email, init.admin_password)
1325
+ .send(user)
1326
+ .end((err, res) => {
1327
+ res.should.have.status(200);
1328
+ res.body.data.should.have.property("_id");
1329
+ done();
1330
+ });
1100
1331
  });
1101
1332
  it("it should GET a user with a + in email", (done) => {
1102
1333
  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
- });
1334
+ .get("/api/user?filter[email]=plus%2Buser@gmail.com")
1335
+ .auth(init.admin_email, init.admin_password)
1336
+ .end((err, res) => {
1337
+ res.should.have.status(200);
1338
+ res.body.data[0].should.have.property("_id");
1339
+ done();
1340
+ });
1110
1341
  });
1111
1342
  });
1112
1343
 
1113
1344
  describe("Error Handling", () => {
1114
- it ("should get an error", (done) => {
1345
+ it("should get an error", (done) => {
1115
1346
  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
- });
1347
+ .post("/api/test")
1348
+ .auth(init.email, init.password)
1349
+ .send({
1350
+ error: true,
1351
+ bar: "Throw an error"
1352
+ })
1353
+ .end((err, res) => {
1354
+ res.should.have.status(418);
1355
+ res.body.message.should.equal(`I'm a teapot`);
1356
+ done();
1357
+ });
1127
1358
  })
1128
1359
  });
1129
1360
 
1130
1361
  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
- });
1362
+ it("should give us cache stats", (done) => {
1363
+ chai.request(server)
1364
+ .get("/cache/stats")
1365
+ .end((err, res) => {
1366
+ // console.log(res.body);
1367
+ res.should.have.status(200);
1368
+ res.body.should.have.property("hits");
1369
+ done();
1370
+ });
1140
1371
  })
1141
- it ("should clear the cache stats", (done) => {
1372
+ it("should clear the cache stats", (done) => {
1142
1373
  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
- });
1374
+ .get("/cache/clear")
1375
+ .end((err, res) => {
1376
+ // console.log(res.body);
1377
+ res.should.have.status(200);
1378
+ done();
1379
+ });
1149
1380
  });
1150
- it ("should get an uncached request", (done) => {
1381
+ it("should get an uncached request", (done) => {
1151
1382
  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
- });
1383
+ .get("/api/test")
1384
+ .auth(init.email, init.password)
1385
+ .end((err, res) => {
1386
+ res.should.have.status(200);
1387
+ res.headers.should.have.property("jxp-cache");
1388
+ res.headers["jxp-cache"].should.equal("miss");
1389
+ done();
1390
+ });
1160
1391
  });
1161
- it ("should get an cached request", (done) => {
1392
+ it("should get an cached request", (done) => {
1162
1393
  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
- });
1394
+ .get("/api/test")
1395
+ .auth(init.email, init.password)
1396
+ .end((err, res) => {
1397
+ res.should.have.status(200);
1398
+ res.headers.should.have.property("jxp-cache");
1399
+ res.headers["jxp-cache"].should.equal("hit");
1400
+ done();
1401
+ });
1171
1402
  });
1172
- it ("should give us cache stats", (done) => {
1403
+ it("should give us cache stats", (done) => {
1173
1404
  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
- });
1405
+ .get("/cache/stats")
1406
+ .end((err, res) => {
1407
+ res.should.have.status(200);
1408
+ res.body.should.have.property("hits");
1409
+ res.body.hits.should.be.greaterThan(0);
1410
+ res.body.misses.should.be.greaterThan(0);
1411
+ done();
1412
+ });
1182
1413
  })
1183
1414
  });
1184
1415
  describe("Cache invalidating", () => {
@@ -1210,7 +1441,7 @@ describe('Test', () => {
1210
1441
  should.equal(res.body.data[0].link, null);
1211
1442
  done();
1212
1443
  });
1213
- });
1444
+ });
1214
1445
  let link_id;
1215
1446
  it("should add a link record", done => {
1216
1447
  chai.request(server)