2014-02-12 05:23:40 -05:00
|
|
|
sinon = require('sinon')
|
|
|
|
chai = require('chai')
|
|
|
|
should = chai.should()
|
|
|
|
expect = chai.expect
|
|
|
|
modulePath = "../../../../app/js/Features/Project/ProjectGetter.js"
|
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
ObjectId = require("mongojs").ObjectId
|
2014-03-31 13:05:33 -04:00
|
|
|
assert = require("chai").assert
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
describe "ProjectGetter", ->
|
|
|
|
beforeEach ->
|
|
|
|
@callback = sinon.stub()
|
|
|
|
@ProjectGetter = SandboxedModule.require modulePath, requires:
|
|
|
|
"../../infrastructure/mongojs":
|
|
|
|
db: @db =
|
|
|
|
projects: {}
|
|
|
|
users: {}
|
|
|
|
ObjectId: ObjectId
|
2017-04-03 11:18:30 -04:00
|
|
|
"metrics-sharelatex": timeAsyncMethod: sinon.stub()
|
2016-03-03 12:19:03 -05:00
|
|
|
"../../models/Project": Project: @Project = {}
|
|
|
|
"../Collaborators/CollaboratorsHandler": @CollaboratorsHandler = {}
|
2016-02-29 14:01:46 -05:00
|
|
|
"logger-sharelatex":
|
|
|
|
err:->
|
|
|
|
log:->
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
describe "getProjectWithoutDocLines", ->
|
|
|
|
beforeEach ->
|
|
|
|
@project =
|
2016-02-29 12:34:38 -05:00
|
|
|
_id: @project_id = "56d46b0a1d3422b87c5ebcb1"
|
2014-02-12 05:23:40 -05:00
|
|
|
@db.projects.find = sinon.stub().callsArgWith(2, null, [@project])
|
|
|
|
|
2016-02-29 12:34:38 -05:00
|
|
|
describe "passing an id", ->
|
|
|
|
beforeEach ->
|
|
|
|
@ProjectGetter.getProjectWithoutDocLines @project_id, @callback
|
|
|
|
|
|
|
|
it "should call find with the project id", ->
|
2017-02-27 08:54:57 -05:00
|
|
|
expect(@db.projects.find.lastCall.args[0]).to.deep.equal {
|
|
|
|
_id: ObjectId(@project_id)
|
|
|
|
}
|
2016-02-29 12:34:38 -05:00
|
|
|
|
|
|
|
it "should exclude the doc lines", ->
|
|
|
|
excludes =
|
|
|
|
"rootFolder.docs.lines": 0
|
|
|
|
"rootFolder.folder.docs.lines": 0
|
|
|
|
"rootFolder.folder.folder.docs.lines": 0
|
|
|
|
"rootFolder.folder.folder.folder.docs.lines": 0
|
|
|
|
"rootFolder.folder.folder.folder.folder.docs.lines": 0
|
|
|
|
"rootFolder.folder.folder.folder.folder.folder.docs.lines": 0
|
|
|
|
"rootFolder.folder.folder.folder.folder.folder.folder.docs.lines": 0
|
|
|
|
"rootFolder.folder.folder.folder.folder.folder.folder.folder.docs.lines": 0
|
|
|
|
@db.projects.find.calledWith(sinon.match.any, excludes)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should call the callback with the project", ->
|
|
|
|
@callback.calledWith(null, @project).should.equal true
|
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2015-10-21 11:56:06 -04:00
|
|
|
describe "getProjectWithOnlyFolders", ->
|
2016-03-09 06:16:27 -05:00
|
|
|
|
|
|
|
beforeEach ()->
|
2015-10-21 11:56:06 -04:00
|
|
|
@project =
|
2016-03-09 06:16:27 -05:00
|
|
|
_id: @project_id = "56d46b0a1d3422b87c5ebcb1"
|
|
|
|
@db.projects.find = sinon.stub().callsArgWith(2, null, [@project])
|
|
|
|
|
|
|
|
describe "passing an id", ->
|
2016-02-29 12:34:38 -05:00
|
|
|
beforeEach ->
|
2016-03-09 06:16:27 -05:00
|
|
|
@ProjectGetter.getProjectWithOnlyFolders @project_id, @callback
|
2016-02-29 12:34:38 -05:00
|
|
|
|
2016-03-09 06:16:27 -05:00
|
|
|
it "should call find with the project id", ->
|
2017-02-27 08:54:57 -05:00
|
|
|
expect(@db.projects.find.lastCall.args[0]).to.deep.equal {
|
|
|
|
_id: ObjectId(@project_id)
|
|
|
|
}
|
2016-03-09 06:16:27 -05:00
|
|
|
|
|
|
|
it "should exclude the docs and files linesaaaa", ->
|
|
|
|
excludes =
|
|
|
|
"rootFolder.docs": 0
|
|
|
|
"rootFolder.fileRefs": 0
|
|
|
|
"rootFolder.folder.docs": 0
|
|
|
|
"rootFolder.folder.fileRefs": 0
|
|
|
|
"rootFolder.folder.folder.docs": 0
|
|
|
|
"rootFolder.folder.folder.fileRefs": 0
|
|
|
|
"rootFolder.folder.folder.folder.docs": 0
|
|
|
|
"rootFolder.folder.folder.folder.fileRefs": 0
|
|
|
|
"rootFolder.folder.folder.folder.folder.docs": 0
|
|
|
|
"rootFolder.folder.folder.folder.folder.fileRefs": 0
|
|
|
|
"rootFolder.folder.folder.folder.folder.folder.docs": 0
|
|
|
|
"rootFolder.folder.folder.folder.folder.folder.fileRefs": 0
|
|
|
|
"rootFolder.folder.folder.folder.folder.folder.folder.docs": 0
|
|
|
|
"rootFolder.folder.folder.folder.folder.folder.folder.fileRefs": 0
|
|
|
|
"rootFolder.folder.folder.folder.folder.folder.folder.folder.docs": 0
|
|
|
|
"rootFolder.folder.folder.folder.folder.folder.folder.folder.fileRefs": 0
|
|
|
|
@db.projects.find.calledWith(sinon.match.any, excludes).should.equal true
|
2016-02-29 12:34:38 -05:00
|
|
|
|
|
|
|
it "should call the callback with the project", ->
|
|
|
|
@callback.calledWith(null, @project).should.equal true
|
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2016-03-09 06:16:27 -05:00
|
|
|
|
|
|
|
describe "getProject", ->
|
2016-02-29 12:34:38 -05:00
|
|
|
beforeEach ()->
|
2015-10-21 11:56:06 -04:00
|
|
|
@project =
|
2016-02-29 12:34:38 -05:00
|
|
|
_id: @project_id = "56d46b0a1d3422b87c5ebcb1"
|
2015-10-21 11:56:06 -04:00
|
|
|
@db.projects.find = sinon.stub().callsArgWith(2, null, [@project])
|
2016-02-29 12:34:38 -05:00
|
|
|
|
|
|
|
describe "passing an id", ->
|
|
|
|
beforeEach ->
|
|
|
|
@ProjectGetter.getProjectWithOnlyFolders @project_id, @callback
|
|
|
|
|
|
|
|
it "should call find with the project id", ->
|
2017-02-27 08:54:57 -05:00
|
|
|
expect(@db.projects.find.lastCall.args[0]).to.deep.equal {
|
|
|
|
_id: ObjectId(@project_id)
|
|
|
|
}
|
2016-02-29 12:34:38 -05:00
|
|
|
|
|
|
|
it "should exclude the docs and files linesaaaa", ->
|
|
|
|
excludes =
|
|
|
|
"rootFolder.docs": 0
|
|
|
|
"rootFolder.fileRefs": 0
|
|
|
|
"rootFolder.folder.docs": 0
|
|
|
|
"rootFolder.folder.fileRefs": 0
|
|
|
|
"rootFolder.folder.folder.docs": 0
|
|
|
|
"rootFolder.folder.folder.fileRefs": 0
|
|
|
|
"rootFolder.folder.folder.folder.docs": 0
|
|
|
|
"rootFolder.folder.folder.folder.fileRefs": 0
|
|
|
|
"rootFolder.folder.folder.folder.folder.docs": 0
|
|
|
|
"rootFolder.folder.folder.folder.folder.fileRefs": 0
|
|
|
|
"rootFolder.folder.folder.folder.folder.folder.docs": 0
|
|
|
|
"rootFolder.folder.folder.folder.folder.folder.fileRefs": 0
|
|
|
|
"rootFolder.folder.folder.folder.folder.folder.folder.docs": 0
|
|
|
|
"rootFolder.folder.folder.folder.folder.folder.folder.fileRefs": 0
|
|
|
|
"rootFolder.folder.folder.folder.folder.folder.folder.folder.docs": 0
|
|
|
|
"rootFolder.folder.folder.folder.folder.folder.folder.folder.fileRefs": 0
|
|
|
|
@db.projects.find.calledWith(sinon.match.any, excludes).should.equal true
|
|
|
|
|
|
|
|
it "should call the callback with the project", ->
|
|
|
|
@callback.calledWith(null, @project).should.equal true
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-03-09 06:16:27 -05:00
|
|
|
describe "getProject", ->
|
2016-02-29 12:34:38 -05:00
|
|
|
beforeEach ()->
|
|
|
|
@project =
|
|
|
|
_id: @project_id = "56d46b0a1d3422b87c5ebcb1"
|
2015-10-21 11:56:06 -04:00
|
|
|
@db.projects.find = sinon.stub().callsArgWith(2, null, [@project])
|
|
|
|
|
|
|
|
|
2016-03-03 12:19:03 -05:00
|
|
|
describe "findAllUsersProjects", ->
|
|
|
|
beforeEach ->
|
|
|
|
@fields = {"mock": "fields"}
|
|
|
|
@Project.find = sinon.stub()
|
|
|
|
@Project.find.withArgs({owner_ref: @user_id}, @fields).yields(null, ["mock-owned-projects"])
|
2016-03-08 07:07:42 -05:00
|
|
|
@CollaboratorsHandler.getProjectsUserIsCollaboratorOf = sinon.stub()
|
|
|
|
@CollaboratorsHandler.getProjectsUserIsCollaboratorOf.withArgs(@user_id, @fields).yields(null, ["mock-rw-projects"], ["mock-ro-projects"])
|
2016-03-03 12:19:03 -05:00
|
|
|
@ProjectGetter.findAllUsersProjects @user_id, @fields, @callback
|
|
|
|
|
|
|
|
it "should call the callback with all the projects", ->
|
|
|
|
@callback
|
|
|
|
.calledWith(null, ["mock-owned-projects"], ["mock-rw-projects"], ["mock-ro-projects"])
|
|
|
|
.should.equal true
|