overleaf/services/web/test/UnitTests/coffee/User/UserUpdaterTests.coffee

48 lines
1.4 KiB
CoffeeScript
Raw Normal View History

2014-05-16 16:45:48 +00:00
should = require('chai').should()
SandboxedModule = require('sandboxed-module')
assert = require('assert')
path = require('path')
sinon = require('sinon')
modulePath = path.join __dirname, "../../../../app/js/Features/User/UserUpdater"
expect = require("chai").expect
describe "UserUpdater", ->
beforeEach ->
@settings = {}
@mongojs =
db:{}
ObjectId:(id)-> return id
@UserLocator =
2014-05-19 10:50:32 +00:00
findByEmail:sinon.stub()
2014-05-16 16:45:48 +00:00
@UserUpdater = SandboxedModule.require modulePath, requires:
"settings-sharelatex":@settings
"logger-sharelatex": log:->
"./UserLocator":@UserLocator
"../../infrastructure/mongojs":@mongojs
@stubbedUser =
name:"bob"
email:"hello@world.com"
@user_id = "3131231"
@newEmail = "bob@bob.com"
describe "changeEmailAddress", ->
beforeEach ->
@UserUpdater.updateUser = sinon.stub().callsArgWith(2)
it "should check if the new email already has an account", (done)->
2014-05-19 10:50:32 +00:00
@UserLocator.findByEmail.callsArgWith(1, null, @stubbedUser)
@UserUpdater.changeEmailAddress @user_id, @stubbedUser.email, (err)=>
2014-05-16 16:45:48 +00:00
@UserUpdater.updateUser.called.should.equal false
should.exist(err)
done()
it "should set the users password", (done)->
2014-05-19 10:50:32 +00:00
@UserLocator.findByEmail.callsArgWith(1, null)
2014-05-16 16:45:48 +00:00
@UserUpdater.changeEmailAddress @user_id, @newEmail, (err)=>
@UserUpdater.updateUser.calledWith(@user_id, $set: { "email": @newEmail}).should.equal true
done()