Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow installation get, fixes #1718 #1980

Merged
merged 1 commit into from
Jun 4, 2016
Merged
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
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
};