EmailHandlerTests.coffee 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. should = require('chai').should()
  2. SandboxedModule = require('sandboxed-module')
  3. assert = require('assert')
  4. path = require('path')
  5. sinon = require('sinon')
  6. modulePath = path.join __dirname, "../../../../app/js/Features/Email/EmailHandler"
  7. expect = require("chai").expect
  8. describe "EmailHandler", ->
  9. beforeEach ->
  10. @settings = {}
  11. @EmailTemplator =
  12. buildEmail:sinon.stub()
  13. @EmailSender =
  14. sendEmail:sinon.stub()
  15. @EmailHandler = SandboxedModule.require modulePath, requires:
  16. "./EmailTemplator":@EmailTemplator
  17. "./EmailSender":@EmailSender
  18. "settings-sharelatex":@settings
  19. "logger-sharelatex": log:->
  20. @html = "<html>hello</html>"
  21. describe "send email", ->
  22. it "should use the correct options", (done)->
  23. @EmailTemplator.buildEmail.returns({html:@html})
  24. @EmailSender.sendEmail.callsArgWith(1)
  25. opts =
  26. to: "bob@bob.com"
  27. @EmailHandler.sendEmail "welcome", opts, =>
  28. args = @EmailSender.sendEmail.args[0][0]
  29. args.html.should.equal @html
  30. done()
  31. it "should return the erroor", (done)->
  32. @EmailTemplator.buildEmail.returns({html:@html})
  33. @EmailSender.sendEmail.callsArgWith(1, "error")
  34. opts =
  35. to: "bob@bob.com"
  36. subject:"hello bob"
  37. @EmailHandler.sendEmail "welcome", opts, (err)=>
  38. err.should.equal "error"
  39. done()