More work in REST api deletion

This commit is contained in:
vjrj 2018-06-19 10:49:53 +02:00
parent 5642b106d4
commit b8c7cc5a10
2 changed files with 10 additions and 16 deletions

View file

@ -317,13 +317,16 @@ if (!Meteor.settings.private.internalApiToken) {
return fail(e); return fail(e);
} }
return jsend.success({ subsId: result._str }); return jsend.success({ subsId: result._str });
}, }
});
apiV1.addRoute('mobile/subscriptions/:token/:mobileToken/:subsId', { authRequired: false }, {
delete: function del() { delete: function del() {
const { const {
token, token,
mobileToken, mobileToken,
subsId subsId
} = this.bodyParams; } = this.urlParams;
try { try {
check(token, String); check(token, String);
check(mobileToken, String); check(mobileToken, String);

View file

@ -140,7 +140,6 @@ describe('basic api v1 returns', () => {
}); });
}); });
function addSubs(done) { function addSubs(done) {
// this are removed in the test database but we are testing in dev/ci database // this are removed in the test database but we are testing in dev/ci database
// Remove previous subs of this user // Remove previous subs of this user
@ -199,6 +198,7 @@ describe('basic api v1 returns', () => {
chai.expect(jsendResult.status).equal('success'); chai.expect(jsendResult.status).equal('success');
chai.expect(typeof jsendResult.data.subscriptions).to.equal('object'); chai.expect(typeof jsendResult.data.subscriptions).to.equal('object');
chai.expect(typeof jsendResult.data.count).to.equal('number'); chai.expect(typeof jsendResult.data.count).to.equal('number');
if (jsendResult.data.count !== 1) console.log(result);
chai.expect(jsendResult.data.count).to.equal(1); chai.expect(jsendResult.data.count).to.equal(1);
// console.log(JSON.stringify(jsendResult.data.subscriptions)); // console.log(JSON.stringify(jsendResult.data.subscriptions));
done(); done();
@ -209,12 +209,7 @@ describe('basic api v1 returns', () => {
it('should remove mobile user subscriptions', async (done) => { it('should remove mobile user subscriptions', async (done) => {
// this are removed in the test database but we are testing in dev/ci database // this are removed in the test database but we are testing in dev/ci database
HTTP.del(url('api/v1/mobile/subscriptions'), { HTTP.del(url(`api/v1/mobile/subscriptions/${token}/${mobileToken}/${returnedSubsId}`), {
data: {
token,
mobileToken,
subsId: returnedSubsId
}
}, (error, result) => { }, (error, result) => {
chai.expect(error, null); chai.expect(error, null);
if (result.statusCode !== 200) console.log(result); if (result.statusCode !== 200) console.log(result);
@ -235,20 +230,15 @@ describe('basic api v1 returns', () => {
chai.expect(jsendResult.status).equal('success'); chai.expect(jsendResult.status).equal('success');
chai.expect(typeof jsendResult.data.subscriptions).to.equal('object'); chai.expect(typeof jsendResult.data.subscriptions).to.equal('object');
chai.expect(typeof jsendResult.data.count).to.equal('number'); chai.expect(typeof jsendResult.data.count).to.equal('number');
if (jsendResult.data.count !== 0) console.log(result);
chai.expect(jsendResult.data.count).to.equal(0); chai.expect(jsendResult.data.count).to.equal(0);
// console.log(JSON.stringify(jsendResult.data.subscriptions)); // console.log(JSON.stringify(jsendResult.data.subscriptions));
done(); done();
}); });
}); });
it('should not remove mobile user subscriptions with wrong token', async (done) => { it('should not remove mobile user subscriptions with wrong token', async (done) => {
HTTP.del(url('api/v1/mobile/subscriptions'), { HTTP.del(url(`api/v1/mobile/subscriptions/wrongOne/${mobileToken}/${returnedSubsId}`), {
data: {
token: 'wrongOne',
mobileToken,
subsId: returnedSubsId
}
}, (error, result) => { }, (error, result) => {
chai.expect(error, null); chai.expect(error, null);
if (result.statusCode !== 401) console.log(result); if (result.statusCode !== 401) console.log(result);
@ -278,6 +268,7 @@ describe('basic api v1 returns', () => {
chai.expect(jsendResult.status).equal('success'); chai.expect(jsendResult.status).equal('success');
chai.expect(typeof jsendResult.data.subscriptions).to.equal('object'); chai.expect(typeof jsendResult.data.subscriptions).to.equal('object');
chai.expect(typeof jsendResult.data.count).to.equal('number'); chai.expect(typeof jsendResult.data.count).to.equal('number');
if (jsendResult.data.count !== 0) console.log(result);
chai.expect(jsendResult.data.count).to.equal(0); chai.expect(jsendResult.data.count).to.equal(0);
done(); done();
}); });