Add functionality to generate user to update user

This commit is contained in:
Blade Barringer
2015-10-17 19:19:40 -05:00
parent 7f6b392511
commit 75f63b1367
2 changed files with 20 additions and 1 deletions

View File

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

View File

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