Skip to content

Commit

Permalink
fix requestNotificationPermission()
Browse files Browse the repository at this point in the history
requestNotificationPermission() was returning undefined due to
incorrectly converting a string to an enum.
  • Loading branch information
jkasten2 committed Sep 10, 2024
1 parent d2302b6 commit a828638
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
32 changes: 32 additions & 0 deletions __test__/unit/notifications/subscriptionmanager.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import MockNotification from '../../support/mocks/MockNotification';
import { SubscriptionManager } from '../../../src/shared/managers/SubscriptionManager';
import { NotificationPermission } from '../../../src/shared/models/NotificationPermission';

describe('SubscriptionManager', () => {
describe('requestNotificationPermission', () => {
beforeEach(() => {
window.Notification = MockNotification;
});

test('default', async () => {
MockNotification.permission = 'default';
expect(await SubscriptionManager.requestNotificationPermission()).toBe(
NotificationPermission.Default,
);
});

test('denied', async () => {
MockNotification.permission = 'denied';
expect(await SubscriptionManager.requestNotificationPermission()).toBe(
NotificationPermission.Denied,
);
});

test('granted', async () => {
MockNotification.permission = 'granted';
expect(await SubscriptionManager.requestNotificationPermission()).toBe(
NotificationPermission.Granted,
);
});
});
});
2 changes: 1 addition & 1 deletion src/shared/managers/SubscriptionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ export class SubscriptionManager {
const results = await window.Notification.requestPermission();
// TODO: Clean up our custom NotificationPermission enum
// in favor of TS union type NotificationPermission instead of converting
return NotificationPermission[results];
return results as NotificationPermission;
}

public async isAlreadyRegisteredWithOneSignal(): Promise<boolean> {
Expand Down

0 comments on commit a828638

Please sign in to comment.