UserLocatorTests.coffee 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. @db.users =
  13. findOne : sinon.stub().callsArgWith(1, null, @user)
  14. @email = "bob.oswald@gmail.com"
  15. describe "findByEmail", ->
  16. it "should try and find a user with that email address", (done)->
  17. @UserLocator.findByEmail @email, (err, user)=>
  18. @db.users.findOne.calledWith(email:@email).should.equal true
  19. done()
  20. it "should trim white space", (done)->
  21. @UserLocator.findByEmail "#{@email} ", (err, user)=>
  22. @db.users.findOne.calledWith(email:@email).should.equal true
  23. done()
  24. it "should return the user if found", (done)->
  25. @UserLocator.findByEmail @email, (err, user)=>
  26. user.should.deep.equal @user
  27. done()