AnalyticsControllerTests.coffee 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. should = require('chai').should()
  2. SandboxedModule = require('sandboxed-module')
  3. assert = require('assert')
  4. path = require('path')
  5. modulePath = path.join __dirname, '../../../../app/js/Features/Analytics/AnalyticsController'
  6. sinon = require("sinon")
  7. expect = require("chai").expect
  8. describe 'AnalyticsController', ->
  9. beforeEach ->
  10. @AuthenticationController =
  11. getLoggedInUserId: sinon.stub()
  12. @AnalyticsManager =
  13. updateEditingSession: sinon.stub().callsArgWith(4)
  14. recordEvent: sinon.stub().callsArgWith(3)
  15. @controller = SandboxedModule.require modulePath, requires:
  16. "./AnalyticsManager":@AnalyticsManager
  17. "../Authentication/AuthenticationController":@AuthenticationController
  18. "logger-sharelatex":
  19. log:->
  20. @res =
  21. send:->
  22. describe "updateEditingSession", ->
  23. beforeEach ->
  24. @req =
  25. params:
  26. projectId: "a project id"
  27. session: {countryCode: 'US'}
  28. it "delegates to the AnalyticsManager", (done) ->
  29. @AuthenticationController.getLoggedInUserId.returns("1234")
  30. @controller.updateEditingSession @req, @res
  31. @AnalyticsManager.updateEditingSession.calledWith(
  32. "1234",
  33. "a project id",
  34. 'US',
  35. {}
  36. ).should.equal true
  37. done()
  38. describe "recordEvent", ->
  39. beforeEach ->
  40. @req =
  41. params:
  42. event:"i_did_something"
  43. body:"stuff"
  44. sessionID: "sessionIDHere"
  45. session: {}
  46. it "should use the user_id", (done)->
  47. @AuthenticationController.getLoggedInUserId.returns("1234")
  48. @controller.recordEvent @req, @res
  49. @AnalyticsManager.recordEvent.calledWith("1234", @req.params["event"], @req.body).should.equal true
  50. done()
  51. it "should use the session id", (done)->
  52. @controller.recordEvent @req, @res
  53. @AnalyticsManager.recordEvent.calledWith(@req.sessionID, @req.params["event"], @req.body).should.equal true
  54. done()