From 75f63b1367c1f28be6f7a63fe4c58b7f4d1fefaa Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Sat, 17 Oct 2015 19:19:40 -0500 Subject: [PATCH] Add functionality to generate user to update user --- package.json | 1 + test/helpers/api.helper.js | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 3ffdc11869..a14173614d 100644 --- a/package.json +++ b/package.json @@ -121,6 +121,7 @@ "karma-script-launcher": "~0.1.0", "lcov-result-merger": "^1.0.2", "mocha": "~1.12.1", + "mongodb": "^2.0.46", "mongoskin": "~0.6.1", "protractor": "~2.0.0", "rewire": "^2.3.3", diff --git a/test/helpers/api.helper.js b/test/helpers/api.helper.js index 31fdaf089e..6da6728d78 100644 --- a/test/helpers/api.helper.js +++ b/test/helpers/api.helper.js @@ -1,4 +1,5 @@ import {isEmpty} from 'lodash'; +import {MongoClient as mongo} from 'mongodb'; import {v4 as generateRandomUserName} from 'uuid'; import superagent from 'superagent'; @@ -27,7 +28,9 @@ export function generateUser(update={}) { password: password, confirmPassword: password, }).then((user) => { - resolve(user); + _updateDocument('users', user._id, update, () => { + resolve(user); + }); }); }); }; @@ -55,3 +58,18 @@ function _requestMaker(user, method) { }); } } + +function _updateDocument(collectionName, uuid, update, cb) { + if (isEmpty(update)) { return cb(); } + + mongo.connect('mongodb://localhost/habitrpg_test', (err, db) => { + if (err) throw `Error connecting to database when updating ${collectionName} collection: ${err}`; + + let collection = db.collection(collectionName); + + collection.update({ _id: uuid }, { $set: update }, (err, result) => { + if (err) throw `Error updating ${collectionName}: ${err}`; + cb(); + }); + }); +}