mirror of
https://github.com/overleaf/overleaf.git
synced 2025-03-14 03:54:48 +00:00
use ProjectGetter.getProject in other ProjectGetter methods
This commit is contained in:
parent
95b82a3c9d
commit
66cd5cd24b
2 changed files with 19 additions and 20 deletions
|
@ -10,22 +10,18 @@ LockManager = require("../../infrastructure/LockManager")
|
|||
module.exports = ProjectGetter =
|
||||
EXCLUDE_DEPTH: 8
|
||||
|
||||
|
||||
getProjectWithoutDocLines: (project_id, callback=(error, project) ->) ->
|
||||
excludes = {}
|
||||
for i in [1..ProjectGetter.EXCLUDE_DEPTH]
|
||||
excludes["rootFolder#{Array(i).join(".folders")}.docs.lines"] = 0
|
||||
db.projects.find _id: ObjectId(project_id.toString()), excludes, (error, projects = []) ->
|
||||
callback error, projects[0]
|
||||
ProjectGetter.getProject project_id, excludes, callback
|
||||
|
||||
getProjectWithOnlyFolders: (project_id, callback=(error, project) ->) ->
|
||||
excludes = {}
|
||||
for i in [1..ProjectGetter.EXCLUDE_DEPTH]
|
||||
excludes["rootFolder#{Array(i).join(".folders")}.docs"] = 0
|
||||
excludes["rootFolder#{Array(i).join(".folders")}.fileRefs"] = 0
|
||||
db.projects.find _id: ObjectId(project_id.toString()), excludes, (error, projects = []) ->
|
||||
callback error, projects[0]
|
||||
|
||||
ProjectGetter.getProject project_id, excludes, callback
|
||||
|
||||
getProject: (project_id, projection, callback = (error, project) ->) ->
|
||||
if projection?.rootFolder
|
||||
|
|
|
@ -30,16 +30,16 @@ describe "ProjectGetter", ->
|
|||
beforeEach ->
|
||||
@project =
|
||||
_id: @project_id = "56d46b0a1d3422b87c5ebcb1"
|
||||
@db.projects.find = sinon.stub().callsArgWith(2, null, [@project])
|
||||
@ProjectGetter.getProject = sinon.stub().yields()
|
||||
|
||||
describe "passing an id", ->
|
||||
beforeEach ->
|
||||
@ProjectGetter.getProjectWithoutDocLines @project_id, @callback
|
||||
|
||||
it "should call find with the project id", ->
|
||||
expect(@db.projects.find.lastCall.args[0]).to.deep.equal {
|
||||
_id: ObjectId(@project_id)
|
||||
}
|
||||
@ProjectGetter.getProject
|
||||
.calledWith(@project_id)
|
||||
.should.equal true
|
||||
|
||||
it "should exclude the doc lines", ->
|
||||
excludes =
|
||||
|
@ -51,11 +51,13 @@ describe "ProjectGetter", ->
|
|||
"rootFolder.folders.folders.folders.folders.folders.docs.lines": 0
|
||||
"rootFolder.folders.folders.folders.folders.folders.folders.docs.lines": 0
|
||||
"rootFolder.folders.folders.folders.folders.folders.folders.folders.docs.lines": 0
|
||||
@db.projects.find.calledWith(sinon.match.any, excludes)
|
||||
|
||||
@ProjectGetter.getProject
|
||||
.calledWith(@project_id, excludes)
|
||||
.should.equal true
|
||||
|
||||
it "should call the callback with the project", ->
|
||||
@callback.calledWith(null, @project).should.equal true
|
||||
it "should call the callback", ->
|
||||
@callback.called.should.equal true
|
||||
|
||||
|
||||
describe "getProjectWithOnlyFolders", ->
|
||||
|
@ -63,16 +65,16 @@ describe "ProjectGetter", ->
|
|||
beforeEach ()->
|
||||
@project =
|
||||
_id: @project_id = "56d46b0a1d3422b87c5ebcb1"
|
||||
@db.projects.find = sinon.stub().callsArgWith(2, null, [@project])
|
||||
@ProjectGetter.getProject = sinon.stub().yields()
|
||||
|
||||
describe "passing an id", ->
|
||||
beforeEach ->
|
||||
@ProjectGetter.getProjectWithOnlyFolders @project_id, @callback
|
||||
|
||||
it "should call find with the project id", ->
|
||||
expect(@db.projects.find.lastCall.args[0]).to.deep.equal {
|
||||
_id: ObjectId(@project_id)
|
||||
}
|
||||
@ProjectGetter.getProject
|
||||
.calledWith(@project_id)
|
||||
.should.equal true
|
||||
|
||||
it "should exclude the docs and files linesaaaa", ->
|
||||
excludes =
|
||||
|
@ -92,11 +94,12 @@ describe "ProjectGetter", ->
|
|||
"rootFolder.folders.folders.folders.folders.folders.folders.fileRefs": 0
|
||||
"rootFolder.folders.folders.folders.folders.folders.folders.folders.docs": 0
|
||||
"rootFolder.folders.folders.folders.folders.folders.folders.folders.fileRefs": 0
|
||||
@db.projects.find.calledWith(sinon.match.any, excludes).should.equal true
|
||||
@ProjectGetter.getProject
|
||||
.calledWith(@project_id, excludes)
|
||||
.should.equal true
|
||||
|
||||
it "should call the callback with the project", ->
|
||||
@callback.calledWith(null, @project).should.equal true
|
||||
|
||||
@callback.called.should.equal true
|
||||
|
||||
|
||||
describe "getProject", ->
|
||||
|
|
Loading…
Reference in a new issue