finally fix tests

This commit is contained in:
Matteo Pagliazzi
2016-01-29 12:52:57 +01:00
parent 80160597b0
commit 361d0aa35c
4 changed files with 19 additions and 15 deletions

View File

@@ -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();

View File

@@ -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

View File

@@ -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);

View File

@@ -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)
// 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
@@ -527,3 +529,4 @@ model.count({_id: 'habitrpg'}, (err, ct) => {
validateBeforeSave: false, // _id = 'habitrpg' would not be valid otherwise
}); // TODO catch/log?
});
}