mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
failing unit test
This commit is contained in:
@@ -4,7 +4,7 @@ import { requester } from './requester';
|
||||
import {
|
||||
getDocument as getDocumentFromMongo,
|
||||
updateDocument as updateDocumentInMongo,
|
||||
} from './mongo';
|
||||
} from '../mongo';
|
||||
import {
|
||||
assign,
|
||||
each,
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
/* eslint-disable no-use-before-define */
|
||||
import nconf from 'nconf';
|
||||
import { MongoClient as mongo } from 'mongodb';
|
||||
|
||||
// Useful for checking things that have been deleted,
|
||||
// but you no longer have access to,
|
||||
// like private parties or users
|
||||
export async function checkExistence (collectionName, id) {
|
||||
let db = await connectToMongo();
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
let collection = db.collection(collectionName);
|
||||
|
||||
collection.find({_id: id}, {_id: 1}).limit(1).toArray((findError, docs) => {
|
||||
if (findError) return reject(findError);
|
||||
|
||||
let exists = docs.length > 0;
|
||||
|
||||
db.close();
|
||||
resolve(exists);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Specifically helpful for the GET /groups tests,
|
||||
// resets the db to an empty state and creates a tavern document
|
||||
export async function resetHabiticaDB () {
|
||||
let db = await connectToMongo();
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
db.dropDatabase((dbErr) => {
|
||||
if (dbErr) return reject(dbErr);
|
||||
let groups = db.collection('groups');
|
||||
|
||||
groups.insertOne({
|
||||
_id: 'habitrpg',
|
||||
chat: [],
|
||||
leader: '9',
|
||||
name: 'HabitRPG',
|
||||
type: 'guild',
|
||||
privacy: 'public',
|
||||
}, (insertErr) => {
|
||||
if (insertErr) return reject(insertErr);
|
||||
|
||||
db.close();
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export async function updateDocument (collectionName, doc, update) {
|
||||
let db = await connectToMongo();
|
||||
|
||||
let collection = db.collection(collectionName);
|
||||
|
||||
return new Promise((resolve) => {
|
||||
collection.updateOne({ _id: doc._id }, { $set: update }, (updateErr) => {
|
||||
if (updateErr) throw new Error(`Error updating ${collectionName}: ${updateErr}`);
|
||||
db.close();
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export async function getDocument (collectionName, doc) {
|
||||
let db = await connectToMongo();
|
||||
|
||||
let collection = db.collection(collectionName);
|
||||
|
||||
return new Promise((resolve) => {
|
||||
collection.findOne({ _id: doc._id }, (lookupErr, found) => {
|
||||
if (lookupErr) throw new Error(`Error looking up ${collectionName}: ${lookupErr}`);
|
||||
db.close();
|
||||
resolve(found);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function connectToMongo () {
|
||||
return new Promise((resolve, reject) => {
|
||||
mongo.connect(nconf.get('NODE_DB_URI'), (err, db) => {
|
||||
if (err) return reject(err);
|
||||
|
||||
resolve(db);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
import superagent from 'superagent';
|
||||
import nconf from 'nconf';
|
||||
import app from '../../../website/src/server';
|
||||
|
||||
const API_TEST_SERVER_PORT = nconf.get('PORT');
|
||||
let apiVersion;
|
||||
|
||||
@@ -6,7 +6,7 @@ requester.setApiVersion('v3');
|
||||
export { requester };
|
||||
|
||||
export { translate } from '../translate';
|
||||
export { checkExistence, resetHabiticaDB } from '../mongo';
|
||||
export { checkExistence, resetHabiticaDB } from '../../mongo';
|
||||
export * from './object-generators';
|
||||
|
||||
export async function sleep (seconds) {
|
||||
|
||||
Reference in New Issue
Block a user