Skip to content

Commit

Permalink
code was validate
Browse files Browse the repository at this point in the history
  • Loading branch information
Gonzalo Lopez authored and Fernando Colom committed May 3, 2024
1 parent eb3646f commit dc194bb
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 55 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 14 additions & 14 deletions lib/usePushNotification.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -160,7 +160,7 @@ const usePushNotification = (environment, events, appName, isRegistered) => {
registerDeviceToNotifications,
updateNotificationState,
getSubscribedEvents,
deleteReceivedNotification
deleteReceivedNotification,
};
};

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
Expand Down
78 changes: 42 additions & 36 deletions test/usePushNotification.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});
});
});

0 comments on commit dc194bb

Please sign in to comment.