kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Merge branch 'drop-invalid-notifications' into 'develop'
Notifications: drop status notifications if status is null See merge request soapbox-pub/soapbox-fe!866features-override
commit
7baff3d696
|
@ -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,14 +39,17 @@ describe('notifications reducer', () => {
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle NOTIFICATIONS_EXPAND_SUCCESS', () => {
|
describe('NOTIFICATIONS_EXPAND_SUCCESS', () => {
|
||||||
|
it('imports the notifications', () => {
|
||||||
const state = undefined;
|
const state = undefined;
|
||||||
|
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.NOTIFICATIONS_EXPAND_SUCCESS,
|
type: NOTIFICATIONS_EXPAND_SUCCESS,
|
||||||
notifications: take(notifications, 3),
|
notifications: take(notifications, 3),
|
||||||
next: null,
|
next: null,
|
||||||
skipLoading: true,
|
skipLoading: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(reducer(state, action)).toEqual(ImmutableMap({
|
expect(reducer(state, action)).toEqual(ImmutableMap({
|
||||||
items: ImmutableOrderedMap([
|
items: ImmutableOrderedMap([
|
||||||
['10744', ImmutableMap({
|
['10744', ImmutableMap({
|
||||||
|
@ -79,12 +93,43 @@ describe('notifications reducer', () => {
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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,
|
||||||
|
created_at: undefined,
|
||||||
|
status: 'a',
|
||||||
|
emoji: undefined,
|
||||||
|
chat_message: undefined,
|
||||||
|
})],
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(reducer(undefined, action).get('items')).toEqual(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should handle NOTIFICATIONS_EXPAND_REQUEST', () => {
|
it('should handle NOTIFICATIONS_EXPAND_REQUEST', () => {
|
||||||
const state = ImmutableMap({
|
const state = ImmutableMap({
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue