refactor notifications cleanup

This commit is contained in:
Matteo Pagliazzi
2020-03-01 20:06:24 +01:00
parent 343f276705
commit 118e3580d6
3 changed files with 51 additions and 23 deletions

View File

@@ -181,7 +181,7 @@ describe('User Model', () => {
});
});
context('notifications', () => {
context.only('notifications', () => {
it('can add notifications without data', () => {
const user = new User();
@@ -215,6 +215,26 @@ describe('User Model', () => {
expect(userToJSON.notifications[0].id).to.equal('123');
});
it('removes invalid notifications when saving', async () => {
const user = new User();
user.notifications = [
null, // invalid, not an object
{ seen: true }, // invalid, no type or id
{ id: 123 }, // invalid, no type
// invalid, no id, not included here because the id would be added automatically
// {type: 'ABC'},
{ type: 'ABC', id: '123' }, // valid
];
await user.save();
expect(user.notifications.length).to.equal(1);
expect(user.notifications[0]).to.have.all.keys(['data', 'id', 'type', 'seen']);
expect(user.notifications[0].type).to.equal('ABC');
expect(user.notifications[0].id).to.equal('123');
});
it('can add notifications with data and already marked as seen', () => {
const user = new User();