From 956ff3300b4c4bcf9f0462ec93edd111b4c303a0 Mon Sep 17 00:00:00 2001 From: Scott Erickson Date: Wed, 31 Aug 2016 09:56:35 -0700 Subject: [PATCH] Fix POST /db/level/:names --- server/routes/index.coffee | 1 + spec/server/functional/level.spec.coffee | 13 +++++++++++++ 2 files changed, 14 insertions(+) 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()