diff --git a/server/routes/index.coffee b/server/routes/index.coffee index cfca0edb5..59329ed9e 100644 --- a/server/routes/index.coffee +++ b/server/routes/index.coffee @@ -98,9 +98,10 @@ module.exports.setup = (app) -> app.get('/db/course_instance/:handle/course', mw.auth.checkLoggedIn(), mw.courseInstances.fetchCourse) EarnedAchievement = require '../models/EarnedAchievement' - app.post('/db/earned_achievement', mw.auth.checkLoggedIn(), mw.earnedAchievements.post) + app.post('/db/earned_achievement', mw.auth.checkHasUser(), 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/achievement.spec.coffee b/spec/server/functional/achievement.spec.coffee index af8b2c94c..e8761ba6c 100644 --- a/spec/server/functional/achievement.spec.coffee +++ b/spec/server/functional/achievement.spec.coffee @@ -172,9 +172,10 @@ describe 'POST /db/earned_achievement', -> eaURL = getURL('/db/earned_achievement') it 'manually creates earned achievements for level achievements, which do not happen automatically', utils.wrap (done) -> + user = yield utils.becomeAnonymous() session = new LevelSession({ permissions: simplePermissions - creator: @admin._id + creator: user._id level: original: 'dungeon-arena' }) yield session.save() @@ -184,7 +185,7 @@ describe 'POST /db/earned_achievement', -> [res, body] = yield request.postAsync { url: eaURL, json } expect(res.statusCode).toBe(201) expect(body.achievement).toBe @unlockable.id - expect(body.user).toBe @admin.id + expect(body.user).toBe user.id expect(body.notified).toBeFalsy() expect(body.earnedPoints).toBe unlockable.worth expect(body.achievedAmount).toBeUndefined() 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()