From 586d4cbae12099f713689acdd3e24ecb1fbdaa99 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Fri, 26 Feb 2016 08:23:43 +0000 Subject: [PATCH] replaced all mongoose Project.find with mongojs calls --- .../Project/ProjectEntityHandler.coffee | 8 +++---- .../Project/ProjectEntityHandlerTests.coffee | 23 ++++++++----------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/services/web/app/coffee/Features/Project/ProjectEntityHandler.coffee b/services/web/app/coffee/Features/Project/ProjectEntityHandler.coffee index d8bf4713a2..2fcb45acc5 100644 --- a/services/web/app/coffee/Features/Project/ProjectEntityHandler.coffee +++ b/services/web/app/coffee/Features/Project/ProjectEntityHandler.coffee @@ -75,7 +75,7 @@ module.exports = ProjectEntityHandler = documentUpdaterHandler = require('../../Features/DocumentUpdater/DocumentUpdaterHandler') documentUpdaterHandler.flushProjectToMongo project_id, (error) -> return callback(error) if error? - Project.findById project_id, (error, project) -> + ProjectGetter.getProject project_id, (error, project) -> return callback(error) if error? requests = [] self.getAllDocs project_id, (error, docs) -> @@ -279,7 +279,7 @@ module.exports = ProjectEntityHandler = logger.err err: "No entityType set", project_id: project_id, entity_id: entity_id return callback("No entityType set") entityType = entityType.toLowerCase() - Project.findById project_id, (err, project)=> + ProjectGetter.getProject project_id, (err, project)=> return callback(err) if err? projectLocator.findElement {project:project, element_id:entity_id, type:entityType}, (err, entity, path)-> return callback(err) if err? @@ -317,7 +317,7 @@ module.exports = ProjectEntityHandler = logger.err err: "No entityType set", project_id: project_id, entity_id: entity_id return callback("No entityType set") entityType = entityType.toLowerCase() - Project.findById project_id, (err, project)=> + ProjectGetter.getProject project_id, (err, project)=> return callback(error) if error? projectLocator.findElement {project: project, element_id: entity_id, type: entityType}, (error, entity, path)=> return callback(error) if error? @@ -336,7 +336,7 @@ module.exports = ProjectEntityHandler = logger.err err: "No entityType set", project_id: project_id, entity_id: entity_id return callback("No entityType set") entityType = entityType.toLowerCase() - Project.findById project_id, (err, project)=> + ProjectGetter.getProject project_id, (err, project)=> projectLocator.findElement {project:project, element_id:entity_id, type:entityType}, (err, entity, path, folder)=> if err? return callback err diff --git a/services/web/test/UnitTests/coffee/Project/ProjectEntityHandlerTests.coffee b/services/web/test/UnitTests/coffee/Project/ProjectEntityHandlerTests.coffee index d63a6e9c59..3e0807c57a 100644 --- a/services/web/test/UnitTests/coffee/Project/ProjectEntityHandlerTests.coffee +++ b/services/web/test/UnitTests/coffee/Project/ProjectEntityHandlerTests.coffee @@ -144,6 +144,7 @@ describe 'ProjectEntityHandler', -> describe 'deleteEntity', -> entity_id = "4eecaffcbffa66588e000009" beforeEach -> + @ProjectGetter.getProject.callsArgWith(1, null, @project) @tpdsUpdateSender.deleteEntity = sinon.stub().callsArg(1) @ProjectEntityHandler._removeElementFromMongoArray = sinon.stub().callsArg(3) @ProjectEntityHandler._cleanUpEntity = sinon.stub().callsArg(3) @@ -231,6 +232,7 @@ describe 'ProjectEntityHandler', -> } @ProjectEntityHandler._removeElementFromMongoArray = sinon.stub().callsArg(3) @ProjectEntityHandler._putElement = sinon.stub().callsArgWith(4, null, path: @pathAfterMove) + @ProjectGetter.getProject.callsArgWith(1, null, @project) @tpdsUpdateSender.moveEntity = sinon.stub().callsArg(1) describe "moving a doc", -> @@ -567,7 +569,7 @@ describe 'ProjectEntityHandler', -> @ProjectModel.update = (conditions, update, options, callback)=> conditions._id.should.equal project_id differenceInMs = update.$set["#{@filePaths.mongo}.created"].getTime() - d.getTime() - differenceInMs.should.be.below(10) + differenceInMs.should.be.below(20) done() @ProjectEntityHandler.replaceFile project_id, @file_id, @fsPath, => @@ -808,27 +810,21 @@ describe 'ProjectEntityHandler', -> @ProjectEntityHandler.getAllDocs = sinon.stub().callsArgWith(1, null, @docs) @ProjectEntityHandler.getAllFiles = sinon.stub().callsArgWith(1, null, @files) + @ProjectGetter.getProject.callsArgWith(1, null, @project) + @ProjectEntityHandler.flushProjectToThirdPartyDataStore project_id, () -> done() it "should flush the project from the doc updater", -> - @documentUpdaterHandler.flushProjectToMongo - .calledWith(project_id) - .should.equal true + @documentUpdaterHandler.flushProjectToMongo.calledWith(project_id).should.equal true it "should look up the project in mongo", -> - @ProjectModel.findById - .calledWith(project_id) - .should.equal true + @ProjectGetter.getProject.calledWith(project_id).should.equal true it "should get all the docs in the project", -> - @ProjectEntityHandler.getAllDocs - .calledWith(project_id) - .should.equal true + @ProjectEntityHandler.getAllDocs.calledWith(project_id).should.equal true it "should get all the files in the project", -> - @ProjectEntityHandler.getAllFiles - .calledWith(project_id) - .should.equal true + @ProjectEntityHandler.getAllFiles.calledWith(project_id).should.equal true it "should flush each doc to the TPDS", -> for path, doc of @docs @@ -931,6 +927,7 @@ describe 'ProjectEntityHandler', -> @projectLocator.findElement = sinon.stub().callsArgWith(1, null, @entity = { _id: @entity_id, name:"old.tex", rev:4 }, @path) @ProjectModel.update = sinon.stub().callsArgWith(3) @tpdsUpdateSender.moveEntity = sinon.stub() + @ProjectGetter.getProject.callsArgWith(1, null, @project) it "should update the name in mongo", (done)->