diff --git a/server/routes/index.coffee b/server/routes/index.coffee index cfca0edb5..ac0592419 100644 --- a/server/routes/index.coffee +++ b/server/routes/index.coffee @@ -101,6 +101,7 @@ module.exports.setup = (app) -> app.post('/db/earned_achievement', mw.auth.checkLoggedIn(), mw.earnedAchievements.post) Level = require '../models/Level' + app.post('/db/level/names', mw.named.names(Level)) app.post('/db/level/:handle', mw.auth.checkLoggedIn(), mw.versions.postNewVersion(Level, { hasPermissionsOrTranslations: 'artisan' })) # TODO: add /new-version to route like Article has app.get('/db/level/:handle/session', mw.auth.checkHasUser(), mw.levels.upsertSession) diff --git a/spec/server/functional/level.spec.coffee b/spec/server/functional/level.spec.coffee index 273468e95..4d45bee37 100644 --- a/spec/server/functional/level.spec.coffee +++ b/spec/server/functional/level.spec.coffee @@ -230,3 +230,16 @@ describe 'GET /db/level/:handle/session', -> [res, body] = yield request.getAsync { uri: @url, json: true } expect(res.statusCode).toBe(200) done() + + +describe 'POST /db/level/names', -> + + it 'returns names of levels whose ids have been POSTed', utils.wrap (done) -> + levels = yield _.times(5, utils.makeLevel) + levelIDs = _.map(levels, (level) -> level.id) + [res, body] = yield request.postAsync { url: utils.getURL('/db/level/names'), json: { ids: levelIDs } } + expect(res.statusCode).toBe(200) + expect(res.body.length).toBe(5) + aLevel = levels[2] + expect(_.find(body, (l) -> l._id is aLevel.id).name).toBe(aLevel.get('name')) + done()