ReferalFeaturesTests.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  12. */
  13. const SandboxedModule = require('sandboxed-module')
  14. const assert = require('assert')
  15. require('chai').should()
  16. const sinon = require('sinon')
  17. const modulePath = require('path').join(
  18. __dirname,
  19. '../../../../app/src/Features/Referal/ReferalFeatures.js'
  20. )
  21. describe('ReferalFeatures', function() {
  22. beforeEach(function() {
  23. this.ReferalFeatures = SandboxedModule.require(modulePath, {
  24. globals: {
  25. console: console
  26. },
  27. requires: {
  28. '../../models/User': {
  29. User: (this.User = {})
  30. },
  31. 'settings-sharelatex': (this.Settings = {}),
  32. 'logger-sharelatex': {
  33. log() {},
  34. err() {}
  35. }
  36. }
  37. })
  38. this.callback = sinon.stub()
  39. this.referal_id = 'referal-id-123'
  40. this.referal_medium = 'twitter'
  41. this.user_id = 'user-id-123'
  42. return (this.new_user_id = 'new-user-id-123')
  43. })
  44. describe('getBonusFeatures', function() {
  45. beforeEach(function() {
  46. this.refered_user_count = 3
  47. this.Settings.bonus_features = {
  48. '3': {
  49. collaborators: 3,
  50. dropbox: false,
  51. versioning: false
  52. }
  53. }
  54. const stubbedUser = {
  55. refered_user_count: this.refered_user_count,
  56. features: { collaborators: 1, dropbox: false, versioning: false }
  57. }
  58. this.User.findOne = sinon.stub().callsArgWith(1, null, stubbedUser)
  59. return this.ReferalFeatures.getBonusFeatures(this.user_id, this.callback)
  60. })
  61. it('should get the users number of refered user', function() {
  62. return this.User.findOne
  63. .calledWith({ _id: this.user_id })
  64. .should.equal(true)
  65. })
  66. it('should call the callback with the features', function() {
  67. return this.callback
  68. .calledWith(null, this.Settings.bonus_features[3])
  69. .should.equal(true)
  70. })
  71. })
  72. describe('when the user is not at a bonus level', function() {
  73. beforeEach(function() {
  74. this.refered_user_count = 0
  75. this.Settings.bonus_features = {
  76. '1': {
  77. collaborators: 3,
  78. dropbox: false,
  79. versioning: false
  80. }
  81. }
  82. this.User.findOne = sinon
  83. .stub()
  84. .callsArgWith(1, null, { refered_user_count: this.refered_user_count })
  85. return this.ReferalFeatures.getBonusFeatures(this.user_id, this.callback)
  86. })
  87. it('should get the users number of refered user', function() {
  88. return this.User.findOne
  89. .calledWith({ _id: this.user_id })
  90. .should.equal(true)
  91. })
  92. it('should call the callback with no features', function() {
  93. return this.callback.calledWith(null, {}).should.equal(true)
  94. })
  95. })
  96. })