2022-08-05 08:56:03 -07:00
|
|
|
import { OrderedMap as ImmutableOrderedMap } from 'immutable';
|
|
|
|
|
2024-08-28 04:41:08 -07:00
|
|
|
import { __stub } from 'pl-fe/api';
|
|
|
|
import { mockStore, rootState } from 'pl-fe/jest/test-helpers';
|
|
|
|
import { normalizeNotification } from 'pl-fe/normalizers';
|
2022-08-05 08:56:03 -07:00
|
|
|
|
2023-10-02 12:27:40 -07:00
|
|
|
import { markReadNotifications } from './notifications';
|
2022-08-05 08:56:03 -07:00
|
|
|
|
|
|
|
describe('markReadNotifications()', () => {
|
|
|
|
it('fires off marker when top notification is newer than lastRead', async() => {
|
|
|
|
__stub((mock) => mock.onPost('/api/v1/markers').reply(200, {}));
|
|
|
|
|
|
|
|
const items = ImmutableOrderedMap({
|
|
|
|
'10': normalizeNotification({ id: '10' }),
|
|
|
|
});
|
|
|
|
|
2024-10-08 20:49:56 -07:00
|
|
|
const state = {
|
|
|
|
...rootState,
|
|
|
|
me: '123',
|
|
|
|
notifications: rootState.notifications.merge({
|
|
|
|
lastRead: '9',
|
|
|
|
items,
|
|
|
|
}),
|
|
|
|
};
|
2022-08-05 08:56:03 -07:00
|
|
|
|
|
|
|
const store = mockStore(state);
|
|
|
|
|
2023-03-14 09:22:23 -07:00
|
|
|
const expectedActions = [{
|
2022-08-05 08:56:03 -07:00
|
|
|
type: 'MARKER_SAVE_REQUEST',
|
|
|
|
marker: {
|
|
|
|
notifications: {
|
|
|
|
last_read_id: '10',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}];
|
|
|
|
|
|
|
|
store.dispatch(markReadNotifications());
|
|
|
|
const actions = store.getActions();
|
|
|
|
|
|
|
|
expect(actions).toEqual(expectedActions);
|
|
|
|
});
|
|
|
|
});
|