More REST calls
This commit is contained in:
parent
1de7e4a7b3
commit
a48da85ebe
2 changed files with 134 additions and 17 deletions
|
|
@ -321,3 +321,46 @@ apiV1.addRoute('mobile/subscriptions', { authRequired: false }, {
|
||||||
return jsend.success({});
|
return jsend.success({});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
apiV1.addRoute('mobile/subscriptions/all', { authRequired: false }, {
|
||||||
|
get: function get() {
|
||||||
|
const { token, mobileToken } = this.bodyParams;
|
||||||
|
try {
|
||||||
|
check(token, String);
|
||||||
|
check(mobileToken, String);
|
||||||
|
} catch (e) {
|
||||||
|
return defaultFailParams(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
const failed = checkAuthToken(token);
|
||||||
|
if (failed) return failed;
|
||||||
|
|
||||||
|
const user = Meteor.users.findOne({ fireBaseToken: mobileToken });
|
||||||
|
if (!user) return failed;
|
||||||
|
|
||||||
|
const result = Subscriptions.find({ owner: user._id });
|
||||||
|
|
||||||
|
return jsend.success({ subscriptions: result.fetch(), count: result.count() });
|
||||||
|
},
|
||||||
|
delete: function delAll() {
|
||||||
|
const { token, mobileToken } = this.bodyParams;
|
||||||
|
try {
|
||||||
|
check(token, String);
|
||||||
|
check(mobileToken, String);
|
||||||
|
} catch (e) {
|
||||||
|
return defaultFailParams(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
const failed = checkAuthToken(token);
|
||||||
|
if (failed) return failed;
|
||||||
|
|
||||||
|
if (Meteor.users.find({ fireBaseToken: mobileToken }).count() !== 1) return failed;
|
||||||
|
|
||||||
|
const user = Meteor.users.findOne({ fireBaseToken: mobileToken });
|
||||||
|
if (!user) return failed;
|
||||||
|
const toRemove = Subscriptions.find({ owner: user._id }).count();
|
||||||
|
Subscriptions.remove({ owner: user._id });
|
||||||
|
|
||||||
|
return jsend.success({ count: toRemove });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -142,7 +142,7 @@ describe('basic api v1 returns', () => {
|
||||||
|
|
||||||
let subsId;
|
let subsId;
|
||||||
|
|
||||||
it('should create mobile user subscriptions', async (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
|
||||||
|
|
@ -164,8 +164,48 @@ describe('basic api v1 returns', () => {
|
||||||
subsId = jsendResult.data.subsId;
|
subsId = jsendResult.data.subsId;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
it('should create mobile user subscriptions', async (done) => {
|
||||||
|
addSubs(done);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not create mobile user subscriptions with wrong token', async (done) => {
|
||||||
|
HTTP.post(url('api/v1/mobile/subscriptions'), {
|
||||||
|
data: {
|
||||||
|
token: 'wrongOne',
|
||||||
|
mobileToken,
|
||||||
|
lat: 3.106111,
|
||||||
|
lon: 53.5775,
|
||||||
|
distance: 100
|
||||||
|
}
|
||||||
|
}, (error, result) => {
|
||||||
|
chai.expect(error, null);
|
||||||
|
chai.expect(result.statusCode).equal(401);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should get all mobile user subscriptions', async (done) => {
|
||||||
|
HTTP.get(url('api/v1/mobile/subscriptions/all'), {
|
||||||
|
data: {
|
||||||
|
token,
|
||||||
|
mobileToken
|
||||||
|
}
|
||||||
|
}, (error, result) => {
|
||||||
|
chai.expect(error, null);
|
||||||
|
chai.expect(result.statusCode).equal(200);
|
||||||
|
const jsendResult = result.data;
|
||||||
|
chai.expect(jsendResult.status).equal('success');
|
||||||
|
chai.expect(typeof jsendResult.data.subscriptions).to.equal('object');
|
||||||
|
chai.expect(typeof jsendResult.data.count).to.equal('number');
|
||||||
|
chai.expect(jsendResult.data.count).to.equal(1);
|
||||||
|
// console.log(JSON.stringify(jsendResult.data.subscriptions));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
|
|
@ -184,21 +224,6 @@ describe('basic api v1 returns', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not create mobile user subscriptions with wrong token', async (done) => {
|
|
||||||
HTTP.post(url('api/v1/mobile/subscriptions'), {
|
|
||||||
data: {
|
|
||||||
token: 'wrongOne',
|
|
||||||
mobileToken,
|
|
||||||
lat: 3.106111,
|
|
||||||
lon: 53.5775,
|
|
||||||
distance: 100
|
|
||||||
}
|
|
||||||
}, (error, result) => {
|
|
||||||
chai.expect(error, null);
|
|
||||||
chai.expect(result.statusCode).equal(401);
|
|
||||||
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'), {
|
||||||
|
|
@ -214,7 +239,56 @@ describe('basic api v1 returns', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO list all subs
|
it('should not get mobile user subscriptions with wrong token', async (done) => {
|
||||||
|
HTTP.get(url('api/v1/mobile/subscriptions/all'), {
|
||||||
|
data: {
|
||||||
|
token: 'wrongOne',
|
||||||
|
mobileToken
|
||||||
|
}
|
||||||
|
}, (error, result) => {
|
||||||
|
chai.expect(error, null);
|
||||||
|
chai.expect(result.statusCode).equal(401);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should get all mobile user subscriptions', async (done) => {
|
||||||
|
HTTP.get(url('api/v1/mobile/subscriptions/all'), {
|
||||||
|
data: {
|
||||||
|
token,
|
||||||
|
mobileToken
|
||||||
|
}
|
||||||
|
}, (error, result) => {
|
||||||
|
chai.expect(error, null);
|
||||||
|
chai.expect(result.statusCode).equal(200);
|
||||||
|
const jsendResult = result.data;
|
||||||
|
chai.expect(jsendResult.status).equal('success');
|
||||||
|
chai.expect(typeof jsendResult.data.subscriptions).to.equal('object');
|
||||||
|
chai.expect(typeof jsendResult.data.count).to.equal('number');
|
||||||
|
chai.expect(jsendResult.data.count).to.equal(0);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should del all mobile user subscriptions', async (done) => {
|
||||||
|
// Add two
|
||||||
|
addSubs(() => {});
|
||||||
|
addSubs(() => {});
|
||||||
|
HTTP.del(url('api/v1/mobile/subscriptions/all'), {
|
||||||
|
data: {
|
||||||
|
token,
|
||||||
|
mobileToken
|
||||||
|
}
|
||||||
|
}, (error, result) => {
|
||||||
|
chai.expect(error, null);
|
||||||
|
chai.expect(result.statusCode).equal(200);
|
||||||
|
const jsendResult = result.data;
|
||||||
|
chai.expect(jsendResult.status).equal('success');
|
||||||
|
chai.expect(typeof jsendResult.data.count).to.equal('number');
|
||||||
|
chai.expect(jsendResult.data.count).to.equal(2);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// TODO remove all subs
|
// TODO remove all subs
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue