diff --git a/providers/pushpad/src/lib/pushpad.provider.spec.ts b/providers/pushpad/src/lib/pushpad.provider.spec.ts index da252a805f0..f01a008c5bb 100644 --- a/providers/pushpad/src/lib/pushpad.provider.spec.ts +++ b/providers/pushpad/src/lib/pushpad.provider.spec.ts @@ -5,4 +5,33 @@ test('should trigger pushpad library correctly', async () => { apiKey: 'test-token', appId: '012345', }); + + const mockDeliverTo = jest.fn(); + const mockBroadcast = jest.fn(); + const mockBuildNotification = jest + .spyOn(provider, 'buildNotification' as any) + .mockReturnValue({ + deliverTo: mockDeliverTo, + broadcast: mockBroadcast, + }); + + const result = await provider.sendMessage({ + title: 'Test', + content: 'Test push', + target: ['tester'], + payload: {}, + subscriber: {}, + step: { + digest: false, + events: [{}], + total_count: 1, + }, + }); + + expect(mockBuildNotification).toHaveBeenCalled(); + expect(mockDeliverTo).toHaveBeenCalledTimes(1); + expect(mockBroadcast).not.toHaveBeenCalled(); + + expect(result).toHaveProperty('id'); + expect(result).toHaveProperty('date'); }); diff --git a/providers/pushpad/src/lib/pushpad.provider.ts b/providers/pushpad/src/lib/pushpad.provider.ts index 57bab1bdd2f..14a45779937 100644 --- a/providers/pushpad/src/lib/pushpad.provider.ts +++ b/providers/pushpad/src/lib/pushpad.provider.ts @@ -27,11 +27,7 @@ export class PushpadPushProvider implements IPushProvider { async sendMessage( options: IPushOptions ): Promise { - const notification = new Pushpad.Notification({ - project: this.pushpad, - body: options.content, - title: options.title, - }); + const notification = this.buildNotification(options); let notificationId = null; @@ -56,4 +52,12 @@ export class PushpadPushProvider implements IPushProvider { date: new Date().toISOString(), }; } + + private buildNotification(options: IPushOptions): Pushpad.Notification { + return new Pushpad.Notification({ + project: this.pushpad, + body: options.content, + title: options.title, + }); + } }