mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-14 05:07:22 +01:00
34 lines
1.3 KiB
JavaScript
34 lines
1.3 KiB
JavaScript
import { model as PushDevice } from '../../../../website/server/models/pushDevice';
|
|
|
|
describe('PushDevice Model', () => {
|
|
context('cleanupCorruptData', () => {
|
|
it('converts an array of push devices to a safe version', () => {
|
|
const pushDevices = [
|
|
null, // invalid, not an object
|
|
{ regId: '123' }, // invalid, no type
|
|
{ type: 'android' }, // invalid, no regId
|
|
new PushDevice({ type: 'android', regId: '1234' }), // valid
|
|
];
|
|
|
|
const safePushDevices = PushDevice.cleanupCorruptData(pushDevices);
|
|
expect(safePushDevices.length).to.equal(1);
|
|
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');
|
|
});
|
|
});
|
|
});
|