Skip to content

Commit

Permalink
fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipthelen committed Oct 25, 2023
1 parent 83f2d91 commit ca86511
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 80 deletions.
4 changes: 2 additions & 2 deletions gulp/gulp-console.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import mongoose from 'mongoose';
import nconf from 'nconf';
import repl from 'repl';
import gulp from 'gulp';
import logger from '../website/server/libs/logger';
import {
getDevelopmentConnectionUrl,
getDefaultConnectionOptions,
Expand Down Expand Up @@ -38,7 +37,8 @@ const improveRepl = context => {

mongoose.connect(
connectionUrl,
mongooseOptions);
mongooseOptions,
);
};

gulp.task('console', done => {
Expand Down
19 changes: 9 additions & 10 deletions gulp/gulp-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,15 @@ gulp.task('test:prepare:mongo', cb => {
const mongooseOptions = getDefaultConnectionOptions();
const connectionUrl = getDevelopmentConnectionUrl(TEST_DB_URI);

mongoose.connect(connectionUrl, mongooseOptions).then(() => {
return mongoose.connection.dropDatabase();
}).then(() => {
return mongoose.connection.close();
}).then(() => {
cb();
}).catch(err => {
if (err) return cb(`Unable to connect to mongo database. Are you sure it's running? \n\n${err}`);
throw err
});
mongoose.connect(connectionUrl, mongooseOptions)
.then(() => mongoose.connection.dropDatabase())
.then(() => mongoose.connection.close()).then(() => {
cb();
})
.catch(err => {
if (err) return cb(`Unable to connect to mongo database. Are you sure it's running? \n\n${err}`);
throw err;
});
});

gulp.task('test:prepare:server', gulp.series('test:prepare:mongo', done => {
Expand Down
6 changes: 3 additions & 3 deletions test/api/unit/libs/password.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ describe('Password Utilities', () => {
expiresAt: moment().subtract({ minutes: 1 }),
}));

await user.update({
await user.updateOne({
'auth.local.passwordResetCode': code,
});

Expand Down Expand Up @@ -264,7 +264,7 @@ describe('Password Utilities', () => {
expiresAt: moment().add({ days: 1 }),
}));

await user.update({
await user.updateOne({
'auth.local.passwordResetCode': 'invalid',
});

Expand All @@ -280,7 +280,7 @@ describe('Password Utilities', () => {
expiresAt: moment().add({ days: 1 }),
}));

await user.update({
await user.updateOne({
'auth.local.passwordResetCode': code,
});

Expand Down
12 changes: 6 additions & 6 deletions test/api/unit/middlewares/cronMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ describe('cron middleware', () => {
cronMiddleware(req, res, err => {
if (err) return reject(err);

Tasks.Task.findOne({ _id: task }).then(task => {
expect(task).to.not.exist;
Tasks.Task.findOne({ _id: task }).then(foundTask => {
expect(foundTask).to.not.exist;
resolve();
});

Expand All @@ -76,8 +76,8 @@ describe('cron middleware', () => {
await new Promise((resolve, reject) => {
cronMiddleware(req, res, err => {
if (err) return reject(err);
Tasks.Task.findOne({ _id: task }).then(task => {
expect(task).to.exist;
Tasks.Task.findOne({ _id: task }).then(foundTask => {
expect(foundTask).to.exist;
return resolve();
});
return null;
Expand All @@ -99,8 +99,8 @@ describe('cron middleware', () => {
await new Promise((resolve, reject) => {
cronMiddleware(req, res, err => {
if (err) return reject(err);
Tasks.Task.findOne({ _id: task }).then(task => {
expect(task).to.not.exist;
Tasks.Task.findOne({ _id: task }).then(foundTask => {
expect(foundTask).to.not.exist;
return resolve();
});
return null;
Expand Down
2 changes: 1 addition & 1 deletion test/api/unit/models/newsPost.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('NewsPost Model', () => {
_id: v4(), publishDate: new Date(), published: true,
};
NewsPost.updateLastNewsPost(previousPost);
intervalId = refreshNewsPost(50); // refreshes every 50ms
intervalId = refreshNewsPost(100); // refreshes every 100ms

await sleep(0.1); // wait 100ms to make sure the new post has a more recent publishDate
const newPost = await NewsPost.create({
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/api-unit.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export { translationCheck } from './translate';

afterEach(() => {
sandbox.restore();
return mongoose.connection.dropDatabase()
return mongoose.connection.dropDatabase();
});

export { sleep } from './sleep';
Expand Down
18 changes: 8 additions & 10 deletions test/helpers/common.helper.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import mongoose from 'mongoose';

import { model as User } from '../../website/server/models/user';
import {
daily,
habit,
reward,
todo,
daily as Daily,
habit as Habit,
reward as Reward,
todo as Todo,
} from '../../website/server/models/task';

export { translate } from './translate';
Expand All @@ -17,17 +15,17 @@ export function generateUser (options = {}) {
}

export function generateDaily (options = {}) {
return new daily(options).toObject();
return new Daily(options).toObject();
}

export function generateHabit (options = {}) {
return new habit(options).toObject();
return new Habit(options).toObject();
}

export function generateReward (options = {}) {
return new reward(options).toObject();
return new Reward(options).toObject();
}

export function generateTodo (options = {}) {
return new todo(options).toObject();
return new Todo(options).toObject();
}
73 changes: 36 additions & 37 deletions test/helpers/mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export async function checkExistence (collectionName, id) {
// Obtain a property from the database. Useful if the property is private
// and thus unavailable to the client
export async function getProperty (collectionName, id, path) {
const doc = await mongoose.connection.db.collection(collectionName).find({ _id: id }, { [path]: 1 }, {limit: 1}).next();
const doc = await mongoose.connection.db.collection(collectionName)
.find({ _id: id }, { [path]: 1 }, { limit: 1 }).next();
return get(doc, path);
}

Expand All @@ -23,54 +24,53 @@ export async function resetHabiticaDB () {
const groups = mongoose.connection.db.collection('groups');
const users = mongoose.connection.db.collection('users');
return mongoose.connection.dropDatabase()
.then(() => {
return users.countDocuments({ _id: '7bde7864-ebc5-4ee2-a4b7-1070d464cdb0' });
}).then(count => {
if (count > 0) return;
return users.insertOne({
_id: '7bde7864-ebc5-4ee2-a4b7-1070d464cdb0',
apiToken: TAVERN_ID,
auth: {
local: {
username: 'username',
lowerCaseUsername: 'username',
email: '[email protected]',
hashed_password: 'hashed_password', // eslint-disable-line camelcase
passwordHashMethod: 'bcrypt',
},
},
.then(() => users.countDocuments({ _id: '7bde7864-ebc5-4ee2-a4b7-1070d464cdb0' })).then(count => {
if (count === 0) {
users.insertOne({
_id: '7bde7864-ebc5-4ee2-a4b7-1070d464cdb0',
apiToken: TAVERN_ID,
auth: {
local: {
username: 'username',
lowerCaseUsername: 'username',
email: '[email protected]',
hashed_password: 'hashed_password', // eslint-disable-line camelcase
passwordHashMethod: 'bcrypt',
},
},
});
}
}).then(() => groups.countDocuments({ _id: TAVERN_ID }))
.then(count => {
if (count === 0) {
groups.insertOne({
_id: TAVERN_ID,
chat: [],
leader: '7bde7864-ebc5-4ee2-a4b7-1070d464cdb0', // Siena Leslie
name: 'HabitRPG',
type: 'guild',
privacy: 'public',
memberCount: 0,
});
}
});
}).then(() => {
return groups.countDocuments({ _id: TAVERN_ID });
}).then(count => {
if (count > 0) return;
return groups.insertOne({
_id: TAVERN_ID,
chat: [],
leader: '7bde7864-ebc5-4ee2-a4b7-1070d464cdb0', // Siena Leslie
name: 'HabitRPG',
type: 'guild',
privacy: 'public',
memberCount: 0,
});
})
}

export async function updateDocument (collectionName, doc, update) {
const collection = mongoose.connection.db.collection(collectionName);
return await collection.updateOne({ _id: doc._id }, { $set: update });
return collection.updateOne({ _id: doc._id }, { $set: update });
}

// Unset a property in the database.
// Useful for testing.
export async function unsetDocument (collectionName, doc, update) {
const collection = mongoose.connection.db.collection(collectionName);
return await collection.updateOne({ _id: doc._id }, { $unset: update });
return collection.updateOne({ _id: doc._id }, { $unset: update });
}

export async function getDocument (collectionName, doc) {
const collection = mongoose.connection.db.collection(collectionName);
return await collection.findOne({ _id: doc._id });
return collection.findOne({ _id: doc._id });
}

before(done => {
Expand All @@ -80,9 +80,8 @@ before(done => {
.then(() => {
done();
})
.catch(err => {
logger.error(err);
throw err;
.catch(error => {
throw error;
});
});
});
Expand Down
1 change: 0 additions & 1 deletion test/helpers/start-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ if (process.env.LOAD_SERVER === '0') { // when the server is in a different proc
setupNconf('./config.json');
// Use Q promises instead of mpromise in mongoose
mongoose.connect(nconf.get('TEST_DB_URI'));
console.log("connecting");
} else { // When running tests and the server in the same process
setupNconf('./config.json.example');
nconf.set('NODE_DB_URI', nconf.get('TEST_DB_URI'));
Expand Down
4 changes: 2 additions & 2 deletions website/server/controllers/api-v3/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ api.joinGroup = {
{
$set: { 'achievements.partyUp': true },
$push: { notifications: notification.toObject() },
}
},
).exec());

if (inviter) {
Expand All @@ -704,7 +704,7 @@ api.joinGroup = {
{
$set: { 'achievements.partyOn': true },
$push: { notifications: notification.toObject() },
}
},
).exec());

if (inviter) {
Expand Down
1 change: 0 additions & 1 deletion website/server/libs/password.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export async function validatePasswordResetCodeAndFindUser (code) {

if (isCodeValid) {
user = await User.findById(userId).exec();
console.log("found user")
// check if user is found
if (!user) {
isCodeValid = false;
Expand Down
5 changes: 3 additions & 2 deletions website/server/middlewares/domain.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import domainMiddleware from 'domain-middleware';
const logger = require('../libs/logger');

import logger from '../libs/logger';

export default function implementDomainMiddleware (server, mongoose) {
return domainMiddleware({
server: {
close () {
logger.info("Closing Server");
logger.info('Closing Server');
server.close();
mongoose.connection.close();
},
Expand Down
5 changes: 2 additions & 3 deletions website/server/models/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,6 @@ schema.methods.leave = async function leaveGroup (user, keep = 'keep-all', keepC
_.remove(members, { _id: user._id });

if (members.length === 0) {
console.log("deleting group")
promises.push(group.deleteOne());
return Promise.all(promises);
}
Expand Down Expand Up @@ -1641,8 +1640,8 @@ export const model = mongoose.model('Group', schema);
// initialize tavern if !exists (fresh installs)
// do not run when testing as it's handled by the tests and can easily cause a race condition
if (!nconf.get('IS_TEST')) {
model.countDocuments({ _id: TAVERN_ID }).then( (count) => {
if (count == 0) {
model.countDocuments({ _id: TAVERN_ID }).then(count => {
if (count === 0) {
new model({ // eslint-disable-line new-cap
_id: TAVERN_ID,
leader: '7bde7864-ebc5-4ee2-a4b7-1070d464cdb0', // Siena Leslie
Expand Down
2 changes: 1 addition & 1 deletion website/server/models/user/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ schema.pre('validate', function preValidateUser (next) {
next();
});

schema.pre('save', { document: true }, function preSaveUser (next, done) {
schema.pre('save', true, function preSaveUser (next, done) {
next();

// VERY IMPORTANT NOTE: when only some fields from an user document are selected
Expand Down

0 comments on commit ca86511

Please sign in to comment.