jxp 2.15.0 → 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/libs/jxp.js +111 -31
- package/models/test_model.js +13 -12
- package/package.json +2 -2
- package/test/test.js +531 -440
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
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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: [
|
|
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
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
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
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
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
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
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
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
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
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
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
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
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
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
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
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
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
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
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
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
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
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
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
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
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
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
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
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
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
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
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
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
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
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
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: [
|
|
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
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
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
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
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
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
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
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
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
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
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
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
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
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
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
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
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
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
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
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
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
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
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
|
|
1205
|
+
it("should get an error", (done) => {
|
|
1115
1206
|
chai.request(server)
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
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
|
|
1132
|
-
chai.request(server)
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
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
|
|
1232
|
+
it("should clear the cache stats", (done) => {
|
|
1142
1233
|
chai.request(server)
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
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
|
|
1241
|
+
it("should get an uncached request", (done) => {
|
|
1151
1242
|
chai.request(server)
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
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
|
|
1252
|
+
it("should get an cached request", (done) => {
|
|
1162
1253
|
chai.request(server)
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
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
|
|
1263
|
+
it("should give us cache stats", (done) => {
|
|
1173
1264
|
chai.request(server)
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
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)
|