mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-14 13:17:24 +01:00
fix test lint
This commit is contained in:
@@ -5,7 +5,7 @@ import common from '../../../../website/common';
|
||||
|
||||
describe('User Model', () => {
|
||||
it('keeps user._tmp when calling .toJSON', () => {
|
||||
let user = new User({
|
||||
const user = new User({
|
||||
auth: {
|
||||
local: {
|
||||
username: 'username',
|
||||
@@ -17,26 +17,26 @@ describe('User Model', () => {
|
||||
},
|
||||
});
|
||||
|
||||
user._tmp = {ok: true};
|
||||
user._nonTmp = {ok: true};
|
||||
user._tmp = { ok: true };
|
||||
user._nonTmp = { ok: true };
|
||||
|
||||
expect(user._tmp).to.eql({ok: true});
|
||||
expect(user._nonTmp).to.eql({ok: true});
|
||||
expect(user._tmp).to.eql({ ok: true });
|
||||
expect(user._nonTmp).to.eql({ ok: true });
|
||||
|
||||
let toObject = user.toObject();
|
||||
let toJSON = user.toJSON();
|
||||
const toObject = user.toObject();
|
||||
const toJSON = user.toJSON();
|
||||
|
||||
expect(toObject).to.not.have.keys('_tmp');
|
||||
expect(toObject).to.not.have.keys('_nonTmp');
|
||||
|
||||
expect(toJSON).to.have.any.key('_tmp');
|
||||
expect(toJSON._tmp).to.eql({ok: true});
|
||||
expect(toJSON._tmp).to.eql({ ok: true });
|
||||
expect(toJSON).to.not.have.keys('_nonTmp');
|
||||
});
|
||||
|
||||
it('can add computed stats to a JSONified user object', () => {
|
||||
let user = new User();
|
||||
let userToJSON = user.toJSON();
|
||||
const user = new User();
|
||||
const userToJSON = user.toJSON();
|
||||
|
||||
expect(userToJSON.stats.maxMP).to.not.exist;
|
||||
expect(userToJSON.stats.maxHealth).to.not.exist;
|
||||
@@ -50,9 +50,9 @@ describe('User Model', () => {
|
||||
});
|
||||
|
||||
it('can transform user object without mongoose helpers', async () => {
|
||||
let user = new User();
|
||||
const user = new User();
|
||||
await user.save();
|
||||
let userToJSON = await User.findById(user._id).lean().exec();
|
||||
const userToJSON = await User.findById(user._id).lean().exec();
|
||||
|
||||
expect(userToJSON.stats.maxMP).to.not.exist;
|
||||
expect(userToJSON.stats.maxHealth).to.not.exist;
|
||||
@@ -68,9 +68,9 @@ describe('User Model', () => {
|
||||
});
|
||||
|
||||
it('can transform user object without mongoose helpers (including computed stats)', async () => {
|
||||
let user = new User();
|
||||
const user = new User();
|
||||
await user.save();
|
||||
let userToJSON = await User.findById(user._id).lean().exec();
|
||||
const userToJSON = await User.findById(user._id).lean().exec();
|
||||
|
||||
expect(userToJSON.stats.maxMP).to.not.exist;
|
||||
expect(userToJSON.stats.maxHealth).to.not.exist;
|
||||
@@ -86,11 +86,11 @@ describe('User Model', () => {
|
||||
|
||||
context('notifications', () => {
|
||||
it('can add notifications without data', () => {
|
||||
let user = new User();
|
||||
const user = new User();
|
||||
|
||||
user.addNotification('CRON');
|
||||
|
||||
let userToJSON = user.toJSON();
|
||||
const userToJSON = user.toJSON();
|
||||
expect(user.notifications.length).to.equal(1);
|
||||
expect(userToJSON.notifications[0]).to.have.all.keys(['data', 'id', 'type', 'seen']);
|
||||
expect(userToJSON.notifications[0].type).to.equal('CRON');
|
||||
@@ -99,14 +99,15 @@ describe('User Model', () => {
|
||||
});
|
||||
|
||||
it('removes invalid notifications when calling toJSON', () => {
|
||||
let user = new User();
|
||||
const user = new User();
|
||||
|
||||
user.notifications = [
|
||||
null, // invalid, not an object
|
||||
{seen: true}, // invalid, no type or id
|
||||
{id: 123}, // invalid, no type
|
||||
// {type: 'ABC'}, // invalid, no id, not included here because the id would be added automatically
|
||||
{type: 'ABC', id: '123'}, // valid
|
||||
{ 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
|
||||
];
|
||||
|
||||
const userToJSON = user.toJSON();
|
||||
@@ -118,15 +119,15 @@ describe('User Model', () => {
|
||||
});
|
||||
|
||||
it('can add notifications with data and already marked as seen', () => {
|
||||
let user = new User();
|
||||
const user = new User();
|
||||
|
||||
user.addNotification('CRON', {field: 1}, true);
|
||||
user.addNotification('CRON', { field: 1 }, true);
|
||||
|
||||
let userToJSON = user.toJSON();
|
||||
const userToJSON = user.toJSON();
|
||||
expect(user.notifications.length).to.equal(1);
|
||||
expect(userToJSON.notifications[0]).to.have.all.keys(['data', 'id', 'type', 'seen']);
|
||||
expect(userToJSON.notifications[0].type).to.equal('CRON');
|
||||
expect(userToJSON.notifications[0].data).to.eql({field: 1});
|
||||
expect(userToJSON.notifications[0].data).to.eql({ field: 1 });
|
||||
expect(userToJSON.notifications[0].seen).to.eql(true);
|
||||
});
|
||||
|
||||
@@ -135,11 +136,11 @@ describe('User Model', () => {
|
||||
let user = new User();
|
||||
await user.save();
|
||||
|
||||
await User.pushNotification({_id: user._id}, 'CRON');
|
||||
await User.pushNotification({ _id: user._id }, 'CRON');
|
||||
|
||||
user = await User.findOne({_id: user._id}).exec();
|
||||
user = await User.findOne({ _id: user._id }).exec();
|
||||
|
||||
let userToJSON = user.toJSON();
|
||||
const userToJSON = user.toJSON();
|
||||
expect(user.notifications.length).to.equal(1);
|
||||
expect(userToJSON.notifications[0]).to.have.all.keys(['data', 'id', 'type', 'seen']);
|
||||
expect(userToJSON.notifications[0].type).to.equal('CRON');
|
||||
@@ -147,21 +148,21 @@ describe('User Model', () => {
|
||||
});
|
||||
|
||||
it('validates notifications via static method', async () => {
|
||||
let user = new User();
|
||||
const user = new User();
|
||||
await user.save();
|
||||
|
||||
expect(User.pushNotification({_id: user._id}, 'BAD_TYPE')).to.eventually.be.rejected;
|
||||
expect(User.pushNotification({_id: user._id}, 'CRON', null, 'INVALID_SEEN')).to.eventually.be.rejected;
|
||||
expect(User.pushNotification({ _id: user._id }, 'BAD_TYPE')).to.eventually.be.rejected;
|
||||
expect(User.pushNotification({ _id: user._id }, 'CRON', null, 'INVALID_SEEN')).to.eventually.be.rejected;
|
||||
});
|
||||
|
||||
it('adds notifications without data for all given users via static method', async () => {
|
||||
let user = new User();
|
||||
let otherUser = new User();
|
||||
const otherUser = new User();
|
||||
await Promise.all([user.save(), otherUser.save()]);
|
||||
|
||||
await User.pushNotification({_id: {$in: [user._id, otherUser._id]}}, 'CRON');
|
||||
await User.pushNotification({ _id: { $in: [user._id, otherUser._id] } }, 'CRON');
|
||||
|
||||
user = await User.findOne({_id: user._id}).exec();
|
||||
user = await User.findOne({ _id: user._id }).exec();
|
||||
|
||||
let userToJSON = user.toJSON();
|
||||
expect(user.notifications.length).to.equal(1);
|
||||
@@ -170,7 +171,7 @@ describe('User Model', () => {
|
||||
expect(userToJSON.notifications[0].data).to.eql({});
|
||||
expect(userToJSON.notifications[0].seen).to.eql(false);
|
||||
|
||||
user = await User.findOne({_id: otherUser._id}).exec();
|
||||
user = await User.findOne({ _id: otherUser._id }).exec();
|
||||
|
||||
userToJSON = user.toJSON();
|
||||
expect(user.notifications.length).to.equal(1);
|
||||
@@ -182,27 +183,27 @@ describe('User Model', () => {
|
||||
|
||||
it('adds notifications with data and seen status for all given users via static method', async () => {
|
||||
let user = new User();
|
||||
let otherUser = new User();
|
||||
const otherUser = new User();
|
||||
await Promise.all([user.save(), otherUser.save()]);
|
||||
|
||||
await User.pushNotification({_id: {$in: [user._id, otherUser._id]}}, 'CRON', {field: 1}, true);
|
||||
await User.pushNotification({ _id: { $in: [user._id, otherUser._id] } }, 'CRON', { field: 1 }, true);
|
||||
|
||||
user = await User.findOne({_id: user._id}).exec();
|
||||
user = await User.findOne({ _id: user._id }).exec();
|
||||
|
||||
let userToJSON = user.toJSON();
|
||||
expect(user.notifications.length).to.equal(1);
|
||||
expect(userToJSON.notifications[0]).to.have.all.keys(['data', 'id', 'type', 'seen']);
|
||||
expect(userToJSON.notifications[0].type).to.equal('CRON');
|
||||
expect(userToJSON.notifications[0].data).to.eql({field: 1});
|
||||
expect(userToJSON.notifications[0].data).to.eql({ field: 1 });
|
||||
expect(userToJSON.notifications[0].seen).to.eql(true);
|
||||
|
||||
user = await User.findOne({_id: otherUser._id}).exec();
|
||||
user = await User.findOne({ _id: otherUser._id }).exec();
|
||||
|
||||
userToJSON = user.toJSON();
|
||||
expect(user.notifications.length).to.equal(1);
|
||||
expect(userToJSON.notifications[0]).to.have.all.keys(['data', 'id', 'type', 'seen']);
|
||||
expect(userToJSON.notifications[0].type).to.equal('CRON');
|
||||
expect(userToJSON.notifications[0].data).to.eql({field: 1});
|
||||
expect(userToJSON.notifications[0].data).to.eql({ field: 1 });
|
||||
expect(userToJSON.notifications[0].seen).to.eql(true);
|
||||
});
|
||||
});
|
||||
@@ -245,7 +246,7 @@ describe('User Model', () => {
|
||||
let group;
|
||||
beforeEach(() => {
|
||||
user = new User();
|
||||
let leader = new User();
|
||||
const leader = new User();
|
||||
group = new Group({
|
||||
name: 'test',
|
||||
type: 'guild',
|
||||
@@ -379,7 +380,8 @@ describe('User Model', () => {
|
||||
|
||||
// Create conditions for the Beast Master achievement to be awarded
|
||||
user.achievements.beastMasterCount = 3;
|
||||
expect(user.achievements.beastMaster).to.not.equal(true); // verify that it was not awarded initially
|
||||
// verify that it was not awarded initially
|
||||
expect(user.achievements.beastMaster).to.not.equal(true);
|
||||
|
||||
user = await user.save();
|
||||
// verify that it's been awarded
|
||||
@@ -397,7 +399,8 @@ describe('User Model', () => {
|
||||
user = await User.findById(user._id).select('-items').exec();
|
||||
expect(user.isSelected('items')).to.equal(false);
|
||||
|
||||
// create the conditions for the beast master achievement but this time it should not be awarded
|
||||
// create the conditions for the beast master achievement
|
||||
// but this time it should not be awarded
|
||||
user.achievements.beastMasterCount = 3;
|
||||
user = await user.save();
|
||||
expect(user.achievements.beastMaster).to.equal(false);
|
||||
@@ -536,11 +539,9 @@ describe('User Model', () => {
|
||||
|
||||
const today = moment('2017-12-06T00:00:00.000-06:00'); // 11 pm on 4 Texas
|
||||
const req = {};
|
||||
req.header = () => {
|
||||
return timezoneOffset + 60;
|
||||
};
|
||||
req.header = () => timezoneOffset + 60;
|
||||
|
||||
const {daysMissed} = user.daysUserHasMissed(today, req);
|
||||
const { daysMissed } = user.daysUserHasMissed(today, req);
|
||||
|
||||
expect(daysMissed).to.eql(0);
|
||||
});
|
||||
@@ -554,11 +555,9 @@ describe('User Model', () => {
|
||||
|
||||
const today = moment('2017-12-06T02:00:00.000-08:00');
|
||||
const req = {};
|
||||
req.header = () => {
|
||||
return timezoneOffset + 60;
|
||||
};
|
||||
req.header = () => timezoneOffset + 60;
|
||||
|
||||
const {daysMissed} = user.daysUserHasMissed(today, req);
|
||||
const { daysMissed } = user.daysUserHasMissed(today, req);
|
||||
|
||||
expect(daysMissed).to.eql(0);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user