2014-04-09 09:50:12 -04:00
|
|
|
sinon = require('sinon')
|
|
|
|
chai = require('chai')
|
|
|
|
should = chai.should()
|
|
|
|
expect = chai.expect
|
|
|
|
modulePath = "../../../../app/js/Features/User/UserController.js"
|
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
events = require "events"
|
|
|
|
MockResponse = require "../helpers/MockResponse"
|
|
|
|
MockRequest = require "../helpers/MockRequest"
|
|
|
|
ObjectId = require("mongojs").ObjectId
|
|
|
|
|
|
|
|
describe "UserController", ->
|
|
|
|
beforeEach ->
|
2014-04-09 10:41:19 -04:00
|
|
|
@user =
|
|
|
|
_id:"!@£!23123"
|
2014-04-09 11:33:54 -04:00
|
|
|
save:sinon.stub().callsArgWith(0)
|
|
|
|
ace:{}
|
2014-04-09 10:26:07 -04:00
|
|
|
|
|
|
|
@UserDeleter =
|
|
|
|
deleteUser: sinon.stub().callsArgWith(1)
|
2014-04-09 11:33:54 -04:00
|
|
|
@User =
|
2014-04-09 10:41:19 -04:00
|
|
|
findById: sinon.stub().callsArgWith(1, null, @user)
|
|
|
|
@NewsLetterManager =
|
|
|
|
unsubscribe: sinon.stub().callsArgWith(1)
|
2014-04-09 09:50:12 -04:00
|
|
|
@UserController = SandboxedModule.require modulePath, requires:
|
|
|
|
"./UserDeleter": @UserDeleter
|
2014-04-09 11:33:54 -04:00
|
|
|
"../../models/User": User:@User
|
2014-04-09 10:41:19 -04:00
|
|
|
'../Newsletter/NewsletterManager':@NewsLetterManager
|
2014-04-09 10:04:47 -04:00
|
|
|
"logger-sharelatex": {log:->}
|
|
|
|
|
2014-04-09 09:50:12 -04:00
|
|
|
|
|
|
|
@req = new MockRequest()
|
|
|
|
@res = new MockResponse()
|
|
|
|
@next = sinon.stub()
|
2014-04-09 10:41:19 -04:00
|
|
|
@user_id = "323123"
|
|
|
|
@req.session.user =
|
|
|
|
_id = @user_id
|
2014-04-09 09:50:12 -04:00
|
|
|
describe "deleteUser", ->
|
|
|
|
|
|
|
|
it "should delete the user", (done)->
|
2014-04-09 10:41:19 -04:00
|
|
|
|
2014-04-09 09:50:12 -04:00
|
|
|
@res.send = (code)=>
|
2014-04-09 10:41:19 -04:00
|
|
|
@UserDeleter.deleteUser.calledWith(@user_id)
|
2014-04-09 09:50:12 -04:00
|
|
|
code.should.equal 200
|
|
|
|
done()
|
|
|
|
@UserController.deleteUser @req, @res
|
|
|
|
|
2014-04-09 10:41:19 -04:00
|
|
|
describe "unsubscribe", ->
|
|
|
|
|
|
|
|
it "should send the user to unsubscribe", (done)->
|
|
|
|
@res.send = (code)=>
|
|
|
|
@NewsLetterManager.unsubscribe.calledWith(@user).should.equal true
|
|
|
|
done()
|
|
|
|
@UserController.unsubscribe @req, @res
|
|
|
|
|
|
|
|
|
2014-04-09 09:50:12 -04:00
|
|
|
|
2014-04-09 11:33:54 -04:00
|
|
|
describe "updateUserSettings", ->
|
|
|
|
|
|
|
|
it "should call save", (done)->
|
|
|
|
@req.body = {}
|
|
|
|
@res.send = (code)=>
|
|
|
|
@user.save.called.should.equal true
|
|
|
|
done()
|
|
|
|
@UserController.updateUserSettings @req, @res
|
|
|
|
|
|
|
|
|
|
|
|
it "should set the first name", (done)->
|
|
|
|
@req.body =
|
|
|
|
first_name: "bobby "
|
|
|
|
@res.send = (code)=>
|
|
|
|
@user.first_name.should.equal "bobby"
|
|
|
|
done()
|
|
|
|
@UserController.updateUserSettings @req, @res
|
|
|
|
|
|
|
|
it "should set some props on ace", (done)->
|
|
|
|
@req.body =
|
|
|
|
theme: "something "
|
|
|
|
@res.send = (code)=>
|
|
|
|
@user.ace.theme.should.equal "something"
|
|
|
|
done()
|
|
|
|
@UserController.updateUserSettings @req, @res
|
|
|
|
|
|
|
|
|