UserLocatorTests.coffee 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. sinon = require('sinon')
  2. chai = require('chai')
  3. should = chai.should()
  4. modulePath = "../../../../app/js/Features/User/UserLocator.js"
  5. SandboxedModule = require('sandboxed-module')
  6. describe "UserLocator", ->
  7. beforeEach ->
  8. @user = {_id:"12390i"}
  9. @UserLocator = SandboxedModule.require modulePath, requires:
  10. "../../infrastructure/mongojs": db: @db = { users: {} }
  11. "metrics-sharelatex": timeAsyncMethod: sinon.stub()
  12. 'logger-sharelatex' : { log: sinon.stub() }
  13. @db.users =
  14. findOne : sinon.stub().callsArgWith(1, null, @user)
  15. @email = "bob.oswald@gmail.com"
  16. describe "findByEmail", ->
  17. it "should try and find a user with that email address", (done)->
  18. @UserLocator.findByEmail @email, (err, user)=>
  19. @db.users.findOne.calledWith(email:@email).should.equal true
  20. done()
  21. it "should trim white space", (done)->
  22. @UserLocator.findByEmail "#{@email} ", (err, user)=>
  23. @db.users.findOne.calledWith(email:@email).should.equal true
  24. done()
  25. it "should return the user if found", (done)->
  26. @UserLocator.findByEmail @email, (err, user)=>
  27. user.should.deep.equal @user
  28. done()