|
@@ -15,6 +15,7 @@ describe "DocumentController", ->
|
|
|
"logger-sharelatex":
|
|
"logger-sharelatex":
|
|
|
log:->
|
|
log:->
|
|
|
err:->
|
|
err:->
|
|
|
|
|
+ "../Project/ProjectGetter": @ProjectGetter = {}
|
|
|
"../Project/ProjectLocator": @ProjectLocator = {}
|
|
"../Project/ProjectLocator": @ProjectLocator = {}
|
|
|
"../Project/ProjectEntityHandler": @ProjectEntityHandler = {}
|
|
"../Project/ProjectEntityHandler": @ProjectEntityHandler = {}
|
|
|
"../Project/ProjectEntityUpdateHandler": @ProjectEntityUpdateHandler = {}
|
|
"../Project/ProjectEntityUpdateHandler": @ProjectEntityUpdateHandler = {}
|
|
@@ -35,39 +36,76 @@ describe "DocumentController", ->
|
|
|
Project_id: @project_id
|
|
Project_id: @project_id
|
|
|
doc_id: @doc_id
|
|
doc_id: @doc_id
|
|
|
|
|
|
|
|
- describe "when the document exists", ->
|
|
|
|
|
|
|
+ describe "when the project exists without project history enabled", ->
|
|
|
|
|
+ beforeEach ->
|
|
|
|
|
+ @project = _id: @project_id
|
|
|
|
|
+ @ProjectGetter.getProject = sinon.stub().callsArgWith(2, null, @project)
|
|
|
|
|
+
|
|
|
|
|
+ describe "when the document exists", ->
|
|
|
|
|
+ beforeEach ->
|
|
|
|
|
+ @doc = _id: @doc_id
|
|
|
|
|
+ @ProjectLocator.findElement = sinon.stub().callsArgWith(1, null, @doc, fileSystem: @pathname)
|
|
|
|
|
+ @ProjectEntityHandler.getDoc = sinon.stub().callsArgWith(2, null, @doc_lines, @rev, @version, @ranges)
|
|
|
|
|
+ @DocumentController.getDocument(@req, @res, @next)
|
|
|
|
|
+
|
|
|
|
|
+ it "should get the project", ->
|
|
|
|
|
+ @ProjectGetter.getProject
|
|
|
|
|
+ .calledWith(@project_id, rootFolder: true, overleaf: true)
|
|
|
|
|
+ .should.equal true
|
|
|
|
|
+
|
|
|
|
|
+ it "should get the pathname of the document", ->
|
|
|
|
|
+ @ProjectLocator.findElement
|
|
|
|
|
+ .calledWith({project: @project, element_id: @doc_id, type: 'doc'})
|
|
|
|
|
+ .should.equal true
|
|
|
|
|
+
|
|
|
|
|
+ it "should get the document content", ->
|
|
|
|
|
+ @ProjectEntityHandler.getDoc
|
|
|
|
|
+ .calledWith(@project_id, @doc_id)
|
|
|
|
|
+ .should.equal true
|
|
|
|
|
+
|
|
|
|
|
+ it "should return the document data to the client as JSON", ->
|
|
|
|
|
+ @res.type.should.equal "json"
|
|
|
|
|
+ @res.body.should.equal JSON.stringify
|
|
|
|
|
+ lines: @doc_lines
|
|
|
|
|
+ version: @version
|
|
|
|
|
+ ranges: @ranges
|
|
|
|
|
+ pathname: @pathname
|
|
|
|
|
+
|
|
|
|
|
+ describe "when the document doesn't exist", ->
|
|
|
|
|
+ beforeEach ->
|
|
|
|
|
+ @ProjectLocator.findElement = sinon.stub().callsArgWith(1, new Errors.NotFoundError("not found"))
|
|
|
|
|
+ @DocumentController.getDocument(@req, @res, @next)
|
|
|
|
|
+
|
|
|
|
|
+ it "should call next with the NotFoundError", ->
|
|
|
|
|
+ @next.calledWith(new Errors.NotFoundError("not found"))
|
|
|
|
|
+ .should.equal true
|
|
|
|
|
+
|
|
|
|
|
+ describe "when project exists with project history enabled", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
@doc = _id: @doc_id
|
|
@doc = _id: @doc_id
|
|
|
|
|
+ @projectHistoryId = 1234
|
|
|
|
|
+ @project = _id: @project_id, overleaf: history: id: @projectHistoryId
|
|
|
|
|
+ @ProjectGetter.getProject = sinon.stub().callsArgWith(2, null, @project)
|
|
|
@ProjectLocator.findElement = sinon.stub().callsArgWith(1, null, @doc, fileSystem: @pathname)
|
|
@ProjectLocator.findElement = sinon.stub().callsArgWith(1, null, @doc, fileSystem: @pathname)
|
|
|
@ProjectEntityHandler.getDoc = sinon.stub().callsArgWith(2, null, @doc_lines, @rev, @version, @ranges)
|
|
@ProjectEntityHandler.getDoc = sinon.stub().callsArgWith(2, null, @doc_lines, @rev, @version, @ranges)
|
|
|
@DocumentController.getDocument(@req, @res, @next)
|
|
@DocumentController.getDocument(@req, @res, @next)
|
|
|
|
|
|
|
|
- it "should get the pathname of the document", ->
|
|
|
|
|
- @ProjectLocator.findElement
|
|
|
|
|
- .calledWith({project_id: @project_id, element_id: @doc_id, type: 'doc'})
|
|
|
|
|
- .should.equal true
|
|
|
|
|
-
|
|
|
|
|
- it "should get the document content", ->
|
|
|
|
|
- @ProjectEntityHandler.getDoc
|
|
|
|
|
- .calledWith(@project_id, @doc_id)
|
|
|
|
|
- .should.equal true
|
|
|
|
|
-
|
|
|
|
|
- it "should return the document data to the client as JSON", ->
|
|
|
|
|
|
|
+ it "should return the history id to the client as JSON", ->
|
|
|
@res.type.should.equal "json"
|
|
@res.type.should.equal "json"
|
|
|
@res.body.should.equal JSON.stringify
|
|
@res.body.should.equal JSON.stringify
|
|
|
lines: @doc_lines
|
|
lines: @doc_lines
|
|
|
version: @version
|
|
version: @version
|
|
|
ranges: @ranges
|
|
ranges: @ranges
|
|
|
pathname: @pathname
|
|
pathname: @pathname
|
|
|
|
|
+ projectHistoryId: @projectHistoryId
|
|
|
|
|
|
|
|
- describe "when the document doesn't exist", ->
|
|
|
|
|
|
|
+ describe "when the project does not exist", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
- @ProjectLocator.findElement = sinon.stub().callsArgWith(1, new Errors.NotFoundError("not found"))
|
|
|
|
|
|
|
+ @ProjectGetter.getProject = sinon.stub().callsArgWith(2, null, null)
|
|
|
@DocumentController.getDocument(@req, @res, @next)
|
|
@DocumentController.getDocument(@req, @res, @next)
|
|
|
|
|
|
|
|
- it "should call next with the NotFoundError", ->
|
|
|
|
|
- @next.calledWith(new Errors.NotFoundError("not found"))
|
|
|
|
|
- .should.equal true
|
|
|
|
|
|
|
+ it "returns a 404", ->
|
|
|
|
|
+ @res.statusCode.should.equal 404
|
|
|
|
|
|
|
|
describe "setDocument", ->
|
|
describe "setDocument", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|