Merge branch 'drop-invalid-notifications' into 'develop'
Notifications: drop status notifications if status is null See merge request soapbox-pub/soapbox-fe!866
This commit is contained in:
commit
7baff3d696
2 changed files with 106 additions and 61 deletions
|
@ -1,7 +1,18 @@
|
||||||
import * as actions from 'soapbox/actions/notifications';
|
import {
|
||||||
|
NOTIFICATIONS_EXPAND_SUCCESS,
|
||||||
|
NOTIFICATIONS_EXPAND_REQUEST,
|
||||||
|
NOTIFICATIONS_EXPAND_FAIL,
|
||||||
|
NOTIFICATIONS_FILTER_SET,
|
||||||
|
NOTIFICATIONS_SCROLL_TOP,
|
||||||
|
NOTIFICATIONS_UPDATE,
|
||||||
|
NOTIFICATIONS_UPDATE_QUEUE,
|
||||||
|
NOTIFICATIONS_DEQUEUE,
|
||||||
|
NOTIFICATIONS_CLEAR,
|
||||||
|
NOTIFICATIONS_MARK_READ_REQUEST,
|
||||||
|
} from 'soapbox/actions/notifications';
|
||||||
import reducer from '../notifications';
|
import reducer from '../notifications';
|
||||||
import notifications from 'soapbox/__fixtures__/notifications.json';
|
import notifications from 'soapbox/__fixtures__/notifications.json';
|
||||||
import { Map as ImmutableMap, OrderedMap as ImmutableOrderedMap } from 'immutable';
|
import { Map as ImmutableMap, OrderedMap as ImmutableOrderedMap, fromJS } from 'immutable';
|
||||||
import { take } from 'lodash';
|
import { take } from 'lodash';
|
||||||
import { ACCOUNT_BLOCK_SUCCESS, ACCOUNT_MUTE_SUCCESS } from 'soapbox/actions/accounts';
|
import { ACCOUNT_BLOCK_SUCCESS, ACCOUNT_MUTE_SUCCESS } from 'soapbox/actions/accounts';
|
||||||
import notification from 'soapbox/__fixtures__/notification.json';
|
import notification from 'soapbox/__fixtures__/notification.json';
|
||||||
|
@ -28,55 +39,89 @@ describe('notifications reducer', () => {
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle NOTIFICATIONS_EXPAND_SUCCESS', () => {
|
describe('NOTIFICATIONS_EXPAND_SUCCESS', () => {
|
||||||
const state = undefined;
|
it('imports the notifications', () => {
|
||||||
const action = {
|
const state = undefined;
|
||||||
type: actions.NOTIFICATIONS_EXPAND_SUCCESS,
|
|
||||||
notifications: take(notifications, 3),
|
const action = {
|
||||||
next: null,
|
type: NOTIFICATIONS_EXPAND_SUCCESS,
|
||||||
skipLoading: true,
|
notifications: take(notifications, 3),
|
||||||
};
|
next: null,
|
||||||
expect(reducer(state, action)).toEqual(ImmutableMap({
|
skipLoading: true,
|
||||||
items: ImmutableOrderedMap([
|
};
|
||||||
['10744', ImmutableMap({
|
|
||||||
id: '10744',
|
expect(reducer(state, action)).toEqual(ImmutableMap({
|
||||||
type: 'pleroma:emoji_reaction',
|
items: ImmutableOrderedMap([
|
||||||
account: '9vMAje101ngtjlMj7w',
|
['10744', ImmutableMap({
|
||||||
|
id: '10744',
|
||||||
|
type: 'pleroma:emoji_reaction',
|
||||||
|
account: '9vMAje101ngtjlMj7w',
|
||||||
|
target: null,
|
||||||
|
created_at: '2020-06-10T02:54:39.000Z',
|
||||||
|
status: '9vvNxoo5EFbbnfdXQu',
|
||||||
|
emoji: '😢',
|
||||||
|
chat_message: undefined,
|
||||||
|
})],
|
||||||
|
['10743', ImmutableMap({
|
||||||
|
id: '10743',
|
||||||
|
type: 'favourite',
|
||||||
|
account: '9v5c6xSEgAi3Zu1Lv6',
|
||||||
|
target: null,
|
||||||
|
created_at: '2020-06-10T02:51:05.000Z',
|
||||||
|
status: '9vvNxoo5EFbbnfdXQu',
|
||||||
|
emoji: undefined,
|
||||||
|
chat_message: undefined,
|
||||||
|
})],
|
||||||
|
['10741', ImmutableMap({
|
||||||
|
id: '10741',
|
||||||
|
type: 'favourite',
|
||||||
|
account: '9v5cKMOPGqPcgfcWp6',
|
||||||
|
target: null,
|
||||||
|
created_at: '2020-06-10T02:05:06.000Z',
|
||||||
|
status: '9vvNxoo5EFbbnfdXQu',
|
||||||
|
emoji: undefined,
|
||||||
|
chat_message: undefined,
|
||||||
|
})],
|
||||||
|
]),
|
||||||
|
hasMore: false,
|
||||||
|
top: false,
|
||||||
|
unread: 0,
|
||||||
|
isLoading: false,
|
||||||
|
queuedNotifications: ImmutableOrderedMap(),
|
||||||
|
totalQueuedNotificationsCount: 0,
|
||||||
|
lastRead: -1,
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('drops invalid notifications', () => {
|
||||||
|
const action = {
|
||||||
|
type: NOTIFICATIONS_EXPAND_SUCCESS,
|
||||||
|
notifications: [
|
||||||
|
{ id: '1', type: 'mention', status: null, account: { id: '10' } },
|
||||||
|
{ id: '2', type: 'reblog', status: null, account: { id: '9' } },
|
||||||
|
{ id: '3', type: 'favourite', status: null, account: { id: '8' } },
|
||||||
|
{ id: '4', type: 'mention', status: { id: 'a' }, account: { id: '7' } },
|
||||||
|
{ id: '5', type: 'reblog', status: { id: 'b' }, account: null },
|
||||||
|
],
|
||||||
|
next: null,
|
||||||
|
skipLoading: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
const expected = ImmutableOrderedMap([
|
||||||
|
['4', fromJS({
|
||||||
|
id: '4',
|
||||||
|
type: 'mention',
|
||||||
|
account: '7',
|
||||||
target: null,
|
target: null,
|
||||||
created_at: '2020-06-10T02:54:39.000Z',
|
created_at: undefined,
|
||||||
status: '9vvNxoo5EFbbnfdXQu',
|
status: 'a',
|
||||||
emoji: '😢',
|
|
||||||
chat_message: undefined,
|
|
||||||
})],
|
|
||||||
['10743', ImmutableMap({
|
|
||||||
id: '10743',
|
|
||||||
type: 'favourite',
|
|
||||||
account: '9v5c6xSEgAi3Zu1Lv6',
|
|
||||||
target: null,
|
|
||||||
created_at: '2020-06-10T02:51:05.000Z',
|
|
||||||
status: '9vvNxoo5EFbbnfdXQu',
|
|
||||||
emoji: undefined,
|
emoji: undefined,
|
||||||
chat_message: undefined,
|
chat_message: undefined,
|
||||||
})],
|
})],
|
||||||
['10741', ImmutableMap({
|
]);
|
||||||
id: '10741',
|
|
||||||
type: 'favourite',
|
expect(reducer(undefined, action).get('items')).toEqual(expected);
|
||||||
account: '9v5cKMOPGqPcgfcWp6',
|
});
|
||||||
target: null,
|
|
||||||
created_at: '2020-06-10T02:05:06.000Z',
|
|
||||||
status: '9vvNxoo5EFbbnfdXQu',
|
|
||||||
emoji: undefined,
|
|
||||||
chat_message: undefined,
|
|
||||||
})],
|
|
||||||
]),
|
|
||||||
hasMore: false,
|
|
||||||
top: false,
|
|
||||||
unread: 0,
|
|
||||||
isLoading: false,
|
|
||||||
queuedNotifications: ImmutableOrderedMap(),
|
|
||||||
totalQueuedNotificationsCount: 0,
|
|
||||||
lastRead: -1,
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle NOTIFICATIONS_EXPAND_REQUEST', () => {
|
it('should handle NOTIFICATIONS_EXPAND_REQUEST', () => {
|
||||||
|
@ -84,7 +129,7 @@ describe('notifications reducer', () => {
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
});
|
});
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.NOTIFICATIONS_EXPAND_REQUEST,
|
type: NOTIFICATIONS_EXPAND_REQUEST,
|
||||||
};
|
};
|
||||||
expect(reducer(state, action)).toEqual(ImmutableMap({
|
expect(reducer(state, action)).toEqual(ImmutableMap({
|
||||||
isLoading: true,
|
isLoading: true,
|
||||||
|
@ -96,7 +141,7 @@ describe('notifications reducer', () => {
|
||||||
isLoading: true,
|
isLoading: true,
|
||||||
});
|
});
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.NOTIFICATIONS_EXPAND_FAIL,
|
type: NOTIFICATIONS_EXPAND_FAIL,
|
||||||
};
|
};
|
||||||
expect(reducer(state, action)).toEqual(ImmutableMap({
|
expect(reducer(state, action)).toEqual(ImmutableMap({
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
|
@ -146,7 +191,7 @@ describe('notifications reducer', () => {
|
||||||
lastRead: -1,
|
lastRead: -1,
|
||||||
});
|
});
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.NOTIFICATIONS_FILTER_SET,
|
type: NOTIFICATIONS_FILTER_SET,
|
||||||
};
|
};
|
||||||
expect(reducer(state, action)).toEqual(ImmutableMap({
|
expect(reducer(state, action)).toEqual(ImmutableMap({
|
||||||
items: ImmutableOrderedMap(),
|
items: ImmutableOrderedMap(),
|
||||||
|
@ -165,7 +210,7 @@ describe('notifications reducer', () => {
|
||||||
unread: 1,
|
unread: 1,
|
||||||
});
|
});
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.NOTIFICATIONS_SCROLL_TOP,
|
type: NOTIFICATIONS_SCROLL_TOP,
|
||||||
top: true,
|
top: true,
|
||||||
};
|
};
|
||||||
expect(reducer(state, action)).toEqual(ImmutableMap({
|
expect(reducer(state, action)).toEqual(ImmutableMap({
|
||||||
|
@ -179,7 +224,7 @@ describe('notifications reducer', () => {
|
||||||
unread: 3,
|
unread: 3,
|
||||||
});
|
});
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.NOTIFICATIONS_SCROLL_TOP,
|
type: NOTIFICATIONS_SCROLL_TOP,
|
||||||
top: false,
|
top: false,
|
||||||
};
|
};
|
||||||
expect(reducer(state, action)).toEqual(ImmutableMap({
|
expect(reducer(state, action)).toEqual(ImmutableMap({
|
||||||
|
@ -195,7 +240,7 @@ describe('notifications reducer', () => {
|
||||||
unread: 1,
|
unread: 1,
|
||||||
});
|
});
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.NOTIFICATIONS_UPDATE,
|
type: NOTIFICATIONS_UPDATE,
|
||||||
notification: notification,
|
notification: notification,
|
||||||
};
|
};
|
||||||
expect(reducer(state, action)).toEqual(ImmutableMap({
|
expect(reducer(state, action)).toEqual(ImmutableMap({
|
||||||
|
@ -223,7 +268,7 @@ describe('notifications reducer', () => {
|
||||||
totalQueuedNotificationsCount: 0,
|
totalQueuedNotificationsCount: 0,
|
||||||
});
|
});
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.NOTIFICATIONS_UPDATE_QUEUE,
|
type: NOTIFICATIONS_UPDATE_QUEUE,
|
||||||
notification: notification,
|
notification: notification,
|
||||||
intlMessages: intlMessages,
|
intlMessages: intlMessages,
|
||||||
intlLocale: 'en',
|
intlLocale: 'en',
|
||||||
|
@ -246,7 +291,7 @@ describe('notifications reducer', () => {
|
||||||
totalQueuedNotificationsCount: 1,
|
totalQueuedNotificationsCount: 1,
|
||||||
});
|
});
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.NOTIFICATIONS_DEQUEUE,
|
type: NOTIFICATIONS_DEQUEUE,
|
||||||
};
|
};
|
||||||
expect(reducer(state, action)).toEqual(ImmutableMap({
|
expect(reducer(state, action)).toEqual(ImmutableMap({
|
||||||
items: ImmutableOrderedMap(),
|
items: ImmutableOrderedMap(),
|
||||||
|
@ -274,7 +319,7 @@ describe('notifications reducer', () => {
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
});
|
});
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.NOTIFICATIONS_EXPAND_SUCCESS,
|
type: NOTIFICATIONS_EXPAND_SUCCESS,
|
||||||
notifications: take(notifications, 3),
|
notifications: take(notifications, 3),
|
||||||
next: true,
|
next: true,
|
||||||
};
|
};
|
||||||
|
@ -335,7 +380,7 @@ describe('notifications reducer', () => {
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
});
|
});
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.NOTIFICATIONS_EXPAND_SUCCESS,
|
type: NOTIFICATIONS_EXPAND_SUCCESS,
|
||||||
notifications: take(notifications, 3),
|
notifications: take(notifications, 3),
|
||||||
next: true,
|
next: true,
|
||||||
};
|
};
|
||||||
|
@ -514,7 +559,7 @@ describe('notifications reducer', () => {
|
||||||
hasMore: true,
|
hasMore: true,
|
||||||
});
|
});
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.NOTIFICATIONS_CLEAR,
|
type: NOTIFICATIONS_CLEAR,
|
||||||
};
|
};
|
||||||
expect(reducer(state, action)).toEqual(ImmutableMap({
|
expect(reducer(state, action)).toEqual(ImmutableMap({
|
||||||
items: ImmutableOrderedMap(),
|
items: ImmutableOrderedMap(),
|
||||||
|
@ -527,7 +572,7 @@ describe('notifications reducer', () => {
|
||||||
items: ImmutableOrderedMap(),
|
items: ImmutableOrderedMap(),
|
||||||
});
|
});
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.NOTIFICATIONS_MARK_READ_REQUEST,
|
type: NOTIFICATIONS_MARK_READ_REQUEST,
|
||||||
lastRead: 35098814,
|
lastRead: 35098814,
|
||||||
};
|
};
|
||||||
expect(reducer(state, action)).toEqual(ImmutableMap({
|
expect(reducer(state, action)).toEqual(ImmutableMap({
|
||||||
|
|
|
@ -64,8 +64,8 @@ const isValid = notification => {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mastodon can return mentions with a null status
|
// Mastodon can return status notifications with a null status
|
||||||
if (notification.type === 'mention' && !notification.status.id) {
|
if (['mention', 'reblog', 'favourite', 'poll'].includes(notification.type) && !notification.status.id) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue