mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-04-15 12:16:22 +00:00
add final tests for push devices and notifications
This commit is contained in:
parent
3f5ee32684
commit
979d0c519d
3 changed files with 110 additions and 0 deletions
|
|
@ -15,5 +15,19 @@ describe('PushDevice Model', () => {
|
|||
expect(safePushDevices[0].type).to.equal('android');
|
||||
expect(safePushDevices[0].regId).to.equal('1234');
|
||||
});
|
||||
|
||||
it('removes duplicates', () => {
|
||||
const pushDevices = [
|
||||
new PushDevice({ type: 'android', regId: '1234' }),
|
||||
new PushDevice({ type: 'android', regId: '1234' }),
|
||||
new PushDevice({ type: 'iphone', regId: '1234' }), // not duplicate
|
||||
new PushDevice({ type: 'android', regId: '12345' }), // not duplicate
|
||||
];
|
||||
|
||||
const safePushDevices = PushDevice.cleanupCorruptData(pushDevices);
|
||||
expect(safePushDevices.length).to.equal(3);
|
||||
expect(safePushDevices[0].type).to.equal('android');
|
||||
expect(safePushDevices[0].regId).to.equal('1234');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -206,6 +206,28 @@ describe('User Model', () => {
|
|||
expect(userToJSON.pushDevices[0].regId).to.equal('1234');
|
||||
});
|
||||
|
||||
it('removes duplicate push devices when loading the user', async () => {
|
||||
let user = new User();
|
||||
await user.save();
|
||||
await user.update({
|
||||
$set: {
|
||||
pushDevices: [
|
||||
{ type: 'android', regId: '1234' },
|
||||
{ type: 'android', regId: '1234' },
|
||||
],
|
||||
},
|
||||
}).exec();
|
||||
|
||||
user = await User.findById(user._id).exec();
|
||||
|
||||
const userToJSON = user.toJSON();
|
||||
expect(userToJSON.pushDevices.length).to.equal(1);
|
||||
|
||||
expect(userToJSON.pushDevices[0]).to.have.all.keys(['regId', 'type', 'createdAt', 'updatedAt']);
|
||||
expect(userToJSON.pushDevices[0].type).to.equal('android');
|
||||
expect(userToJSON.pushDevices[0].regId).to.equal('1234');
|
||||
});
|
||||
|
||||
it('removes invalid notifications when loading the user', async () => {
|
||||
let user = new User();
|
||||
await user.save();
|
||||
|
|
@ -231,6 +253,48 @@ describe('User Model', () => {
|
|||
expect(userToJSON.notifications[0].type).to.equal('ABC');
|
||||
expect(userToJSON.notifications[0].id).to.equal('123');
|
||||
});
|
||||
|
||||
it('removes multiple NEW_CHAT_MESSAGE for the same group', async () => {
|
||||
let user = new User();
|
||||
await user.save();
|
||||
await user.update({
|
||||
$set: {
|
||||
notifications: [
|
||||
{
|
||||
type: 'NEW_CHAT_MESSAGE',
|
||||
id: 123,
|
||||
data: { group: { id: 12345 } },
|
||||
},
|
||||
{
|
||||
type: 'NEW_CHAT_MESSAGE',
|
||||
id: 1234,
|
||||
data: { group: { id: 12345 } },
|
||||
},
|
||||
{
|
||||
type: 'NEW_CHAT_MESSAGE',
|
||||
id: 123,
|
||||
data: { group: { id: 123456 } },
|
||||
}, // not duplicate, different group
|
||||
{
|
||||
type: 'NEW_CHAT_MESSAGE_DIFF',
|
||||
id: 123,
|
||||
data: { group: { id: 12345 } },
|
||||
}, // not duplicate, different type
|
||||
],
|
||||
},
|
||||
}).exec();
|
||||
|
||||
user = await User.findById(user._id).exec();
|
||||
|
||||
const userToJSON = user.toJSON();
|
||||
expect(userToJSON.notifications.length).to.equal(3);
|
||||
|
||||
expect(userToJSON.notifications[0]).to.have.all.keys(['data', 'id', 'type', 'seen']);
|
||||
expect(userToJSON.notifications[0].type).to.equal('NEW_CHAT_MESSAGE');
|
||||
expect(userToJSON.notifications[0].id).to.equal('123');
|
||||
expect(userToJSON.notifications[0].data).to.deep.equal({ group: { id: 12345 } });
|
||||
expect(userToJSON.notifications[0].seen).to.equal(false);
|
||||
});
|
||||
});
|
||||
|
||||
context('notifications', () => {
|
||||
|
|
|
|||
|
|
@ -18,5 +18,37 @@ describe('UserNotification Model', () => {
|
|||
expect(safeNotifications[0].type).to.equal('ABC');
|
||||
expect(safeNotifications[0].id).to.equal('123');
|
||||
});
|
||||
|
||||
it('removes multiple NEW_CHAT_MESSAGE for the same group', () => {
|
||||
const notifications = [
|
||||
new UserNotification({
|
||||
type: 'NEW_CHAT_MESSAGE',
|
||||
id: 123,
|
||||
data: { group: { id: 12345 } },
|
||||
}),
|
||||
new UserNotification({
|
||||
type: 'NEW_CHAT_MESSAGE',
|
||||
id: 1234,
|
||||
data: { group: { id: 12345 } },
|
||||
}),
|
||||
new UserNotification({
|
||||
type: 'NEW_CHAT_MESSAGE',
|
||||
id: 123,
|
||||
data: { group: { id: 123456 } },
|
||||
}), // not duplicate, different group
|
||||
new UserNotification({
|
||||
type: 'NEW_CHAT_MESSAGE_DIFF',
|
||||
id: 123,
|
||||
data: { group: { id: 12345 } },
|
||||
}), // not duplicate, different type
|
||||
];
|
||||
|
||||
const safeNotifications = UserNotification.cleanupCorruptData(notifications);
|
||||
expect(safeNotifications.length).to.equal(3);
|
||||
expect(safeNotifications[0].data).to.deep.equal({ group: { id: 12345 } });
|
||||
expect(safeNotifications[0].seen).to.equal(false);
|
||||
expect(safeNotifications[0].type).to.equal('NEW_CHAT_MESSAGE');
|
||||
expect(safeNotifications[0].id).to.equal('123');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue