UserLocatorTests.coffee 1.0 KB

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