* fix: handle missing solutions correctly Rather than creating an [[]] the parser now creates [] which isEmpty(). This makes the test suite check the next challenge for a solution. In addition, the logic for testing solutions was fixed. * chore: update snapshots * test: build new superblock in node.js-tests CI * test: allow forward slash in superblock slug * fix: borked tests oops * test: ignore duplicated projects * fix: i did not break these shaun did :) * fix: idIndex is index of id not id Co-authored-by: Nicholas Carrigan <nhcarrigan@gmail.com>
36 lines
931 B
JavaScript
36 lines
931 B
JavaScript
const Joi = require('joi');
|
|
const findIndex = require('lodash/findIndex');
|
|
Joi.objectId = require('joi-objectid')(Joi);
|
|
|
|
const schema = Joi.objectId();
|
|
const duplicatedProjectIds = [
|
|
'bd7158d8c442eddfaeb5bd18',
|
|
'587d78af367417b2b2512b03',
|
|
'587d78af367417b2b2512b04',
|
|
'587d78b0367417b2b2512b05',
|
|
'bd7158d8c242eddfaeb5bd13'
|
|
];
|
|
|
|
class MongoIds {
|
|
constructor() {
|
|
this.knownIds = [];
|
|
}
|
|
check(id, title) {
|
|
try {
|
|
schema.validate(id);
|
|
} catch {
|
|
throw Error(`Expected a valid ObjectId for ${title}, but got ${id}`);
|
|
}
|
|
|
|
const idIndex = findIndex(this.knownIds, existing => id === existing);
|
|
if (idIndex !== -1 && !duplicatedProjectIds.includes(id)) {
|
|
throw Error(`The id for challenge ${title} appears more than once.
|
|
With the exception of duplicatedProjectIds this should not happen.
|
|
`);
|
|
}
|
|
this.knownIds = [...this.knownIds, id];
|
|
}
|
|
}
|
|
|
|
module.exports = MongoIds;
|