Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
JSoufer committed Oct 21, 2024
1 parent 9ac693a commit c6572dd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type { PushNotificationEnv } from './types';

const MOCK_JWT = 'mockJwt';
const MOCK_FCM_TOKEN = 'mockFcmToken';
const MOCK_MOBILE_FCM_TOKEN = 'mockMobileFcmToken';
const MOCK_TRIGGERS = ['uuid1', 'uuid2'];

describe('NotificationServicesPushController', () => {
Expand Down Expand Up @@ -58,6 +59,20 @@ describe('NotificationServicesPushController', () => {

expect(services.listenToPushNotifications).toHaveBeenCalled();
});

it('should update the state with provided mobile fcmToken', async () => {
arrangeServicesMocks();
const { controller, messenger } = arrangeMockMessenger();
mockAuthBearerTokenCall(messenger);

await controller.enablePushNotifications(
MOCK_TRIGGERS,
MOCK_MOBILE_FCM_TOKEN,
);
expect(controller.state.fcmToken).toBe(MOCK_MOBILE_FCM_TOKEN);

expect(services.listenToPushNotifications).toHaveBeenCalled();
});
});

describe('disablePushNotifications', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {

const MOCK_REG_TOKEN = 'REG_TOKEN';
const MOCK_NEW_REG_TOKEN = 'NEW_REG_TOKEN';
const MOCK_MOBILE_FCM_TOKEN = 'mockMobileFcmToken';
const MOCK_TRIGGERS = ['1', '2', '3'];
const MOCK_JWT = 'MOCK_JWT';

Expand Down Expand Up @@ -78,8 +79,15 @@ describe('NotificationServicesPushController Services', () => {
env: {} as PushNotificationEnv,
};

const mobileParams = {
...params,
fcmToken: MOCK_MOBILE_FCM_TOKEN,
platform: 'mobile' as const,
};

return {
params,
mobileParams,
apis: {
mockGet: mockEndpointGetPushNotificationLinks(override?.mockGet),
mockPut: mockEndpointUpdatePushNotificationLinks(override?.mockPut),
Expand All @@ -98,6 +106,17 @@ describe('NotificationServicesPushController Services', () => {
expect(result).toBe(MOCK_NEW_REG_TOKEN);
});

it('should successfully call APIs and add provided mobile fcmToken', async () => {
const { mobileParams, apis } = arrangeMocks();
const result = await activatePushNotifications(mobileParams);

expect(apis.mockGet.isDone()).toBe(true);
expect(mobileParams.createRegToken).not.toHaveBeenCalled();
expect(apis.mockPut.isDone()).toBe(true);

expect(result).toBe(MOCK_MOBILE_FCM_TOKEN);
});

it('should return null if unable to get links from API', async () => {
const { params, apis } = arrangeMocks({ mockGet: { status: 500 } });
const result = await activatePushNotifications(params);
Expand Down

0 comments on commit c6572dd

Please sign in to comment.