Add a unit test for the analytics events sent from project-creation

This commit is contained in:
Shane Kilkelly 2018-03-12 10:50:15 +00:00
parent d5109d22d2
commit 9dc8600588

View file

@ -52,7 +52,7 @@ describe 'ProjectCreationHandler', ->
@Settings = apis: { project_history: {} }
@AnalyticsManger = recordEvent: sinon.stub()
@AnalyticsManager = recordEvent: sinon.stub()
@handler = SandboxedModule.require modulePath, requires:
'../../models/User': User:@User
@ -62,7 +62,7 @@ describe 'ProjectCreationHandler', ->
'./ProjectEntityUpdateHandler':@ProjectEntityUpdateHandler
"./ProjectDetailsHandler":@ProjectDetailsHandler
"settings-sharelatex": @Settings
"../Analytics/AnalyticsManager": @AnalyticsManger
"../Analytics/AnalyticsManager": @AnalyticsManager
'logger-sharelatex': {log:->}
"metrics-sharelatex": {
inc: ()->,
@ -131,6 +131,23 @@ describe 'ProjectCreationHandler', ->
expect(project.overleaf.history.display).to.equal true
done()
it "should send a project-created event to analytics", (done) ->
@handler.createBlankProject ownerId, projectName, (err, project) =>
expect(@AnalyticsManager.recordEvent.callCount).to.equal 1
expect(
@AnalyticsManager.recordEvent.calledWith(ownerId, 'project-created')
).to.equal true
done()
it "should send a project-imported event when importing a project", (done) ->
@handler.createBlankProject ownerId, projectName, 1234, (err, project) =>
expect(@AnalyticsManager.recordEvent.callCount).to.equal 1
expect(
@AnalyticsManager.recordEvent.calledWith(ownerId, 'project-imported')
).to.equal true
done()
describe "with an error", ->
beforeEach ->
@ProjectModel::save = sinon.stub().callsArgWith(0, new Error("something went wrong"))