|
|
@@ -3,7 +3,6 @@ modulePath = "../../../../app/js/Features/Project/ProjectDeleter"
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
sinon = require('sinon')
|
|
|
|
|
|
-
|
|
|
describe 'ProjectDeleter', ->
|
|
|
|
|
|
beforeEach ->
|
|
|
@@ -16,14 +15,10 @@ describe 'ProjectDeleter', ->
|
|
|
owner_ref:"owner ref here"
|
|
|
remove: sinon.stub().callsArg(0)
|
|
|
|
|
|
- @user_id = 1234
|
|
|
-
|
|
|
- @mongojs =
|
|
|
- db:
|
|
|
- deletedProjects:
|
|
|
- insert: sinon.stub().callsArg(1)
|
|
|
- projectsDeletedByMigration:
|
|
|
- insert: sinon.stub().callsArg(1)
|
|
|
+ @user =
|
|
|
+ _id:"588f3ddae8ebc1bac07c9fa4"
|
|
|
+ first_name: "bjkdsjfk"
|
|
|
+ features: {}
|
|
|
|
|
|
@Project =
|
|
|
update: sinon.stub().callsArgWith(3)
|
|
|
@@ -31,6 +26,9 @@ describe 'ProjectDeleter', ->
|
|
|
findOne: sinon.stub().callsArgWith(1, null, @project)
|
|
|
find: sinon.stub().callsArgWith(1, null, [@project])
|
|
|
applyToAllFilesRecursivly: sinon.stub()
|
|
|
+ @DeletedProject = class DeletedProject
|
|
|
+ constructor: ->
|
|
|
+ save: sinon.stub().callsArgWith(0)
|
|
|
@documentUpdaterHandler =
|
|
|
flushProjectToMongoAndDelete:sinon.stub().callsArgWith(1)
|
|
|
@editorController = notifyUsersProjectHasBeenDeletedOrRenamed : sinon.stub().callsArgWith(1)
|
|
|
@@ -42,11 +40,11 @@ describe 'ProjectDeleter', ->
|
|
|
@deleter = SandboxedModule.require modulePath, requires:
|
|
|
"../Editor/EditorController": @editorController
|
|
|
'../../models/Project':{Project:@Project}
|
|
|
+ '../../models/DeletedProject':{DeletedProject:@DeletedProject}
|
|
|
'../DocumentUpdater/DocumentUpdaterHandler': @documentUpdaterHandler
|
|
|
"../Tags/TagsHandler":@TagsHandler
|
|
|
"../FileStore/FileStoreHandler": @FileStoreHandler = {}
|
|
|
"../Collaborators/CollaboratorsHandler": @CollaboratorsHandler
|
|
|
- "../../infrastructure/mongojs": @mongojs
|
|
|
'logger-sharelatex':
|
|
|
log:->
|
|
|
|
|
|
@@ -83,12 +81,12 @@ describe 'ProjectDeleter', ->
|
|
|
@deleter.deleteProject = sinon.stub().callsArg(1)
|
|
|
|
|
|
it "should find all the projects owned by the user_id", (done)->
|
|
|
- @deleter.deleteUsersProjects @user_id, =>
|
|
|
- sinon.assert.calledWith(@Project.find, owner_ref: @user_id)
|
|
|
+ @deleter.deleteUsersProjects @user._id, =>
|
|
|
+ sinon.assert.calledWith(@Project.find, owner_ref: @user._id)
|
|
|
done()
|
|
|
|
|
|
it "should call deleteProject on the found projects", (done)->
|
|
|
- @deleter.deleteUsersProjects @user_id, =>
|
|
|
+ @deleter.deleteUsersProjects @user._id, =>
|
|
|
sinon.assert.calledWith(@deleter.deleteProject, @project._id)
|
|
|
done()
|
|
|
|
|
|
@@ -96,54 +94,31 @@ describe 'ProjectDeleter', ->
|
|
|
@Project.find.callsArgWith(1, null, [
|
|
|
{_id: 'potato'}, {_id: 'wombat'}
|
|
|
])
|
|
|
- @deleter.deleteUsersProjects @user_id, =>
|
|
|
+ @deleter.deleteUsersProjects @user._id, =>
|
|
|
sinon.assert.calledTwice(@deleter.deleteProject)
|
|
|
sinon.assert.calledWith(@deleter.deleteProject, 'wombat')
|
|
|
sinon.assert.calledWith(@deleter.deleteProject, 'potato')
|
|
|
done()
|
|
|
|
|
|
it "should remove all the projects the user is a collaborator of", (done)->
|
|
|
- @deleter.deleteUsersProjects @user_id, =>
|
|
|
- @CollaboratorsHandler.removeUserFromAllProjets.calledWith(@user_id).should.equal true
|
|
|
- done()
|
|
|
-
|
|
|
- describe "softDeleteUsersProjectsForMigrationForMigration", ->
|
|
|
- beforeEach ->
|
|
|
- @deleter.softDeleteProjectForMigration = sinon.stub().callsArg(1)
|
|
|
-
|
|
|
- it "should find all the projects owned by the user_id", (done)->
|
|
|
- @deleter.softDeleteUsersProjectsForMigration @user_id, =>
|
|
|
- @Project.find.calledWith(owner_ref: @user_id).should.equal true
|
|
|
- done()
|
|
|
-
|
|
|
- it "should call deleteProject on the found projects", (done)->
|
|
|
- @deleter.softDeleteUsersProjectsForMigration @user_id, =>
|
|
|
- sinon.assert.calledWith(@deleter.softDeleteProjectForMigration, @project._id)
|
|
|
- done()
|
|
|
-
|
|
|
- it "should call deleteProject once for each project", (done)->
|
|
|
- @Project.find.callsArgWith(1, null, [
|
|
|
- {_id: 'potato'}, {_id: 'wombat'}
|
|
|
- ])
|
|
|
- @deleter.softDeleteUsersProjectsForMigration @user_id, =>
|
|
|
- sinon.assert.calledTwice(@deleter.softDeleteProjectForMigration)
|
|
|
- sinon.assert.calledWith(@deleter.softDeleteProjectForMigration, 'wombat')
|
|
|
- sinon.assert.calledWith(@deleter.softDeleteProjectForMigration, 'potato')
|
|
|
- done()
|
|
|
-
|
|
|
- it "should remove all the projects the user is a collaborator of", (done)->
|
|
|
- @deleter.softDeleteUsersProjectsForMigration @user_id, =>
|
|
|
- @CollaboratorsHandler.removeUserFromAllProjets.calledWith(@user_id).should.equal true
|
|
|
+ @deleter.deleteUsersProjects @user._id, =>
|
|
|
+ @CollaboratorsHandler.removeUserFromAllProjets.calledWith(@user._id).should.equal true
|
|
|
done()
|
|
|
|
|
|
describe "deleteProject", ->
|
|
|
- beforeEach (done) ->
|
|
|
+ beforeEach () ->
|
|
|
@project_id = "mock-project-id-123"
|
|
|
- @Project.remove.callsArgWith(1)
|
|
|
- done()
|
|
|
+ @ip = "192.170.18.1"
|
|
|
+
|
|
|
+ it "should save a DeletedProject with additional deleterData", (done) ->
|
|
|
+ @deleter.deleteProject @project_id, {deleterUser: @user, ipAddress: @ip}, (err, deletedProject) =>
|
|
|
+ @DeletedProject::save.called.should.equal true
|
|
|
+ deletedProject.deleterData.deleterIpAddress.should.equal(@ip)
|
|
|
+ deletedProject.deleterData.deleterId.should.equal(@user._id)
|
|
|
+ done()
|
|
|
|
|
|
it "should flushProjectToMongoAndDelete in doc updater", (done)->
|
|
|
- @deleter.deleteProject @project_id, =>
|
|
|
+ @deleter.deleteProject @project_id, {deleterUser: @user, ipAddress: @ip}, =>
|
|
|
@documentUpdaterHandler.flushProjectToMongoAndDelete.calledWith(@project_id).should.equal true
|
|
|
done()
|
|
|
|
|
|
@@ -160,25 +135,6 @@ describe 'ProjectDeleter', ->
|
|
|
}).should.equal true
|
|
|
done()
|
|
|
|
|
|
- describe "softDeleteProjectForMigration", ->
|
|
|
- beforeEach ->
|
|
|
- @deleter.deleteProject = sinon.stub().callsArg(1)
|
|
|
-
|
|
|
- it "should set the deletedAt time", (done)->
|
|
|
- @deleter.softDeleteProjectForMigration @project_id, =>
|
|
|
- @project.deletedAt.should.exist
|
|
|
- done()
|
|
|
-
|
|
|
- it "should insert the project into the deleted projects collection", (done)->
|
|
|
- @deleter.softDeleteProjectForMigration @project_id, =>
|
|
|
- sinon.assert.calledWith(@mongojs.db.projectsDeletedByMigration.insert, @project)
|
|
|
- done()
|
|
|
-
|
|
|
- it "should delete the project", (done)->
|
|
|
- @deleter.softDeleteProjectForMigration @project_id, =>
|
|
|
- sinon.assert.calledWith(@deleter.deleteProject, @project_id)
|
|
|
- done()
|
|
|
-
|
|
|
describe "archiveProject", ->
|
|
|
beforeEach ->
|
|
|
@Project.update.callsArgWith(2)
|