mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-14 13:17:24 +01:00
notifications tests
This commit is contained in:
@@ -195,17 +195,23 @@ describe('User Model', () => {
|
||||
expect(userToJSON.notifications[0].seen).to.eql(false);
|
||||
});
|
||||
|
||||
it('removes invalid notifications when calling toJSON', () => {
|
||||
const user = new User();
|
||||
it('removes invalid notifications when loading the user', async () => {
|
||||
let user = new User();
|
||||
await user.save();
|
||||
await user.update({
|
||||
$set: {
|
||||
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
|
||||
],
|
||||
},
|
||||
}).exec();
|
||||
|
||||
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
|
||||
];
|
||||
user = await User.findById(user._id).exec();
|
||||
|
||||
const userToJSON = user.toJSON();
|
||||
expect(userToJSON.notifications.length).to.equal(1);
|
||||
@@ -215,26 +221,6 @@ 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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user