mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-02 13:10:20 -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')
|
fs = require('fs')
|
||||||
Path = require "path"
|
Path = require "path"
|
||||||
_ = require "underscore"
|
_ = require "underscore"
|
||||||
|
AnalyticsManger = require("../Analytics/AnalyticsManager")
|
||||||
|
|
||||||
module.exports = ProjectCreationHandler =
|
module.exports = ProjectCreationHandler =
|
||||||
|
|
||||||
|
@ -25,11 +26,21 @@ module.exports = ProjectCreationHandler =
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
logger.log owner_id:owner_id, projectName:projectName, "creating blank project"
|
logger.log owner_id:owner_id, projectName:projectName, "creating blank project"
|
||||||
if projectHistoryId?
|
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
|
else
|
||||||
HistoryManager.initializeProject (error, history) ->
|
HistoryManager.initializeProject (error, history) ->
|
||||||
return callback(error) if error?
|
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) ->)->
|
_createBlankProject : (owner_id, projectName, projectHistoryId, callback = (error, project) ->)->
|
||||||
rootFolder = new Folder {'name':'rootFolder'}
|
rootFolder = new Folder {'name':'rootFolder'}
|
||||||
|
|
|
@ -52,6 +52,8 @@ describe 'ProjectCreationHandler', ->
|
||||||
|
|
||||||
@Settings = apis: { project_history: {} }
|
@Settings = apis: { project_history: {} }
|
||||||
|
|
||||||
|
@AnalyticsManager = recordEvent: sinon.stub()
|
||||||
|
|
||||||
@handler = SandboxedModule.require modulePath, requires:
|
@handler = SandboxedModule.require modulePath, requires:
|
||||||
'../../models/User': User:@User
|
'../../models/User': User:@User
|
||||||
'../../models/Project':{Project:@ProjectModel}
|
'../../models/Project':{Project:@ProjectModel}
|
||||||
|
@ -60,6 +62,7 @@ describe 'ProjectCreationHandler', ->
|
||||||
'./ProjectEntityUpdateHandler':@ProjectEntityUpdateHandler
|
'./ProjectEntityUpdateHandler':@ProjectEntityUpdateHandler
|
||||||
"./ProjectDetailsHandler":@ProjectDetailsHandler
|
"./ProjectDetailsHandler":@ProjectDetailsHandler
|
||||||
"settings-sharelatex": @Settings
|
"settings-sharelatex": @Settings
|
||||||
|
"../Analytics/AnalyticsManager": @AnalyticsManager
|
||||||
'logger-sharelatex': {log:->}
|
'logger-sharelatex': {log:->}
|
||||||
"metrics-sharelatex": {
|
"metrics-sharelatex": {
|
||||||
inc: ()->,
|
inc: ()->,
|
||||||
|
@ -128,6 +131,23 @@ describe 'ProjectCreationHandler', ->
|
||||||
expect(project.overleaf.history.display).to.equal true
|
expect(project.overleaf.history.display).to.equal true
|
||||||
done()
|
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", ->
|
describe "with an error", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@ProjectModel::save = sinon.stub().callsArgWith(0, new Error("something went wrong"))
|
@ProjectModel::save = sinon.stub().callsArgWith(0, new Error("something went wrong"))
|
||||||
|
|
Loading…
Reference in a new issue