mirror of
https://github.com/overleaf/overleaf.git
synced 2025-02-17 10:04:24 +00:00
add tests for AnalyticsController
This commit is contained in:
parent
d722f47b0f
commit
f910bb58de
1 changed files with 44 additions and 0 deletions
|
@ -0,0 +1,44 @@
|
|||
should = require('chai').should()
|
||||
SandboxedModule = require('sandboxed-module')
|
||||
assert = require('assert')
|
||||
path = require('path')
|
||||
modulePath = path.join __dirname, '../../../../app/js/Features/Analytics/AnalyticsController'
|
||||
sinon = require("sinon")
|
||||
expect = require("chai").expect
|
||||
|
||||
|
||||
describe 'AnalyticsController', ->
|
||||
|
||||
beforeEach ->
|
||||
@AuthenticationController =
|
||||
getLoggedInUserId: sinon.stub()
|
||||
|
||||
@AnalyticsManager =
|
||||
recordEvent: sinon.stub().callsArgWith(3)
|
||||
|
||||
@req =
|
||||
params:
|
||||
event:"i_did_something"
|
||||
body:"stuff"
|
||||
sessionID: "sessionIDHere"
|
||||
|
||||
@res =
|
||||
send:->
|
||||
@controller = SandboxedModule.require modulePath, requires:
|
||||
"./AnalyticsManager":@AnalyticsManager
|
||||
"../Authentication/AuthenticationController":@AuthenticationController
|
||||
"logger-sharelatex":
|
||||
log:->
|
||||
|
||||
describe "recordEvent", ->
|
||||
|
||||
it "should use the user_id", (done)->
|
||||
@AuthenticationController.getLoggedInUserId.returns("1234")
|
||||
@controller.recordEvent @req, @res
|
||||
@AnalyticsManager.recordEvent.calledWith("1234", @req.params["event"], @req.body).should.equal true
|
||||
done()
|
||||
|
||||
it "should use the session id", (done)->
|
||||
@controller.recordEvent @req, @res
|
||||
@AnalyticsManager.recordEvent.calledWith(@req.sessionID, @req.params["event"], @req.body).should.equal true
|
||||
done()
|
Loading…
Reference in a new issue