Skip to content

Throw error when push is missing configuration #2035

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

Merged
merged 1 commit into from
Jun 13, 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
20 changes: 20 additions & 0 deletions spec/Parse.Push.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,24 @@ describe('Parse.Push', () => {
});
});
});

it('should throw error if missing push configuration', done => {
reconfigureServer({push: null})
.then(() => {
return Parse.Push.send({
where: {
deviceType: 'ios'
},
data: {
badge: 'increment',
alert: 'Hello world!'
}
}, {useMasterKey: true})
}).then((response) => {
fail('should not succeed');
}, (err) => {
expect(err.code).toEqual(Parse.Error.PUSH_MISCONFIGURED);
done();
});
});
});
10 changes: 5 additions & 5 deletions spec/PushController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ describe('PushController', () => {
isMaster: true
}

var pushController = new PushController(pushAdapter, Parse.applicationId);
var pushController = new PushController(pushAdapter, Parse.applicationId, defaultConfiguration.push);
Parse.Object.saveAll(installations).then((installations) => {
return pushController.sendPush(payload, {}, config, auth);
}).then((result) => {
Expand Down Expand Up @@ -226,7 +226,7 @@ describe('PushController', () => {
isMaster: true
}

var pushController = new PushController(pushAdapter, Parse.applicationId);
var pushController = new PushController(pushAdapter, Parse.applicationId, defaultConfiguration.push);
Parse.Object.saveAll(installations).then((installations) => {
return pushController.sendPush(payload, {}, config, auth);
}).then((result) => {
Expand Down Expand Up @@ -277,7 +277,7 @@ describe('PushController', () => {
isMaster: true
}

var pushController = new PushController(pushAdapter, Parse.applicationId);
var pushController = new PushController(pushAdapter, Parse.applicationId, defaultConfiguration.push);
Parse.Object.saveAll(installations).then(() => {
return pushController.sendPush(payload, {}, config, auth);
}).then((result) => {
Expand Down Expand Up @@ -342,7 +342,7 @@ describe('PushController', () => {
var auth = {
isMaster: true
}
var pushController = new PushController(pushAdapter, Parse.applicationId);
var pushController = new PushController(pushAdapter, Parse.applicationId, defaultConfiguration.push);
pushController.sendPush(payload, where, config, auth).then(() => {
fail('should not succeed');
done();
Expand Down Expand Up @@ -388,7 +388,7 @@ describe('PushController', () => {
}
}

var pushController = new PushController(pushAdapter, Parse.applicationId);
var pushController = new PushController(pushAdapter, Parse.applicationId, defaultConfiguration.push);
pushController.sendPush(payload, where, config, auth).then((result) => {
done();
}).catch((err) => {
Expand Down
4 changes: 4 additions & 0 deletions src/Controllers/PushController.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export class PushController extends AdaptableController {
throw new Parse.Error(Parse.Error.PUSH_MISCONFIGURED,
'Push adapter is not available');
}
if (!this.options) {
throw new Parse.Error(Parse.Error.PUSH_MISCONFIGURED,
'Missing push configuration');
}
PushController.validatePushType(where, pushAdapter.getValidPushTypes());
// Replace the expiration_time with a valid Unix epoch milliseconds time
body['expiration_time'] = PushController.getExpirationTime(body);
Expand Down
4 changes: 2 additions & 2 deletions src/ParseServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,15 @@ class ParseServer {
return new GridStoreAdapter(databaseURI);
});
// Pass the push options too as it works with the default
const pushControllerAdapter = loadAdapter(push && push.adapter, ParsePushAdapter, push);
const pushControllerAdapter = loadAdapter(push && push.adapter, ParsePushAdapter, push || {});
const loggerControllerAdapter = loadAdapter(loggerAdapter, FileLoggerAdapter);
const emailControllerAdapter = loadAdapter(emailAdapter);
const cacheControllerAdapter = loadAdapter(cacheAdapter, InMemoryCacheAdapter, {appId: appId});

// We pass the options and the base class for the adatper,
// Note that passing an instance would work too
const filesController = new FilesController(filesControllerAdapter, appId);
const pushController = new PushController(pushControllerAdapter, appId);
const pushController = new PushController(pushControllerAdapter, appId, push);
const loggerController = new LoggerController(loggerControllerAdapter, appId);
const userController = new UserController(emailControllerAdapter, appId, { verifyUserEmails });
const liveQueryController = new LiveQueryController(liveQuery);
Expand Down