Fix POST /db/earned_achievement to be accessible to anonymous users

This commit is contained in:
Scott Erickson 2016-08-31 10:07:19 -07:00
parent 956ff3300b
commit 273845ce2e
2 changed files with 4 additions and 3 deletions

View file

@ -98,7 +98,7 @@ 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))

View file

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