mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
finally fix tests
This commit is contained in:
@@ -3,6 +3,7 @@ import mongoose from 'mongoose';
|
||||
import { defaultsDeep as defaults } from 'lodash';
|
||||
import { model as User } from '../../website/src/models/user';
|
||||
import { model as Group } from '../../website/src/models/group';
|
||||
import mongo from './mongo'; // eslint-disable-line
|
||||
|
||||
afterEach((done) => {
|
||||
sandbox.restore();
|
||||
|
||||
@@ -18,6 +18,7 @@ import nconf from 'nconf';
|
||||
//------------------------------
|
||||
require('../../website/src/libs/api-v3/setupNconf')('./config.json.example');
|
||||
nconf.set('NODE_DB_URI', 'mongodb://localhost/habitrpg_test');
|
||||
nconf.set('NODE_ENV', 'test');
|
||||
// We require src/server and npt src/index because
|
||||
// 1. nconf is already setup
|
||||
// 2. we don't need clustering
|
||||
|
||||
@@ -20,7 +20,6 @@ export async function checkExistence (collectionName, id) {
|
||||
// Specifically helpful for the GET /groups tests,
|
||||
// resets the db to an empty state and creates a tavern document
|
||||
export async function resetHabiticaDB () {
|
||||
console.log('calling resetHabiticaDatabase'); // eslint-disable-line
|
||||
return new Promise((resolve, reject) => {
|
||||
mongoose.connection.db.dropDatabase((dbErr) => {
|
||||
if (dbErr) return reject(dbErr);
|
||||
|
||||
@@ -11,6 +11,7 @@ import { removeFromArray } from '../libs/api-v3/collectionManipulators';
|
||||
import * as firebase from '../libs/api-v2/firebase';
|
||||
import baseModel from '../libs/api-v3/baseModel';
|
||||
import Q from 'q';
|
||||
import nconf from 'nconf';
|
||||
|
||||
let Schema = mongoose.Schema;
|
||||
|
||||
@@ -513,10 +514,11 @@ export const INVITES_LIMIT = 100;
|
||||
export let model = mongoose.model('Group', schema);
|
||||
|
||||
// initialize tavern if !exists (fresh installs)
|
||||
model.count({_id: 'habitrpg'}, (err, ct) => {
|
||||
// do not run when testing as it's handled by the tests and can easily cause a race condition
|
||||
if (nconf.get('NODE_ENV') !== 'test') {
|
||||
model.count({_id: 'habitrpg'}, (err, ct) => {
|
||||
if (err) throw err;
|
||||
if (ct > 0) return;
|
||||
|
||||
new model({ // eslint-disable-line babel/new-cap
|
||||
_id: 'habitrpg',
|
||||
leader: '9', // TODO change this user id
|
||||
@@ -526,4 +528,5 @@ model.count({_id: 'habitrpg'}, (err, ct) => {
|
||||
}).save({
|
||||
validateBeforeSave: false, // _id = 'habitrpg' would not be valid otherwise
|
||||
}); // TODO catch/log?
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user