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

50 lines
1.5 KiB
CoffeeScript
Raw Normal View History

2014-05-16 12:45:48 -04: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
@UserGetter =
getUserByMainEmail: sinon.stub()
2014-05-16 12:45:48 -04:00
@UserUpdater = SandboxedModule.require modulePath, requires:
"settings-sharelatex":@settings
"logger-sharelatex": log:->
"./UserGetter": @UserGetter
2014-05-16 12:45:48 -04:00
"../../infrastructure/mongojs":@mongojs
"metrics-sharelatex": timeAsyncMethod: sinon.stub()
2014-05-16 12:45:48 -04:00
@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)->
@UserGetter.getUserByMainEmail.callsArgWith(1, null, @stubbedUser)
2014-05-19 06:50:32 -04:00
@UserUpdater.changeEmailAddress @user_id, @stubbedUser.email, (err)=>
2014-05-16 12:45:48 -04:00
@UserUpdater.updateUser.called.should.equal false
should.exist(err)
done()
it "should set the users password", (done)->
@UserGetter.getUserByMainEmail.callsArgWith(1, null)
2014-05-16 12:45:48 -04:00
@UserUpdater.changeEmailAddress @user_id, @newEmail, (err)=>
@UserUpdater.updateUser.calledWith(@user_id, $set: { "email": @newEmail}).should.equal true
done()
2014-06-11 07:46:28 -04:00