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 { defaultsDeep as defaults } from 'lodash';
|
||||||
import { model as User } from '../../website/src/models/user';
|
import { model as User } from '../../website/src/models/user';
|
||||||
import { model as Group } from '../../website/src/models/group';
|
import { model as Group } from '../../website/src/models/group';
|
||||||
|
import mongo from './mongo'; // eslint-disable-line
|
||||||
|
|
||||||
afterEach((done) => {
|
afterEach((done) => {
|
||||||
sandbox.restore();
|
sandbox.restore();
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import nconf from 'nconf';
|
|||||||
//------------------------------
|
//------------------------------
|
||||||
require('../../website/src/libs/api-v3/setupNconf')('./config.json.example');
|
require('../../website/src/libs/api-v3/setupNconf')('./config.json.example');
|
||||||
nconf.set('NODE_DB_URI', 'mongodb://localhost/habitrpg_test');
|
nconf.set('NODE_DB_URI', 'mongodb://localhost/habitrpg_test');
|
||||||
|
nconf.set('NODE_ENV', 'test');
|
||||||
// We require src/server and npt src/index because
|
// We require src/server and npt src/index because
|
||||||
// 1. nconf is already setup
|
// 1. nconf is already setup
|
||||||
// 2. we don't need clustering
|
// 2. we don't need clustering
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ export async function checkExistence (collectionName, id) {
|
|||||||
// Specifically helpful for the GET /groups tests,
|
// Specifically helpful for the GET /groups tests,
|
||||||
// resets the db to an empty state and creates a tavern document
|
// resets the db to an empty state and creates a tavern document
|
||||||
export async function resetHabiticaDB () {
|
export async function resetHabiticaDB () {
|
||||||
console.log('calling resetHabiticaDatabase'); // eslint-disable-line
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
mongoose.connection.db.dropDatabase((dbErr) => {
|
mongoose.connection.db.dropDatabase((dbErr) => {
|
||||||
if (dbErr) return reject(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 * as firebase from '../libs/api-v2/firebase';
|
||||||
import baseModel from '../libs/api-v3/baseModel';
|
import baseModel from '../libs/api-v3/baseModel';
|
||||||
import Q from 'q';
|
import Q from 'q';
|
||||||
|
import nconf from 'nconf';
|
||||||
|
|
||||||
let Schema = mongoose.Schema;
|
let Schema = mongoose.Schema;
|
||||||
|
|
||||||
@@ -513,10 +514,11 @@ export const INVITES_LIMIT = 100;
|
|||||||
export let model = mongoose.model('Group', schema);
|
export let model = mongoose.model('Group', schema);
|
||||||
|
|
||||||
// initialize tavern if !exists (fresh installs)
|
// 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) => {
|
model.count({_id: 'habitrpg'}, (err, ct) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
if (ct > 0) return;
|
if (ct > 0) return;
|
||||||
|
|
||||||
new model({ // eslint-disable-line babel/new-cap
|
new model({ // eslint-disable-line babel/new-cap
|
||||||
_id: 'habitrpg',
|
_id: 'habitrpg',
|
||||||
leader: '9', // TODO change this user id
|
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
|
validateBeforeSave: false, // _id = 'habitrpg' would not be valid otherwise
|
||||||
}); // TODO catch/log?
|
}); // TODO catch/log?
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user