[MM-14923] Add channel_id to failed push notification reply (#3014)
* Add channel_id to failed push notification reply * Fix typo
This commit is contained in:
parent
dc5c515e63
commit
76b4bf8262
3 changed files with 70 additions and 3 deletions
|
|
@ -96,13 +96,13 @@ class PushNotification {
|
|||
}
|
||||
|
||||
localNotification(notification) {
|
||||
const deviceNotification = {
|
||||
this.deviceNotification = {
|
||||
alertBody: notification.message,
|
||||
alertAction: '',
|
||||
userInfo: notification.userInfo,
|
||||
};
|
||||
|
||||
NotificationsIOS.localNotification(deviceNotification);
|
||||
NotificationsIOS.localNotification(this.deviceNotification);
|
||||
}
|
||||
|
||||
cancelAllLocalNotifications() {
|
||||
|
|
|
|||
|
|
@ -140,9 +140,9 @@ class PushNotificationUtils {
|
|||
userInfo: {
|
||||
localNotification: true,
|
||||
localTest: true,
|
||||
channel_id: data.channel_id,
|
||||
},
|
||||
});
|
||||
console.warn('Failed to send reply to push notification', result.error); // eslint-disable-line no-console
|
||||
completed();
|
||||
return;
|
||||
}
|
||||
|
|
@ -191,6 +191,10 @@ class PushNotificationUtils {
|
|||
|
||||
unsubscribeFromStore = this.store.subscribe(waitForHydration);
|
||||
}
|
||||
|
||||
getNotification = () => {
|
||||
return PushNotifications.getNotification();
|
||||
}
|
||||
}
|
||||
|
||||
export default new PushNotificationUtils();
|
||||
|
|
|
|||
63
app/utils/push_notifications.test.js
Normal file
63
app/utils/push_notifications.test.js
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import configureMockStore from 'redux-mock-store';
|
||||
import thunk from 'redux-thunk';
|
||||
|
||||
import {PostTypes} from 'mattermost-redux/action_types';
|
||||
|
||||
import PushNotificationUtils from './push_notifications';
|
||||
|
||||
jest.mock('app/init/credentials', () => ({
|
||||
getAppCredentials: jest.fn().mockReturnValue({
|
||||
username: 'device-token,current-user-id',
|
||||
password: 'token,url',
|
||||
}),
|
||||
getCurrentServerUrl: jest.fn().mockReturnValue('url'),
|
||||
}));
|
||||
|
||||
jest.mock('app/actions/views/root', () => ({
|
||||
createPostForNotificationReply: jest.fn().mockImplementation(() => {
|
||||
return () => ({error: 'error'});
|
||||
}),
|
||||
}));
|
||||
|
||||
jest.mock('app/selectors/i18n', () => ({
|
||||
getCurrentLocale: jest.fn().mockReturnValue('en'),
|
||||
}));
|
||||
|
||||
jest.mock('react-native-notifications', () => {
|
||||
return {
|
||||
requestPermissions: jest.fn(),
|
||||
addEventListener: jest.fn(),
|
||||
NotificationAction: jest.fn(),
|
||||
NotificationCategory: jest.fn(),
|
||||
consumeBackgroundQueue: jest.fn(),
|
||||
localNotification: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
const mockStore = configureMockStore([thunk]);
|
||||
const store = mockStore({});
|
||||
PushNotificationUtils.configure(store);
|
||||
|
||||
describe('PushNotifications', () => {
|
||||
it('should add channel_id to failed push notification reply', async () => {
|
||||
let notification = PushNotificationUtils.getNotification();
|
||||
expect(notification).toBe(null);
|
||||
|
||||
const channelID = 'channel-id';
|
||||
const data = {channel_id: channelID};
|
||||
const text = 'text';
|
||||
const badge = 1;
|
||||
const completed = () => {};
|
||||
await PushNotificationUtils.onPushNotificationReply(data, text, badge, completed);
|
||||
|
||||
const storeActions = store.getActions();
|
||||
const receivedPost = storeActions.some((action) => action.type === PostTypes.RECEIVED_POST);
|
||||
expect(receivedPost).toBe(false);
|
||||
|
||||
notification = PushNotificationUtils.getNotification();
|
||||
expect(notification.userInfo.channel_id).toBe(channelID);
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue