habitica/test/api/unit/models/userNotification.test.js

22 lines
915 B
JavaScript
Raw Normal View History

2018-06-18 12:40:25 +00:00
import { model as UserNotification } from '../../../../website/server/models/userNotification';
2018-02-04 12:28:05 +00:00
describe('UserNotification Model', () => {
context('convertNotificationsToSafeJson', () => {
it('converts an array of notifications to a safe version', () => {
const notifications = [
null, // invalid, not an object
2019-10-08 18:45:38 +00:00
{ seen: true }, // invalid, no type or id
{ id: 123 }, // invalid, no type
{ type: 'ABC' }, // invalid, no id
new UserNotification({ type: 'ABC', id: 123 }), // valid
2018-02-04 12:28:05 +00:00
];
const notificationsToJSON = UserNotification.convertNotificationsToSafeJson(notifications);
expect(notificationsToJSON.length).to.equal(1);
expect(notificationsToJSON[0]).to.have.all.keys(['data', 'id', 'type', 'seen']);
expect(notificationsToJSON[0].type).to.equal('ABC');
expect(notificationsToJSON[0].id).to.equal('123');
});
});
});