Skip to content
Open
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
28 changes: 28 additions & 0 deletions spec/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
15 changes: 11 additions & 4 deletions src/Controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down