Skip to content

Commit 7c8ad7e

Browse files
Marco129drew-gross
authored andcommitted
Throw error when push is missing configuration (#2035)
1 parent 0ec78d4 commit 7c8ad7e

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

spec/Parse.Push.spec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,24 @@ describe('Parse.Push', () => {
144144
});
145145
});
146146
});
147+
148+
it('should throw error if missing push configuration', done => {
149+
reconfigureServer({push: null})
150+
.then(() => {
151+
return Parse.Push.send({
152+
where: {
153+
deviceType: 'ios'
154+
},
155+
data: {
156+
badge: 'increment',
157+
alert: 'Hello world!'
158+
}
159+
}, {useMasterKey: true})
160+
}).then((response) => {
161+
fail('should not succeed');
162+
}, (err) => {
163+
expect(err.code).toEqual(Parse.Error.PUSH_MISCONFIGURED);
164+
done();
165+
});
166+
});
147167
});

spec/PushController.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ describe('PushController', () => {
178178
isMaster: true
179179
}
180180

181-
var pushController = new PushController(pushAdapter, Parse.applicationId);
181+
var pushController = new PushController(pushAdapter, Parse.applicationId, defaultConfiguration.push);
182182
Parse.Object.saveAll(installations).then((installations) => {
183183
return pushController.sendPush(payload, {}, config, auth);
184184
}).then((result) => {
@@ -226,7 +226,7 @@ describe('PushController', () => {
226226
isMaster: true
227227
}
228228

229-
var pushController = new PushController(pushAdapter, Parse.applicationId);
229+
var pushController = new PushController(pushAdapter, Parse.applicationId, defaultConfiguration.push);
230230
Parse.Object.saveAll(installations).then((installations) => {
231231
return pushController.sendPush(payload, {}, config, auth);
232232
}).then((result) => {
@@ -277,7 +277,7 @@ describe('PushController', () => {
277277
isMaster: true
278278
}
279279

280-
var pushController = new PushController(pushAdapter, Parse.applicationId);
280+
var pushController = new PushController(pushAdapter, Parse.applicationId, defaultConfiguration.push);
281281
Parse.Object.saveAll(installations).then(() => {
282282
return pushController.sendPush(payload, {}, config, auth);
283283
}).then((result) => {
@@ -342,7 +342,7 @@ describe('PushController', () => {
342342
var auth = {
343343
isMaster: true
344344
}
345-
var pushController = new PushController(pushAdapter, Parse.applicationId);
345+
var pushController = new PushController(pushAdapter, Parse.applicationId, defaultConfiguration.push);
346346
pushController.sendPush(payload, where, config, auth).then(() => {
347347
fail('should not succeed');
348348
done();
@@ -388,7 +388,7 @@ describe('PushController', () => {
388388
}
389389
}
390390

391-
var pushController = new PushController(pushAdapter, Parse.applicationId);
391+
var pushController = new PushController(pushAdapter, Parse.applicationId, defaultConfiguration.push);
392392
pushController.sendPush(payload, where, config, auth).then((result) => {
393393
done();
394394
}).catch((err) => {

src/Controllers/PushController.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ export class PushController extends AdaptableController {
4646
throw new Parse.Error(Parse.Error.PUSH_MISCONFIGURED,
4747
'Push adapter is not available');
4848
}
49+
if (!this.options) {
50+
throw new Parse.Error(Parse.Error.PUSH_MISCONFIGURED,
51+
'Missing push configuration');
52+
}
4953
PushController.validatePushType(where, pushAdapter.getValidPushTypes());
5054
// Replace the expiration_time with a valid Unix epoch milliseconds time
5155
body['expiration_time'] = PushController.getExpirationTime(body);

src/ParseServer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,15 @@ class ParseServer {
177177
return new GridStoreAdapter(databaseURI);
178178
});
179179
// Pass the push options too as it works with the default
180-
const pushControllerAdapter = loadAdapter(push && push.adapter, ParsePushAdapter, push);
180+
const pushControllerAdapter = loadAdapter(push && push.adapter, ParsePushAdapter, push || {});
181181
const loggerControllerAdapter = loadAdapter(loggerAdapter, FileLoggerAdapter);
182182
const emailControllerAdapter = loadAdapter(emailAdapter);
183183
const cacheControllerAdapter = loadAdapter(cacheAdapter, InMemoryCacheAdapter, {appId: appId});
184184

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

0 commit comments

Comments
 (0)