diff --git a/CHANGELOG.md b/CHANGELOG.md index bcda013..789eed6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,10 @@ [Unreleased] +## [0.0.1] - 2024-05-03 + ### Added -- Added NotificationProvider (HOC) to receive notifications at background and foreground.\ -- Added github actions to deploy to npm +- NotificationProvider (HOC) to receive notifications at background and foreground +- Github actions to deploy to npm +- Callback to handle notification diff --git a/lib/usePushNotification.js b/lib/usePushNotification.js index 9962d2d..32d96ad 100644 --- a/lib/usePushNotification.js +++ b/lib/usePushNotification.js @@ -106,31 +106,31 @@ const usePushNotification = (environment, events, appName, isRegistered) => { * @description This utility allows you to reset the state corresponding to the type of notification received as an argument. * @param {string} notificationType the type of notification you want to delete, it can be a foreground or background notification * @returns {null} - * - * @example + * + * @example * import {usePushNotification} from '@janiscommerce/app-push-notification * * const {deleteReceivedNotification} = usePushNotification() - * + * * const resetForegroundNotification = () => { * deleteReceivedNotification('foreground') * } */ const deleteReceivedNotification = (params = {}) => { - const {type = ''} = params - const allowTypes = ['foreground','background'] + const {type = ''} = params; + const allowTypes = ['foreground', 'background']; const deleteNotification = { - foreground: () => updateNotificationState({foregroundNotification:{}}), - background: () => updateNotificationState({backgroundNotification:{}}) - } + foreground: () => updateNotificationState({foregroundNotification: {}}), + background: () => updateNotificationState({backgroundNotification: {}}), + }; + + if (!type || !allowTypes.includes(type)) return null; - if(!type || !allowTypes.includes(type)) return null; + const restartNotification = deleteNotification[type]; - const restartNotification = deleteNotification[type] - - return restartNotification() - } + return restartNotification(); + }; /** * @function addNewEvent @@ -160,7 +160,7 @@ const usePushNotification = (environment, events, appName, isRegistered) => { registerDeviceToNotifications, updateNotificationState, getSubscribedEvents, - deleteReceivedNotification + deleteReceivedNotification, }; }; diff --git a/package-lock.json b/package-lock.json index 9fc5d80..c6e449d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@janiscommerce/app-push-notification", - "version": "0.0.1-beta.1", + "version": "0.0.1", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/package.json b/package.json index f2d95d1..2102980 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@janiscommerce/app-push-notification", - "version": "0.0.1-beta.1", + "version": "0.0.1", "type": "commonjs", "description": "This package will take care of performing the main actions for registration to receive notifications in the foreground and background.", "main": "lib/index.js", @@ -73,7 +73,6 @@ "react-native": "^0.67.5", "react-native-device-info": "^8.5.0", "react-test-renderer": "^17.0.2" - }, "bugs": { "url": "https://github.com/janis-commerce/app-push-notification/issues" diff --git a/test/usePushNotification.test.js b/test/usePushNotification.test.js index d03e0b4..95e71f5 100644 --- a/test/usePushNotification.test.js +++ b/test/usePushNotification.test.js @@ -234,65 +234,71 @@ describe('usePushNotification hook', () => { describe('deleteReceivedNotification util', () => { describe('should remove the information of the selected notification type from the notification status', () => { const mockState = { - foregroundNotification:{data:{},notification:{}}, - backgroundNotification:{data:{},notification:{}}, + foregroundNotification: {data: {}, notification: {}}, + backgroundNotification: {data: {}, notification: {}}, deviceToken: 'fcmToken', - pushEvents: ['picking:session:created'] - } + pushEvents: ['picking:session:created'], + }; it('if the selected type is foreground then should reset the foreground notification information', () => { - useState.mockReturnValueOnce([mockState,mockSetState]); - + useState.mockReturnValueOnce([mockState, mockSetState]); + const {result} = renderHook(() => - usePushNotification( - 'local', - ['picking:session:created'], - 'PickingApp', - {current: false}, + usePushNotification( + 'local', + ['picking:session:created'], + 'PickingApp', + {current: false}, ), ); const {deleteReceivedNotification} = result.current; - deleteReceivedNotification({type:'foreground'}) + deleteReceivedNotification({type: 'foreground'}); - expect(mockSetState).toHaveBeenCalledWith({...mockState,foregroundNotification:{}}) - }) + expect(mockSetState).toHaveBeenCalledWith({ + ...mockState, + foregroundNotification: {}, + }); + }); it('if the selected type is background then should reset the background notification information', () => { - useState.mockReturnValueOnce([mockState,mockSetState]); - + useState.mockReturnValueOnce([mockState, mockSetState]); + const {result} = renderHook(() => - usePushNotification( - 'local', - ['picking:session:created'], - 'PickingApp', - {current: false}, + usePushNotification( + 'local', + ['picking:session:created'], + 'PickingApp', + {current: false}, ), ); const {deleteReceivedNotification} = result.current; - deleteReceivedNotification({type:'background'}) + deleteReceivedNotification({type: 'background'}); - expect(mockSetState).toHaveBeenCalledWith({...mockState,backgroundNotification:{}}) - }) + expect(mockSetState).toHaveBeenCalledWith({ + ...mockState, + backgroundNotification: {}, + }); + }); it('if type is not pass return null', () => { - useState.mockReturnValueOnce([mockState,mockSetState]); - + useState.mockReturnValueOnce([mockState, mockSetState]); + const {result} = renderHook(() => - usePushNotification( - 'local', - ['picking:session:created'], - 'PickingApp', - {current: false}, + usePushNotification( + 'local', + ['picking:session:created'], + 'PickingApp', + {current: false}, ), ); const {deleteReceivedNotification} = result.current; - deleteReceivedNotification() + deleteReceivedNotification(); - expect(mockSetState).not.toHaveBeenCalled() - }) - }) - }) + expect(mockSetState).not.toHaveBeenCalled(); + }); + }); + }); }); });