diff --git a/spec/index.spec.js b/spec/index.spec.js index 988f35cc3e..012b17a191 100644 --- a/spec/index.spec.js +++ b/spec/index.spec.js @@ -211,6 +211,34 @@ describe('server', () => { .catch(done.fail); }); + it('does not load the push adapter when push is not configured', async () => { + const Controllers = require('../lib/Controllers'); + const AdapterLoader = require('../lib/Adapters/AdapterLoader'); + const loadModule = spyOn(AdapterLoader, 'loadModule').and.callThrough(); + const result = await Controllers.getPushController({ push: undefined }); + expect(loadModule).not.toHaveBeenCalled(); + expect(result.hasPushSupport).toBe(false); + expect(result.hasPushScheduledSupport).toBe(false); + expect(result.pushWorker).toBeUndefined(); + }); + + it('loads the push adapter when push is configured', async () => { + const Controllers = require('../lib/Controllers'); + const AdapterLoader = require('../lib/Adapters/AdapterLoader'); + const loadModule = spyOn(AdapterLoader, 'loadModule').and.callThrough(); + const result = await Controllers.getPushController({ + push: { + adapter: { + send() {}, + getValidPushTypes() {}, + }, + queueOptions: { disablePushWorker: true }, + }, + }); + expect(loadModule).toHaveBeenCalledWith('@parse/push-adapter'); + expect(result.hasPushSupport).toBe(true); + }); + it('can properly sets the push support ', done => { reconfigureServer({ push: { diff --git a/src/Controllers/index.js b/src/Controllers/index.js index 9397dac561..784e431aaa 100644 --- a/src/Controllers/index.js +++ b/src/Controllers/index.js @@ -172,23 +172,30 @@ interface PushControlling { export async function getPushController(options: ParseServerOptions): PushControlling { const { scheduledPush, push } = options; + if (!push) { + return { + pushController: new PushController(), + hasPushSupport: false, + hasPushScheduledSupport: false, + pushControllerQueue: new PushQueue(), + pushWorker: undefined, + }; + } + const pushOptions = Object.assign({}, push); const pushQueueOptions = pushOptions.queueOptions || {}; if (pushOptions.queueOptions) { delete pushOptions.queueOptions; } - // Pass the push options too as it works with the default const ParsePushAdapter = await loadModule('@parse/push-adapter'); const pushAdapter = loadAdapter( pushOptions && pushOptions.adapter, ParsePushAdapter, pushOptions ); - // We pass the options and the base class for the adatper, - // Note that passing an instance would work too const pushController = new PushController(); - const hasPushSupport = !!(pushAdapter && push); + const hasPushSupport = !!pushAdapter; const hasPushScheduledSupport = hasPushSupport && scheduledPush === true; const { disablePushWorker } = pushQueueOptions;