overleaf/services/web/test/UnitTests/coffee/Project/ProjectDeleterTests.coffee

42 lines
1.4 KiB
CoffeeScript
Raw Normal View History

2014-02-12 10:23:40 +00:00
should = require('chai').should()
modulePath = "../../../../app/js/Features/Project/ProjectDeleter"
SandboxedModule = require('sandboxed-module')
sinon = require('sinon')
describe 'Project deleter', ->
beforeEach ->
@Project =
update: sinon.stub().callsArgWith(3)
remove: sinon.stub().callsArgWith(1)
@editorController = notifyUsersProjectHasBeenDeletedOrRenamed : sinon.stub().callsArgWith(1)
@deleter = SandboxedModule.require modulePath, requires:
"../Editor/EditorController": @editorController
'../../models/Project':{Project:@Project}
'logger-sharelatex':
log:->
describe "mark as deleted by external source", ->
project_id = 1234
it 'should update the project with the flag set to true', (done)->
@deleter.markAsDeletedByExternalSource project_id, =>
conditions = {_id:project_id}
update = {deletedByExternalDataSource:true}
@Project.update.calledWith(conditions, update).should.equal true
done()
it 'should tell the editor controler so users are notified', (done)->
@deleter.markAsDeletedByExternalSource project_id, =>
@editorController.notifyUsersProjectHasBeenDeletedOrRenamed.calledWith(project_id).should.equal true
done()
describe "deleteUsersProjects", ->
it "should remove all the projects owned by the user_id", (done)->
user_id = 1234
@deleter.deleteUsersProjects user_id, =>
@Project.remove.calledWith(owner_ref:user_id).should.equal true
done()