Fix GET /db/level/:handle/session

When making a course session and user has a HoC course instance (no associated classroom)
This commit is contained in:
Scott Erickson 2016-05-25 10:26:03 -07:00
parent e218af8418
commit b0ad8b2573
2 changed files with 9 additions and 1 deletions
server/middleware
spec/server/functional

View file

@ -52,7 +52,9 @@ module.exports =
classroomMap[classroom.id] = classroom for classroom in classrooms
levelOriginal = level.get('original')
for courseInstance in courseInstances
classroom = classroomMap[courseInstance.get('classroomID').toString()]
classroomID = courseInstance.get('classroomID')
continue unless classroomID
classroom = classroomMap[classroomID.toString()]
courseID = courseInstance.get('courseID')
classroomCourse = _.find(classroom.get('courses'), (c) -> c._id.equals(courseID))
for courseLevel in classroomCourse.levels

View file

@ -80,6 +80,12 @@ describe 'GET /db/level/:handle/session', ->
expect(res.statusCode).toBe(200)
expect(body.codeLanguage).toBe('python')
done()
it 'does not break if the user has a courseInstance without an associated classroom', utils.wrap (done) ->
yield @courseInstance.update({$unset: {classroomID: ''}})
[res, body] = yield request.getAsync { uri: @url, json: true }
expect(res.statusCode).toBe(402)
done()
it 'returns 402 if the user is not in a course with that level', utils.wrap (done) ->
otherStudent = yield utils.initUser({role: 'student'})