2018-01-31 10:55:39 +00:00
|
|
|
import {
|
|
|
|
|
generateUser,
|
2018-06-18 12:40:25 +00:00
|
|
|
} from '../../../../helpers/api-integration/v3';
|
2018-01-31 10:55:39 +00:00
|
|
|
|
|
|
|
|
describe('POST /news/tell-me-later', () => {
|
|
|
|
|
let user;
|
|
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
|
user = await generateUser({
|
|
|
|
|
'flags.newStuff': true,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('marks new stuff as read and adds notification', async () => {
|
|
|
|
|
expect(user.flags.newStuff).to.equal(true);
|
|
|
|
|
const initialNotifications = user.notifications.length;
|
|
|
|
|
|
|
|
|
|
await user.post('/news/tell-me-later');
|
|
|
|
|
await user.sync();
|
|
|
|
|
|
|
|
|
|
expect(user.flags.newStuff).to.equal(false);
|
|
|
|
|
expect(user.notifications.length).to.equal(initialNotifications + 1);
|
|
|
|
|
|
|
|
|
|
const notification = user.notifications[user.notifications.length - 1];
|
|
|
|
|
|
|
|
|
|
expect(notification.type).to.equal('NEW_STUFF');
|
2018-02-17 17:11:24 +00:00
|
|
|
// should be marked as seen by default so it's not counted in the number of notifications
|
2018-01-31 10:55:39 +00:00
|
|
|
expect(notification.seen).to.equal(true);
|
|
|
|
|
expect(notification.data.title).to.be.a.string;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('never adds two notifications', async () => {
|
|
|
|
|
const initialNotifications = user.notifications.length;
|
|
|
|
|
|
|
|
|
|
await user.post('/news/tell-me-later');
|
|
|
|
|
await user.post('/news/tell-me-later');
|
|
|
|
|
|
|
|
|
|
await user.sync();
|
|
|
|
|
|
|
|
|
|
expect(user.notifications.length).to.equal(initialNotifications + 1);
|
|
|
|
|
});
|
|
|
|
|
});
|