2014-02-12 05:23:40 -05:00
|
|
|
sinon = require('sinon')
|
|
|
|
chai = require('chai')
|
|
|
|
should = chai.should()
|
|
|
|
modulePath = "../../../../app/js/Features/User/UserLocator.js"
|
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
|
|
|
|
describe "UserLocator", ->
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
@user = {_id:"12390i"}
|
|
|
|
@UserLocator = SandboxedModule.require modulePath, requires:
|
|
|
|
"../../infrastructure/mongojs": db: @db = { users: {} }
|
2017-04-03 11:18:30 -04:00
|
|
|
"metrics-sharelatex": timeAsyncMethod: sinon.stub()
|
2017-05-22 10:33:52 -04:00
|
|
|
'logger-sharelatex' : { log: sinon.stub() }
|
2014-02-12 05:23:40 -05:00
|
|
|
@db.users =
|
|
|
|
findOne : sinon.stub().callsArgWith(1, null, @user)
|
|
|
|
|
|
|
|
@email = "bob.oswald@gmail.com"
|
|
|
|
|
|
|
|
|
|
|
|
describe "findByEmail", ->
|
|
|
|
|
|
|
|
it "should try and find a user with that email address", (done)->
|
|
|
|
@UserLocator.findByEmail @email, (err, user)=>
|
|
|
|
@db.users.findOne.calledWith(email:@email).should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should trim white space", (done)->
|
|
|
|
@UserLocator.findByEmail "#{@email} ", (err, user)=>
|
|
|
|
@db.users.findOne.calledWith(email:@email).should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should return the user if found", (done)->
|
|
|
|
@UserLocator.findByEmail @email, (err, user)=>
|
|
|
|
user.should.deep.equal @user
|
|
|
|
done()
|
|
|
|
|
|
|
|
|
|
|
|
|