Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions tests/api3.create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,10 @@ describe('API3 CREATE', function() {
delete doc.identifier;

await new Promise((resolve, reject) => {
self.instance.ctx.treatments.create([doc], async (err) => { // let's insert the document in APIv1's way
self.instance.ctx.treatments.create([doc], (err) => { // let's insert the document in APIv1's way
should.not.exist(err);
doc._id = doc._id.toString();
self.cache.nextShouldEql(self.col, doc)
self.cache.nextShouldEql(self.col, doc);

err ? reject(err) : resolve(doc);
});
Expand All @@ -416,10 +416,10 @@ describe('API3 CREATE', function() {

let updatedBody = await self.get(doc2.identifier);
updatedBody.should.containEql(doc2);
self.cache.nextShouldEql(self.col, doc2)
self.cache.nextShouldEql(self.col, doc2);

await self.delete(doc2.identifier);
self.cache.nextShouldDeleteLast(self.col)
self.cache.nextShouldDeleteLast(self.col);
});


Expand All @@ -433,15 +433,17 @@ describe('API3 CREATE', function() {
delete doc.identifier;

await new Promise((resolve, reject) => {
self.instance.ctx.treatments.create([doc], async (err) => { // let's insert the document in APIv1's way
self.instance.ctx.treatments.create([doc], (err) => { // let's insert the document in APIv1's way
should.not.exist(err);
doc._id = doc._id.toString();

self.cache.nextShouldEql(self.col, doc)
self.cache.nextShouldEql(self.col, doc);

err ? reject(err) : resolve(doc);
});
});


const oldBody = await self.get(doc._id);
delete doc._id; // APIv1 updates input document, we must get rid of _id for the next round
oldBody.should.containEql(doc);
Expand All @@ -461,13 +463,13 @@ describe('API3 CREATE', function() {
updatedBody.identifier.should.not.equal(oldBody.identifier);
should.not.exist(updatedBody.isDeduplication);
should.not.exist(updatedBody.deduplicatedIdentifier);
self.cache.nextShouldEql(self.col, doc2)
self.cache.nextShouldEql(self.col, doc2);

await self.delete(doc2.identifier);
self.cache.nextShouldDeleteLast(self.col)
self.cache.nextShouldDeleteLast(self.col);

await self.delete(oldBody.identifier);
self.cache.nextShouldDeleteLast(self.col)
self.cache.nextShouldDeleteLast(self.col);
});


Expand All @@ -484,7 +486,7 @@ describe('API3 CREATE', function() {
let res = await self.instance.delete(`${self.url}/${identifier}`, self.jwt.delete)
.expect(200);
res.body.status.should.equal(200);
self.cache.nextShouldDeleteLast(self.col)
self.cache.nextShouldDeleteLast(self.col);

const date2 = new Date();
res = await self.instance.post(self.url, self.jwt.create)
Expand All @@ -493,7 +495,7 @@ describe('API3 CREATE', function() {

res.body.status.should.equal(403);
res.body.message.should.equal('Missing permission api:treatments:update');
self.cache.shouldBeEmpty()
self.cache.shouldBeEmpty();

const doc2 = Object.assign({}, self.validDoc, { identifier, date: date2.toISOString() });
res = await self.instance.post(`${self.url}`, self.jwt.all)
Expand All @@ -509,7 +511,7 @@ describe('API3 CREATE', function() {
body.identifier.should.equal(identifier);

await self.delete(identifier);
self.cache.nextShouldDeleteLast(self.col)
self.cache.nextShouldDeleteLast(self.col);
});


Expand All @@ -532,7 +534,7 @@ describe('API3 CREATE', function() {
self.cache.nextShouldEql(self.col, self.validDoc);

await self.delete(validIdentifier);
self.cache.nextShouldDeleteLast(self.col)
self.cache.nextShouldDeleteLast(self.col);
});


Expand Down Expand Up @@ -571,7 +573,7 @@ describe('API3 CREATE', function() {
body.length.should.equal(1);

await self.delete(validIdentifier);
self.cache.nextShouldDeleteLast(self.col)
self.cache.nextShouldDeleteLast(self.col);
});

});
Expand Down
16 changes: 7 additions & 9 deletions tests/api3.read.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('API3 READ', function () {

res.body.status.should.equal(404);
should.not.exist(res.body.result);
self.cache.shouldBeEmpty()
self.cache.shouldBeEmpty();
});


Expand All @@ -84,7 +84,7 @@ describe('API3 READ', function () {

res.body.status.should.equal(404);
should.not.exist(res.body.result);
self.cache.shouldBeEmpty()
self.cache.shouldBeEmpty();
});


Expand Down Expand Up @@ -159,7 +159,7 @@ describe('API3 READ', function () {
.expect(200);

res.body.status.should.equal(200);
self.cache.nextShouldDeleteLast(self.col)
self.cache.nextShouldDeleteLast(self.col);

res = await self.instance.get(`${self.url}/${self.validDoc.identifier}`, self.jwt.read)
.expect(410);
Expand All @@ -174,7 +174,7 @@ describe('API3 READ', function () {
.expect(200);

res.body.status.should.equal(200);
self.cache.nextShouldDeleteLast(self.col)
self.cache.nextShouldDeleteLast(self.col);

res = await self.instance.get(`${self.url}/${self.validDoc.identifier}`, self.jwt.read)
.expect(404);
Expand All @@ -192,11 +192,11 @@ describe('API3 READ', function () {
delete doc.identifier;

await new Promise((resolve, reject) => {
self.instance.ctx.devicestatus.create([doc], async (err) => { // let's insert the document in APIv1's way
self.instance.ctx.devicestatus.create([doc], (err) => { // let's insert the document in APIv1's way

should.not.exist(err);
doc._id = doc._id.toString();
self.cache.nextShouldEql(self.col, doc)
self.cache.nextShouldEql(self.col, doc);

err ? reject(err) : resolve(doc);
});
Expand All @@ -215,10 +215,8 @@ describe('API3 READ', function () {
.expect(200);

res.body.status.should.equal(200);
self.cache.nextShouldDeleteLast(self.col)
self.cache.nextShouldDeleteLast(self.col);
});


})
;