mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
Add helper to check the existence of a document
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
checkExistence,
|
||||||
createAndPopulateGroup,
|
createAndPopulateGroup,
|
||||||
generateGroup,
|
generateGroup,
|
||||||
generateUser,
|
generateUser,
|
||||||
@@ -84,13 +85,10 @@ describe('POST /groups/:id/leave', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('group is not accessible after leaving', () => {
|
it('group is deleted', () => {
|
||||||
return expect(api.post(`/groups/${group._id}/leave`).then((result) => {
|
return expect(api.post(`/groups/${group._id}/leave`).then((result) => {
|
||||||
return api.get(`/groups/${group._id}`);
|
return checkExistence('groups', group._id);
|
||||||
})).to.eventually.be.rejected.and.eql({
|
})).to.eventually.eql(false);
|
||||||
code: 404,
|
|
||||||
text: t('messageGroupNotFound'),
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,23 @@ export function translate(key, variables) {
|
|||||||
return translatedString;
|
return translatedString;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Useful for checking things that have been deleted,
|
||||||
|
// but you no longer have access to,
|
||||||
|
// like private parties or users
|
||||||
|
export function checkExistence(collectionName, id) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
mongo.connect('mongodb://localhost/habitrpg_test', (err, db) => {
|
||||||
|
if (err) return reject(err);
|
||||||
|
let collection = db.collection(collectionName);
|
||||||
|
collection.find({_id: id}, {_id: 1}).limit(1).toArray((err, docs) => {
|
||||||
|
let exists = docs.length > 0;
|
||||||
|
db.close();
|
||||||
|
resolve(exists);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Creates a new user and returns it
|
// Creates a new user and returns it
|
||||||
// If you need the user to have specific requirements,
|
// If you need the user to have specific requirements,
|
||||||
// such as a balance > 0, just pass in the adjustment
|
// such as a balance > 0, just pass in the adjustment
|
||||||
|
|||||||
Reference in New Issue
Block a user