From 9dc86005889b514a418872c09f15e3e5c8e91b7b Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Mon, 12 Mar 2018 10:50:15 +0000 Subject: [PATCH] Add a unit test for the analytics events sent from project-creation --- .../ProjectCreationHandlerTests.coffee | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/services/web/test/unit/coffee/Project/ProjectCreationHandlerTests.coffee b/services/web/test/unit/coffee/Project/ProjectCreationHandlerTests.coffee index dd9308fb56..042dc34d09 100644 --- a/services/web/test/unit/coffee/Project/ProjectCreationHandlerTests.coffee +++ b/services/web/test/unit/coffee/Project/ProjectCreationHandlerTests.coffee @@ -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"))