Wire up account settings forms
This commit is contained in:
@@ -95,6 +95,22 @@ describe "UserController", ->
|
||||
done()
|
||||
@UserController.updateUserSettings @req, @res
|
||||
|
||||
it "should set the role", (done)->
|
||||
@req.body =
|
||||
role: "student"
|
||||
@res.send = (code)=>
|
||||
@user.role.should.equal "student"
|
||||
done()
|
||||
@UserController.updateUserSettings @req, @res
|
||||
|
||||
it "should set the institution", (done)->
|
||||
@req.body =
|
||||
institution: "MIT"
|
||||
@res.send = (code)=>
|
||||
@user.institution.should.equal "MIT"
|
||||
done()
|
||||
@UserController.updateUserSettings @req, @res
|
||||
|
||||
it "should set some props on ace", (done)->
|
||||
@req.body =
|
||||
theme: "something"
|
||||
|
||||
@@ -124,51 +124,3 @@ describe "UserInfoController", ->
|
||||
institution: @user.institution
|
||||
}
|
||||
|
||||
describe "setPersonalInfo", ->
|
||||
|
||||
beforeEach ->
|
||||
@req =
|
||||
session:
|
||||
user:
|
||||
_id:"123123j321jikuj90jlk"
|
||||
@req.body =
|
||||
first_name: "bob"
|
||||
last_name: "smith"
|
||||
role:"student"
|
||||
institution: "Sheffield"
|
||||
notWanted: "something"
|
||||
|
||||
it "should send the data from the body to the user updater", (done)->
|
||||
|
||||
@UserUpdater.updatePersonalInfo.callsArgWith(2, null)
|
||||
@res.send = (statusCode)=>
|
||||
statusCode.should.equal 204
|
||||
@UserUpdater.updatePersonalInfo.args[0][0].should.equal @req.session.user._id
|
||||
args = @UserUpdater.updatePersonalInfo.args[0][1]
|
||||
args.first_name.should.equal @req.body.first_name
|
||||
args.last_name.should.equal @req.body.last_name
|
||||
args.role.should.equal @req.body.role
|
||||
args.institution.should.equal @req.body.institution
|
||||
assert.equal args.notWanted, undefined
|
||||
done()
|
||||
|
||||
@UserInfoController.updatePersonalInfo @req, @res
|
||||
|
||||
it "should sanitize the data", (done)->
|
||||
@UserUpdater.updatePersonalInfo.callsArgWith(2, null)
|
||||
@res.send = (statusCode)=>
|
||||
@sanitizer.escape.calledWith(@req.body.first_name).should.equal true
|
||||
@sanitizer.escape.calledWith(@req.body.last_name).should.equal true
|
||||
@sanitizer.escape.calledWith(@req.body.role).should.equal true
|
||||
@sanitizer.escape.calledWith(@req.body.institution).should.equal true
|
||||
done()
|
||||
@UserInfoController.updatePersonalInfo @req, @res
|
||||
|
||||
it "should send an error if the UpserUpdater returns on", (done)->
|
||||
@UserUpdater.updatePersonalInfo.callsArgWith(2, "error")
|
||||
@res.send = (statusCode)->
|
||||
statusCode.should.equal 500
|
||||
done()
|
||||
@UserInfoController.updatePersonalInfo @req, @res
|
||||
|
||||
|
||||
|
||||
@@ -46,39 +46,3 @@ describe "UserUpdater", ->
|
||||
@UserUpdater.updateUser.calledWith(@user_id, $set: { "email": @newEmail}).should.equal true
|
||||
done()
|
||||
|
||||
describe "updatePersonalInfo", ->
|
||||
|
||||
beforeEach ->
|
||||
@info =
|
||||
first_name:"billy"
|
||||
last_name:"brag"
|
||||
role:"student"
|
||||
institution:"sheffield"
|
||||
|
||||
it "should set the names role and institution", (done)->
|
||||
@UserUpdater.updateUser = sinon.stub().callsArgWith(2)
|
||||
@UserUpdater.updatePersonalInfo @user_id, @info, (err)=>
|
||||
@UserUpdater.updateUser.args[0][0].should.equal @user_id
|
||||
args = @UserUpdater.updateUser.args[0][1]
|
||||
args["$set"].first_name.should.equal @info.first_name
|
||||
args["$set"].last_name.should.equal @info.last_name
|
||||
args["$set"].role.should.equal @info.role
|
||||
args["$set"].institution.should.equal @info.institution
|
||||
done()
|
||||
|
||||
it "should return the error", (done)->
|
||||
@UserUpdater.updateUser = sinon.stub().callsArgWith(2, "error")
|
||||
@UserUpdater.updatePersonalInfo @user_id, @info, (err)=>
|
||||
should.exist(err)
|
||||
done()
|
||||
|
||||
it "should default them to empty strings", (done)->
|
||||
@UserUpdater.updateUser = sinon.stub().callsArgWith(2)
|
||||
@UserUpdater.updatePersonalInfo @user_id, {}, (err)=>
|
||||
args = @UserUpdater.updateUser.args[0][1]
|
||||
args["$set"].first_name.should.equal ""
|
||||
args["$set"].last_name.should.equal ""
|
||||
args["$set"].role.should.equal ""
|
||||
args["$set"].institution.should.equal ""
|
||||
done()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user