2017-03-22 09:11:45 -04:00
|
|
|
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 =
|
2018-03-05 06:15:41 -05:00
|
|
|
updateEditingSession: sinon.stub().callsArgWith(3)
|
2017-03-22 09:11:45 -04:00
|
|
|
recordEvent: sinon.stub().callsArgWith(3)
|
|
|
|
|
|
|
|
@controller = SandboxedModule.require modulePath, requires:
|
|
|
|
"./AnalyticsManager":@AnalyticsManager
|
|
|
|
"../Authentication/AuthenticationController":@AuthenticationController
|
|
|
|
"logger-sharelatex":
|
|
|
|
log:->
|
2018-03-05 05:46:51 -05:00
|
|
|
'../../infrastructure/GeoIpLookup': @GeoIpLookup =
|
|
|
|
getDetails: sinon.stub()
|
2017-03-22 09:11:45 -04:00
|
|
|
|
2018-01-22 12:20:55 -05:00
|
|
|
@res =
|
|
|
|
send:->
|
|
|
|
|
|
|
|
describe "updateEditingSession", ->
|
|
|
|
beforeEach ->
|
|
|
|
@req =
|
|
|
|
params:
|
|
|
|
projectId: "a project id"
|
2018-03-05 05:46:51 -05:00
|
|
|
@GeoIpLookup.getDetails = sinon.stub()
|
|
|
|
.callsArgWith(1, null, {country_code: 'XY'})
|
2018-01-22 12:20:55 -05:00
|
|
|
|
|
|
|
it "delegates to the AnalyticsManager", (done) ->
|
|
|
|
@AuthenticationController.getLoggedInUserId.returns("1234")
|
|
|
|
@controller.updateEditingSession @req, @res
|
|
|
|
|
2018-03-02 07:02:45 -05:00
|
|
|
@AnalyticsManager.updateEditingSession.calledWith(
|
|
|
|
"1234",
|
|
|
|
"a project id",
|
2018-03-05 06:15:41 -05:00
|
|
|
'XY'
|
2018-03-02 07:02:45 -05:00
|
|
|
).should.equal true
|
2018-01-22 12:20:55 -05:00
|
|
|
done()
|
|
|
|
|
2017-03-22 09:11:45 -04:00
|
|
|
describe "recordEvent", ->
|
2018-01-22 12:20:55 -05:00
|
|
|
beforeEach ->
|
|
|
|
@req =
|
|
|
|
params:
|
|
|
|
event:"i_did_something"
|
|
|
|
body:"stuff"
|
|
|
|
sessionID: "sessionIDHere"
|
2018-03-02 07:02:45 -05:00
|
|
|
session: {}
|
2017-03-22 09:11:45 -04:00
|
|
|
|
|
|
|
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()
|