Skip to content

Commit

Permalink
Allow installation get (#1980)
Browse files Browse the repository at this point in the history
  • Loading branch information
drew-gross authored and flovilmart committed Jun 4, 2016
1 parent bea655e commit aeb6880
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 16 deletions.
47 changes: 38 additions & 9 deletions spec/ParseInstallation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
// These tests check the Installations functionality of the REST API.
// Ported from installation_collection_test.go

var auth = require('../src/Auth');
var cache = require('../src/cache');
var Config = require('../src/Config');
var DatabaseAdapter = require('../src/DatabaseAdapter');
var Parse = require('parse/node').Parse;
var rest = require('../src/rest');

var config = new Config('test');
let auth = require('../src/Auth');
let cache = require('../src/cache');
let Config = require('../src/Config');
let DatabaseAdapter = require('../src/DatabaseAdapter');
let Parse = require('parse/node').Parse;
let rest = require('../src/rest');
let request = require("request");

let config = new Config('test');
let database = DatabaseAdapter.getDatabaseConnection('test', 'test_');
let defaultColumns = require('../src/Controllers/SchemaController').defaultColumns;

Expand Down Expand Up @@ -808,8 +809,36 @@ describe('Installations', () => {
});
});

it('allows you to get your own installation (regression test for #1718)', done => {
let installId = '12345678-abcd-abcd-abcd-123456789abc';
let device = 'android';
let input = {
'installationId': installId,
'deviceType': device
};
rest.create(config, auth.nobody(config), '_Installation', input)
.then(createResult => {
let headers = {
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest',
};
request.get({
headers: headers,
url: 'http://localhost:8378/1/installations/' + createResult.response.objectId,
json: true,
}, (error, response, body) => {
expect(body.objectId).toEqual(createResult.response.objectId);
done();
});
})
.catch(error => {
console.log(error);
fail('failed');
done();
});
});

// TODO: Look at additional tests from installation_collection_test.go:882
// TODO: Do we need to support _tombstone disabling of installations?
// TODO: Test deletion, badge increments

});
2 changes: 1 addition & 1 deletion src/Routers/ClassesRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class ClassesRouter extends PromiseRouter {
options.include = String(body.include);
}

return rest.find(req.config, req.auth, req.params.className, {objectId: req.params.objectId}, options)
return rest.get(req.config, req.auth, req.params.className, req.params.objectId, options)
.then((response) => {
if (!response.results || response.results.length == 0) {
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Object not found.');
Expand Down
19 changes: 13 additions & 6 deletions src/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ var triggers = require('./triggers');
// Returns a promise for an object with optional keys 'results' and 'count'.
function find(config, auth, className, restWhere, restOptions) {
enforceRoleSecurity('find', className, auth);
var query = new RestQuery(config, auth, className,
restWhere, restOptions);
let query = new RestQuery(config, auth, className, restWhere, restOptions);
return query.execute();
}

// get is just like find but only queries an objectId.
const get = (config, auth, className, objectId, restOptions) => {
enforceRoleSecurity('get', className, auth);
let query = new RestQuery(config, auth, className, { objectId }, restOptions);
return query.execute();
}

Expand Down Expand Up @@ -128,8 +134,9 @@ function enforceRoleSecurity(method, className, auth) {
}

module.exports = {
create: create,
del: del,
find: find,
update: update
create,
del,
find,
get,
update
};

0 comments on commit aeb6880

Please sign in to comment.