Fix POST /db/level/:names

This commit is contained in:
Scott Erickson 2016-08-31 09:56:35 -07:00
parent a7d51d672a
commit 956ff3300b
2 changed files with 14 additions and 0 deletions

View file

@ -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)

View file

@ -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()