diff --git a/server/classrooms/classroom_handler.coffee b/server/classrooms/classroom_handler.coffee index e756e9220..9ac4d217a 100644 --- a/server/classrooms/classroom_handler.coffee +++ b/server/classrooms/classroom_handler.coffee @@ -39,10 +39,9 @@ ClassroomHandler = class ClassroomHandler extends Handler joinClassroomAPI: (req, res, classroomID) -> return @sendBadInputError(res, 'Need an object with a code') unless req.body?.code - Classroom.findById classroomID, (err, classroom) => + Classroom.findOne {code: req.body.code}, (err, classroom) => return @sendDatabaseError(res, err) if err return @sendNotFoundError(res) if not classroom - return @sendBadInputError(res, 'Bad code') unless req.body.code is classroom.get('code') members = _.clone(classroom.get('members')) if _.any(members, (memberID) -> memberID.equals(req.user.get('_id'))) return @sendSuccess(res, @formatEntity(req, classroom)) diff --git a/test/server/functional/classrooms.spec.coffee b/test/server/functional/classrooms.spec.coffee index 9964c1d7a..ce121eb0d 100644 --- a/test/server/functional/classrooms.spec.coffee +++ b/test/server/functional/classrooms.spec.coffee @@ -5,7 +5,7 @@ mongoose = require 'mongoose' classroomsURL = getURL('/db/classroom') -describe 'GET /db/classrooms?ownerID=:id', -> +describe 'GET /db/classroom?ownerID=:id', -> it 'clears database users and classrooms', (done) -> clearModels [User, Classroom], (err) -> throw err if err @@ -34,7 +34,7 @@ describe 'GET /db/classrooms?ownerID=:id', -> done() -describe 'GET /db/classrooms/:id', -> +describe 'GET /db/classroom/:id', -> it 'clears database users and classrooms', (done) -> clearModels [User, Classroom], (err) -> throw err if err @@ -51,7 +51,7 @@ describe 'GET /db/classrooms/:id', -> expect(body._id).toBe(classroomID = body._id) done() -describe 'POST /db/classrooms', -> +describe 'POST /db/classroom', -> it 'clears database users and classrooms', (done) -> clearModels [User, Classroom], (err) -> @@ -76,7 +76,7 @@ describe 'POST /db/classrooms', -> done() -describe 'PUT /db/classrooms', -> +describe 'PUT /db/classroom', -> it 'clears database users and classrooms', (done) -> clearModels [User, Classroom], (err) -> @@ -102,7 +102,7 @@ describe 'PUT /db/classrooms', -> expect(res.statusCode).toBe(200) classroomCode = body.code loginNewUser (user2) -> - url = classroomsURL + '/' + body._id + '/members' + url = getURL("/db/classroom/~/members") data = { code: classroomCode } request.post { uri: url, json: data }, (err, res, body) -> expect(res.statusCode).toBe(200) @@ -111,8 +111,13 @@ describe 'PUT /db/classrooms', -> expect(res.statusCode).toBe(403) done() -describe 'POST /db/classrooms/:id/members', -> - +describe 'POST /db/classroom/:id/members', -> + + it 'clears database users and classrooms', (done) -> + clearModels [User, Classroom], (err) -> + throw err if err + done() + it 'adds the signed in user to the list of members in the classroom', (done) -> loginNewUser (user1) -> data = { name: 'Classroom 5' } @@ -120,14 +125,14 @@ describe 'POST /db/classrooms/:id/members', -> classroomCode = body.code expect(res.statusCode).toBe(200) loginNewUser (user2) -> - url = classroomsURL + '/' + body._id + '/members' + url = getURL("/db/classroom/~/members") data = { code: classroomCode } request.post { uri: url, json: data }, (err, res, body) -> expect(res.statusCode).toBe(200) done() -describe 'POST /db/classrooms/:id/invite-members', -> +describe 'POST /db/classroom/:id/invite-members', -> it 'takes a list of emails and sends invites', (done) -> loginNewUser (user1) ->