SubscriptionGroupControllerTests.coffee 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. SandboxedModule = require('sandboxed-module')
  2. should = require('chai').should()
  3. sinon = require 'sinon'
  4. assert = require("chai").assert
  5. modulePath = "../../../../app/js/Features/Subscription/SubscriptionGroupController"
  6. describe "Subscription Group Controller", ->
  7. beforeEach ->
  8. @user = {_id:"!@312431"}
  9. @subscription = {}
  10. @GroupHandler =
  11. addUserToGroup: sinon.stub().callsArgWith(2, null, @user)
  12. removeUserFromGroup: sinon.stub().callsArgWith(2)
  13. @SubscriptionLocator = getUsersSubscription: sinon.stub().callsArgWith(1, null, @subscription)
  14. @Controller = SandboxedModule.require modulePath, requires:
  15. "./SubscriptionGroupHandler":@GroupHandler
  16. "logger-sharelatex": log:->
  17. "./SubscriptionLocator": @SubscriptionLocator
  18. @adminUserId = "123jlkj"
  19. @req =
  20. session:
  21. user: _id: @adminUserId
  22. describe "addUserToGroup", ->
  23. it "should use the admin id for the logged in user and take the email address from the body", (done)->
  24. newEmail = "31231"
  25. @req.body = email: newEmail
  26. res =
  27. json : (data)=>
  28. @GroupHandler.addUserToGroup.calledWith(@adminUserId, newEmail).should.equal true
  29. data.user.should.deep.equal @user
  30. done()
  31. @Controller.addUserToGroup @req, res
  32. describe "removeUserFromGroup", ->
  33. it "should use the admin id for the logged in user and take the email address from the body", (done)->
  34. userIdToRemove = "31231"
  35. @req.params = user_id: userIdToRemove
  36. res =
  37. send : =>
  38. @GroupHandler.removeUserFromGroup.calledWith(@adminUserId, userIdToRemove).should.equal true
  39. done()
  40. @Controller.removeUserFromGroup @req, res
  41. describe "renderSubscriptionGroupAdminPage", ->
  42. it "should redirect you if you don't have a group account", (done)->
  43. @subscription.group = false
  44. res =
  45. redirect : (path)=>
  46. path.should.equal("/")
  47. done()
  48. @Controller.renderSubscriptionGroupAdminPage @req, res