From 7dab7939cceaf26df140120642ce274695e5e62c Mon Sep 17 00:00:00 2001 From: Matteo Pagliazzi Date: Sat, 23 Apr 2016 03:33:00 +0200 Subject: [PATCH] v3: fix tavern during tests --- test/helpers/mongo.js | 43 ++++++++++++++++++------ website/src/controllers/api-v3/groups.js | 4 +-- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/test/helpers/mongo.js b/test/helpers/mongo.js index 463f375e8e..6b51ff2af0 100644 --- a/test/helpers/mongo.js +++ b/test/helpers/mongo.js @@ -25,23 +25,46 @@ export async function resetHabiticaDB () { mongoose.connection.db.dropDatabase((dbErr) => { if (dbErr) return reject(dbErr); let groups = mongoose.connection.db.collection('groups'); + let users = mongoose.connection.db.collection('users'); - // For some mysterious reason after a dropDatabase there can still be a group... - groups.count({_id: TAVERN_ID}, (err, count) => { + users.count({_id: '7bde7864-ebc5-4ee2-a4b7-1070d464cdb0'}, (err, count) => { if (err) return reject(err); if (count > 0) return resolve(); - groups.insertOne({ - _id: TAVERN_ID, - chat: [], - leader: '9', - name: 'HabitRPG', - type: 'guild', - privacy: 'public', + // create the leader for the tavern + users.insertOne({ + _id: '7bde7864-ebc5-4ee2-a4b7-1070d464cdb0', + apiToken: TAVERN_ID, + auth: { + local: { + username: 'username', + lowerCaseUsername: 'username', + email: 'username@email.com', + salt: 'salt', + hashed_password: 'hashed_password', // eslint-disable-line camelcase + }, + }, }, (insertErr) => { if (insertErr) return reject(insertErr); - resolve(); + // For some mysterious reason after a dropDatabase there can still be a group... + groups.count({_id: TAVERN_ID}, (err2, count2) => { + if (err2) return reject(err2); + if (count2 > 0) return resolve(); + + groups.insertOne({ + _id: TAVERN_ID, + chat: [], + leader: '7bde7864-ebc5-4ee2-a4b7-1070d464cdb0', // Siena Leslie + name: 'HabitRPG', + type: 'guild', + privacy: 'public', + }, (insertErr2) => { + if (insertErr2) return reject(insertErr2); + + resolve(); + }); + }); }); }); }); diff --git a/website/src/controllers/api-v3/groups.js b/website/src/controllers/api-v3/groups.js index 13f3179db0..3f4a7aabb4 100644 --- a/website/src/controllers/api-v3/groups.js +++ b/website/src/controllers/api-v3/groups.js @@ -207,7 +207,7 @@ api.joinGroup = { let user = res.locals.user; let inviter; - req.checkParams('groupId', res.t('groupIdRequired')).notEmpty().isUUID(); + req.checkParams('groupId', res.t('groupIdRequired')).notEmpty(); // .isUUID(); can't be used because it would block 'habitrpg' or 'party' let validationErrors = req.validationErrors(); if (validationErrors) throw validationErrors; @@ -302,7 +302,7 @@ api.rejectGroupInvite = { async handler (req, res) { let user = res.locals.user; - req.checkParams('groupId', res.t('groupIdRequired')).notEmpty().isUUID(); + req.checkParams('groupId', res.t('groupIdRequired')).notEmpty(); // .isUUID(); can't be used because it would block 'habitrpg' or 'party' let validationErrors = req.validationErrors(); if (validationErrors) throw validationErrors;