mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #361 from sharelatex/ta-record-new-project-event
Record New Project Event
This commit is contained in:
commit
2ceb7daa97
2 changed files with 33 additions and 2 deletions
|
@ -12,6 +12,7 @@ User = require('../../models/User').User
|
|||
fs = require('fs')
|
||||
Path = require "path"
|
||||
_ = require "underscore"
|
||||
AnalyticsManger = require("../Analytics/AnalyticsManager")
|
||||
|
||||
module.exports = ProjectCreationHandler =
|
||||
|
||||
|
@ -25,11 +26,21 @@ module.exports = ProjectCreationHandler =
|
|||
return callback(error) if error?
|
||||
logger.log owner_id:owner_id, projectName:projectName, "creating blank project"
|
||||
if projectHistoryId?
|
||||
ProjectCreationHandler._createBlankProject owner_id, projectName, projectHistoryId, callback
|
||||
ProjectCreationHandler._createBlankProject owner_id, projectName, projectHistoryId, (error, project) ->
|
||||
return callback(error) if error?
|
||||
AnalyticsManger.recordEvent(
|
||||
owner_id, 'project-imported', { projectId: project._id, projectHistoryId: projectHistoryId }
|
||||
)
|
||||
callback(error, project)
|
||||
else
|
||||
HistoryManager.initializeProject (error, history) ->
|
||||
return callback(error) if error?
|
||||
ProjectCreationHandler._createBlankProject owner_id, projectName, history?.overleaf_id, callback
|
||||
ProjectCreationHandler._createBlankProject owner_id, projectName, history?.overleaf_id, (error, project) ->
|
||||
return callback(error) if error?
|
||||
AnalyticsManger.recordEvent(
|
||||
owner_id, 'project-created', { projectId: project._id }
|
||||
)
|
||||
callback(error, project)
|
||||
|
||||
_createBlankProject : (owner_id, projectName, projectHistoryId, callback = (error, project) ->)->
|
||||
rootFolder = new Folder {'name':'rootFolder'}
|
||||
|
|
|
@ -52,6 +52,8 @@ describe 'ProjectCreationHandler', ->
|
|||
|
||||
@Settings = apis: { project_history: {} }
|
||||
|
||||
@AnalyticsManager = recordEvent: sinon.stub()
|
||||
|
||||
@handler = SandboxedModule.require modulePath, requires:
|
||||
'../../models/User': User:@User
|
||||
'../../models/Project':{Project:@ProjectModel}
|
||||
|
@ -60,6 +62,7 @@ describe 'ProjectCreationHandler', ->
|
|||
'./ProjectEntityUpdateHandler':@ProjectEntityUpdateHandler
|
||||
"./ProjectDetailsHandler":@ProjectDetailsHandler
|
||||
"settings-sharelatex": @Settings
|
||||
"../Analytics/AnalyticsManager": @AnalyticsManager
|
||||
'logger-sharelatex': {log:->}
|
||||
"metrics-sharelatex": {
|
||||
inc: ()->,
|
||||
|
@ -128,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"))
|
||||
|
|
Loading…
Reference in a new issue