EmailBuilderTests.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* eslint-disable
  2. max-len,
  3. no-return-assign,
  4. no-unused-vars,
  5. */
  6. // TODO: This file was created by bulk-decaffeinate.
  7. // Fix any style issues and re-enable lint.
  8. /*
  9. * decaffeinate suggestions:
  10. * DS102: Remove unnecessary code created because of implicit returns
  11. * DS207: Consider shorter variations of null checks
  12. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  13. */
  14. const should = require('chai').should()
  15. const SandboxedModule = require('sandboxed-module')
  16. const assert = require('assert')
  17. const path = require('path')
  18. const sinon = require('sinon')
  19. const modulePath = path.join(
  20. __dirname,
  21. '../../../../app/src/Features/Email/EmailBuilder'
  22. )
  23. const { expect } = require('chai')
  24. const _ = require('underscore')
  25. _.templateSettings = { interpolate: /\{\{(.+?)\}\}/g }
  26. describe('EmailBuilder', function() {
  27. beforeEach(function() {
  28. this.settings = {
  29. appName: 'testApp',
  30. brandPrefix: ''
  31. }
  32. return (this.EmailBuilder = SandboxedModule.require(modulePath, {
  33. globals: {
  34. console: console
  35. },
  36. requires: {
  37. 'settings-sharelatex': this.settings,
  38. 'logger-sharelatex': {
  39. log() {}
  40. }
  41. }
  42. }))
  43. })
  44. describe('projectInvite', function() {
  45. beforeEach(function() {
  46. return (this.opts = {
  47. to: 'bob@bob.com',
  48. first_name: 'bob',
  49. owner: {
  50. email: 'sally@hally.com'
  51. },
  52. inviteUrl: 'http://example.com/invite',
  53. project: {
  54. url: 'http://www.project.com',
  55. name: 'standard project'
  56. }
  57. })
  58. })
  59. describe('when sending a normal email', function() {
  60. beforeEach(function() {
  61. return (this.email = this.EmailBuilder.buildEmail(
  62. 'projectInvite',
  63. this.opts
  64. ))
  65. })
  66. it('should have html and text properties', function() {
  67. expect(this.email.html != null).to.equal(true)
  68. return expect(this.email.text != null).to.equal(true)
  69. })
  70. it('should not have undefined in it', function() {
  71. this.email.html.indexOf('undefined').should.equal(-1)
  72. return this.email.subject.indexOf('undefined').should.equal(-1)
  73. })
  74. })
  75. describe('when someone is up to no good', function() {
  76. beforeEach(function() {
  77. this.opts.project.name = "<img src='http://evilsite.com/evil.php'>"
  78. return (this.email = this.EmailBuilder.buildEmail(
  79. 'projectInvite',
  80. this.opts
  81. ))
  82. })
  83. it('should not contain unescaped html in the html part', function() {
  84. return expect(this.email.html).to.contain('New Project')
  85. })
  86. it('should not have undefined in it', function() {
  87. this.email.html.indexOf('undefined').should.equal(-1)
  88. return this.email.subject.indexOf('undefined').should.equal(-1)
  89. })
  90. })
  91. })
  92. describe('SpamSafe', function() {
  93. beforeEach(function() {
  94. this.opts = {
  95. to: 'bob@joe.com',
  96. first_name: 'bob',
  97. owner: {
  98. email: 'sally@hally.com'
  99. },
  100. inviteUrl: 'http://example.com/invite',
  101. project: {
  102. url: 'http://www.project.com',
  103. name: 'come buy my product at http://notascam.com'
  104. }
  105. }
  106. return (this.email = this.EmailBuilder.buildEmail(
  107. 'projectInvite',
  108. this.opts
  109. ))
  110. })
  111. it('should replace spammy project name', function() {
  112. this.email.html.indexOf('a new project').should.not.equal(-1)
  113. return this.email.subject.indexOf('New Project').should.not.equal(-1)
  114. })
  115. })
  116. })