test(curriculum): use Mocha for tests

This commit is contained in:
Valeriy
2018-10-25 03:34:47 +03:00
committed by mrugesh mohapatra
parent 73485119f4
commit 62cc8acb87
7 changed files with 534 additions and 723 deletions

View File

@ -0,0 +1,24 @@
const _ = require('lodash');
const { isMongoId } = require('validator');
class MongoIds {
constructor() {
this.knownIds = [];
}
check(id, title) {
if (!isMongoId(id)) {
throw new Error(`Expected a valid ObjectId for ${title}, but got ${id}`);
}
const idIndex = _.findIndex(this.knownIds, existing => id === existing);
if (idIndex !== -1) {
throw new Error(`
All challenges must have a unique id.
The id for ${title} is already assigned
`);
}
this.knownIds = [ ...this.knownIds, id ];
}
}
module.exports = MongoIds;