2014-02-12 05:23:40 -05:00
|
|
|
sinon = require('sinon')
|
|
|
|
chai = require('chai')
|
|
|
|
should = chai.should()
|
|
|
|
expect = chai.expect
|
|
|
|
modulePath = "../../../../app/js/Features/Compile/ClsiManager.js"
|
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
|
|
|
|
describe "ClsiManager", ->
|
|
|
|
beforeEach ->
|
2016-04-19 11:48:51 -04:00
|
|
|
@jar = {cookie:"stuff"}
|
2016-04-20 10:06:39 -04:00
|
|
|
@ClsiCookieManager =
|
2016-04-19 11:48:51 -04:00
|
|
|
getCookieJar: sinon.stub().callsArgWith(1, null, @jar)
|
2016-04-20 11:17:06 -04:00
|
|
|
setServerId: sinon.stub().callsArgWith(2)
|
2016-05-18 05:09:22 -04:00
|
|
|
_getServerId:sinon.stub()
|
2014-02-12 05:23:40 -05:00
|
|
|
@ClsiManager = SandboxedModule.require modulePath, requires:
|
|
|
|
"settings-sharelatex": @settings =
|
|
|
|
apis:
|
|
|
|
filestore:
|
|
|
|
url: "filestore.example.com"
|
|
|
|
secret: "secret"
|
|
|
|
clsi:
|
|
|
|
url: "http://clsi.example.com"
|
2014-10-16 12:52:21 -04:00
|
|
|
clsi_priority:
|
|
|
|
url: "https://clsipremium.example.com"
|
2014-02-12 05:23:40 -05:00
|
|
|
"../../models/Project": Project: @Project = {}
|
2014-05-06 07:54:26 -04:00
|
|
|
"../Project/ProjectEntityHandler": @ProjectEntityHandler = {}
|
2016-04-20 10:06:39 -04:00
|
|
|
"./ClsiCookieManager": @ClsiCookieManager
|
2016-03-21 09:28:53 -04:00
|
|
|
"logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub(), warn: sinon.stub() }
|
2016-04-19 11:48:51 -04:00
|
|
|
"request": @request = sinon.stub()
|
2014-02-12 05:23:40 -05:00
|
|
|
@project_id = "project-id"
|
|
|
|
@callback = sinon.stub()
|
|
|
|
|
|
|
|
describe "sendRequest", ->
|
|
|
|
beforeEach ->
|
2014-06-01 12:16:05 -04:00
|
|
|
@ClsiManager._buildRequest = sinon.stub().callsArgWith(2, null, @request = "mock-request")
|
2016-05-18 05:09:22 -04:00
|
|
|
@ClsiCookieManager._getServerId.callsArgWith(1, null, "clsi3")
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
describe "with a successful compile", ->
|
|
|
|
beforeEach ->
|
2014-10-16 12:52:21 -04:00
|
|
|
@ClsiManager._postToClsi = sinon.stub().callsArgWith(3, null, {
|
2014-02-12 05:23:40 -05:00
|
|
|
compile:
|
2014-05-19 08:46:22 -04:00
|
|
|
status: @status = "success"
|
2014-02-12 05:23:40 -05:00
|
|
|
outputFiles: [{
|
|
|
|
url: "#{@settings.apis.clsi.url}/project/#{@project_id}/output/output.pdf"
|
|
|
|
type: "pdf"
|
2015-02-26 11:19:36 -05:00
|
|
|
build: 1234
|
2014-02-12 05:23:40 -05:00
|
|
|
},{
|
|
|
|
url: "#{@settings.apis.clsi.url}/project/#{@project_id}/output/output.log"
|
|
|
|
type: "log"
|
2015-02-26 11:19:36 -05:00
|
|
|
build: 1234
|
2014-02-12 05:23:40 -05:00
|
|
|
}]
|
|
|
|
})
|
2014-12-01 05:27:58 -05:00
|
|
|
@ClsiManager.sendRequest @project_id, {compileGroup:"standard"}, @callback
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2014-05-06 07:54:26 -04:00
|
|
|
it "should build the request", ->
|
2014-02-12 05:23:40 -05:00
|
|
|
@ClsiManager._buildRequest
|
2014-05-06 07:54:26 -04:00
|
|
|
.calledWith(@project_id)
|
2014-02-12 05:23:40 -05:00
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should send the request to the CLSI", ->
|
|
|
|
@ClsiManager._postToClsi
|
2014-10-16 12:52:21 -04:00
|
|
|
.calledWith(@project_id, @request, "standard")
|
2014-02-12 05:23:40 -05:00
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should call the callback with the status and output files", ->
|
|
|
|
outputFiles = [{
|
|
|
|
path: "output.pdf"
|
|
|
|
type: "pdf"
|
2015-02-26 11:19:36 -05:00
|
|
|
build: 1234
|
2014-02-12 05:23:40 -05:00
|
|
|
},{
|
|
|
|
path: "output.log"
|
|
|
|
type: "log"
|
2015-02-26 11:19:36 -05:00
|
|
|
build: 1234
|
2014-02-12 05:23:40 -05:00
|
|
|
}]
|
2014-05-19 08:46:22 -04:00
|
|
|
@callback.calledWith(null, @status, outputFiles).should.equal true
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
describe "with a failed compile", ->
|
|
|
|
beforeEach ->
|
2014-10-16 12:52:21 -04:00
|
|
|
@ClsiManager._postToClsi = sinon.stub().callsArgWith(3, null, {
|
2014-02-12 05:23:40 -05:00
|
|
|
compile:
|
2014-05-19 08:46:22 -04:00
|
|
|
status: @status = "failure"
|
2014-02-12 05:23:40 -05:00
|
|
|
})
|
2014-06-01 12:16:05 -04:00
|
|
|
@ClsiManager.sendRequest @project_id, {}, @callback
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
it "should call the callback with a failure statue", ->
|
2014-05-19 08:46:22 -04:00
|
|
|
@callback.calledWith(null, @status).should.equal true
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2014-05-19 11:10:41 -04:00
|
|
|
describe "deleteAuxFiles", ->
|
|
|
|
beforeEach ->
|
2016-04-19 11:48:51 -04:00
|
|
|
@ClsiManager._makeRequest = sinon.stub().callsArg(2)
|
2014-12-01 07:19:01 -05:00
|
|
|
|
|
|
|
describe "with the standard compileGroup", ->
|
|
|
|
beforeEach ->
|
|
|
|
@ClsiManager.deleteAuxFiles @project_id, {compileGroup: "standard"}, @callback
|
|
|
|
|
|
|
|
it "should call the delete method in the standard CLSI", ->
|
2016-04-19 11:48:51 -04:00
|
|
|
@ClsiManager._makeRequest
|
|
|
|
.calledWith(@project_id, { method:"DELETE", url:"#{@settings.apis.clsi.url}/project/#{@project_id}"})
|
2014-12-01 07:19:01 -05:00
|
|
|
.should.equal true
|
2014-05-19 11:10:41 -04:00
|
|
|
|
2014-12-01 07:19:01 -05:00
|
|
|
it "should call the callback", ->
|
|
|
|
@callback.called.should.equal true
|
|
|
|
|
2014-05-19 11:10:41 -04:00
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
describe "_buildRequest", ->
|
|
|
|
beforeEach ->
|
|
|
|
@project =
|
|
|
|
_id: @project_id
|
|
|
|
compiler: @compiler = "latex"
|
|
|
|
rootDoc_id: "mock-doc-id-1"
|
2016-01-14 11:35:42 -05:00
|
|
|
imageName: @image = "mock-image-name"
|
2014-05-06 07:54:26 -04:00
|
|
|
|
|
|
|
@docs = {
|
|
|
|
"/main.tex": @doc_1 = {
|
|
|
|
name: "main.tex"
|
|
|
|
_id: "mock-doc-id-1"
|
|
|
|
lines: ["Hello", "world"]
|
|
|
|
},
|
|
|
|
"/chapters/chapter1.tex": @doc_2 = {
|
|
|
|
name: "chapter1.tex"
|
|
|
|
_id: "mock-doc-id-2"
|
|
|
|
lines: [
|
|
|
|
"Chapter 1"
|
2014-02-12 05:23:40 -05:00
|
|
|
]
|
2014-05-06 07:54:26 -04:00
|
|
|
}
|
|
|
|
}
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2014-05-06 07:54:26 -04:00
|
|
|
@files = {
|
|
|
|
"/images/image.png": @file_1 = {
|
|
|
|
name: "image.png"
|
|
|
|
_id: "mock-file-id-1"
|
|
|
|
created: new Date()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Project.findById = sinon.stub().callsArgWith(2, null, @project)
|
|
|
|
@ProjectEntityHandler.getAllDocs = sinon.stub().callsArgWith(1, null, @docs)
|
|
|
|
@ProjectEntityHandler.getAllFiles = sinon.stub().callsArgWith(1, null, @files)
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
describe "with a valid project", ->
|
|
|
|
beforeEach (done) ->
|
2014-10-16 13:43:48 -04:00
|
|
|
@ClsiManager._buildRequest @project_id, {timeout:100}, (error, request) =>
|
2014-02-12 05:23:40 -05:00
|
|
|
@request = request
|
|
|
|
done()
|
|
|
|
|
2014-05-06 07:54:26 -04:00
|
|
|
it "should get the project with the required fields", ->
|
|
|
|
@Project.findById
|
2016-01-14 11:35:42 -05:00
|
|
|
.calledWith(@project_id, {compiler:1, rootDoc_id: 1, imageName: 1})
|
2014-05-06 07:54:26 -04:00
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should get all the docs", ->
|
|
|
|
@ProjectEntityHandler.getAllDocs
|
|
|
|
.calledWith(@project_id)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should get all the files", ->
|
|
|
|
@ProjectEntityHandler.getAllFiles
|
|
|
|
.calledWith(@project_id)
|
|
|
|
.should.equal true
|
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
it "should build up the CLSI request", ->
|
|
|
|
expect(@request).to.deep.equal(
|
|
|
|
compile:
|
|
|
|
options:
|
|
|
|
compiler: @compiler
|
2014-10-16 13:43:48 -04:00
|
|
|
timeout : 100
|
2016-01-14 11:35:42 -05:00
|
|
|
imageName: @image
|
2016-02-02 09:50:48 -05:00
|
|
|
draft: false
|
2014-02-12 05:23:40 -05:00
|
|
|
rootResourcePath: "main.tex"
|
|
|
|
resources: [{
|
2014-05-06 07:54:26 -04:00
|
|
|
path: "main.tex"
|
2014-02-12 05:23:40 -05:00
|
|
|
content: @doc_1.lines.join("\n")
|
|
|
|
}, {
|
2014-05-06 07:54:26 -04:00
|
|
|
path: "chapters/chapter1.tex"
|
2014-02-12 05:23:40 -05:00
|
|
|
content: @doc_2.lines.join("\n")
|
|
|
|
}, {
|
2014-05-06 07:54:26 -04:00
|
|
|
path: "images/image.png"
|
2014-02-12 05:23:40 -05:00
|
|
|
url: "#{@settings.apis.filestore.url}/project/#{@project_id}/file/#{@file_1._id}"
|
|
|
|
modified: @file_1.created.getTime()
|
|
|
|
}]
|
|
|
|
)
|
|
|
|
|
2014-06-01 16:28:19 -04:00
|
|
|
|
|
|
|
describe "when root doc override is valid", ->
|
|
|
|
beforeEach (done) ->
|
|
|
|
@ClsiManager._buildRequest @project_id, {rootDoc_id:"mock-doc-id-2"}, (error, request) =>
|
|
|
|
@request = request
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should change root path", ->
|
|
|
|
@request.compile.rootResourcePath.should.equal "chapters/chapter1.tex"
|
|
|
|
|
|
|
|
|
|
|
|
describe "when root doc override is invalid", ->
|
|
|
|
beforeEach (done) ->
|
|
|
|
@ClsiManager._buildRequest @project_id, {rootDoc_id:"invalid-id"}, (error, request) =>
|
|
|
|
@request = request
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should fallback to default root doc", ->
|
|
|
|
@request.compile.rootResourcePath.should.equal "main.tex"
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
describe "when the project has an invalid compiler", ->
|
|
|
|
beforeEach (done) ->
|
|
|
|
@project.compiler = "context"
|
2014-06-01 12:16:05 -04:00
|
|
|
@ClsiManager._buildRequest @project, null, (error, request) =>
|
2014-02-12 05:23:40 -05:00
|
|
|
@request = request
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should set the compiler to pdflatex", ->
|
|
|
|
@request.compile.options.compiler.should.equal "pdflatex"
|
|
|
|
|
|
|
|
describe "when there is no valid root document", ->
|
|
|
|
beforeEach (done) ->
|
|
|
|
@project.rootDoc_id = "not-valid"
|
2014-06-01 12:16:05 -04:00
|
|
|
@ClsiManager._buildRequest @project, null, (@error, @request) =>
|
2014-02-12 05:23:40 -05:00
|
|
|
done()
|
2016-03-21 09:28:53 -04:00
|
|
|
|
|
|
|
it "should set to main.tex", ->
|
|
|
|
@request.compile.rootResourcePath.should.equal "main.tex"
|
2016-02-02 09:50:48 -05:00
|
|
|
|
|
|
|
describe "with the draft option", ->
|
|
|
|
it "should add the draft option into the request", (done) ->
|
|
|
|
@ClsiManager._buildRequest @project_id, {timeout:100, draft: true}, (error, request) =>
|
|
|
|
request.compile.options.draft.should.equal true
|
|
|
|
done()
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
|
2014-05-19 08:46:22 -04:00
|
|
|
describe '_postToClsi', ->
|
|
|
|
beforeEach ->
|
|
|
|
@req = { mock: "req" }
|
|
|
|
|
|
|
|
describe "successfully", ->
|
|
|
|
beforeEach ->
|
2016-04-19 11:48:51 -04:00
|
|
|
@ClsiManager._makeRequest = sinon.stub().callsArgWith(2, null, {statusCode: 204}, @body = { mock: "foo" })
|
2014-10-16 12:52:21 -04:00
|
|
|
@ClsiManager._postToClsi @project_id, @req, "standard", @callback
|
2014-05-19 08:46:22 -04:00
|
|
|
|
|
|
|
it 'should send the request to the CLSI', ->
|
|
|
|
url = "#{@settings.apis.clsi.url}/project/#{@project_id}/compile"
|
2016-04-19 11:48:51 -04:00
|
|
|
@ClsiManager._makeRequest.calledWith(@project_id, {
|
|
|
|
method: "POST",
|
2014-05-19 08:46:22 -04:00
|
|
|
url: url
|
|
|
|
json: @req
|
|
|
|
}).should.equal true
|
|
|
|
|
|
|
|
it "should call the callback with the body and no error", ->
|
|
|
|
@callback.calledWith(null, @body).should.equal true
|
|
|
|
|
|
|
|
describe "when the CLSI returns an error", ->
|
|
|
|
beforeEach ->
|
2016-04-19 11:48:51 -04:00
|
|
|
@ClsiManager._makeRequest = sinon.stub().callsArgWith(2, null, {statusCode: 500}, @body = { mock: "foo" })
|
2014-10-16 12:52:21 -04:00
|
|
|
@ClsiManager._postToClsi @project_id, @req, "standard", @callback
|
2014-05-19 08:46:22 -04:00
|
|
|
|
|
|
|
it "should call the callback with the body and the error", ->
|
|
|
|
@callback.calledWith(new Error("CLSI returned non-success code: 500"), @body).should.equal true
|
|
|
|
|
2015-09-11 09:21:05 -04:00
|
|
|
|
|
|
|
describe "wordCount", ->
|
|
|
|
beforeEach ->
|
2016-04-19 11:48:51 -04:00
|
|
|
@ClsiManager._makeRequest = sinon.stub().callsArgWith(2, null, {statusCode: 200}, @body = { mock: "foo" })
|
2016-01-19 09:17:01 -05:00
|
|
|
@ClsiManager._buildRequest = sinon.stub().callsArgWith(2, null, @req = { compile: { rootResourcePath: "rootfile.text", options: {} } })
|
2015-09-11 09:21:05 -04:00
|
|
|
@ClsiManager._getCompilerUrl = sinon.stub().returns "compiler.url"
|
|
|
|
|
|
|
|
describe "with root file", ->
|
|
|
|
beforeEach ->
|
|
|
|
@ClsiManager.wordCount @project_id, false, {}, @callback
|
|
|
|
|
|
|
|
it "should call wordCount with root file", ->
|
2016-04-19 11:48:51 -04:00
|
|
|
@ClsiManager._makeRequest
|
|
|
|
.calledWith(@project_id, { method: "GET", url: "compiler.url/project/#{@project_id}/wordcount?file=rootfile.text" })
|
2015-09-11 09:21:05 -04:00
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should call the callback", ->
|
|
|
|
@callback.called.should.equal true
|
|
|
|
|
|
|
|
describe "with param file", ->
|
|
|
|
beforeEach ->
|
|
|
|
@ClsiManager.wordCount @project_id, "main.tex", {}, @callback
|
|
|
|
|
|
|
|
it "should call wordCount with param file", ->
|
2016-04-19 11:48:51 -04:00
|
|
|
@ClsiManager._makeRequest
|
|
|
|
.calledWith(@project_id, { method: "GET", url: "compiler.url/project/#{@project_id}/wordcount?file=main.tex" })
|
2015-09-11 09:21:05 -04:00
|
|
|
.should.equal true
|
2016-01-19 09:17:01 -05:00
|
|
|
|
|
|
|
describe "with image", ->
|
|
|
|
beforeEach ->
|
|
|
|
@req.compile.options.imageName = @image = "example.com/mock/image"
|
|
|
|
@ClsiManager.wordCount @project_id, "main.tex", {}, @callback
|
|
|
|
|
|
|
|
it "should call wordCount with file and image", ->
|
2016-04-19 11:48:51 -04:00
|
|
|
@ClsiManager._makeRequest
|
|
|
|
.calledWith(@project_id, { method: "GET", url: "compiler.url/project/#{@project_id}/wordcount?file=main.tex&image=#{encodeURIComponent(@image)}" })
|
2016-01-19 09:17:01 -05:00
|
|
|
.should.equal true
|
2016-04-20 11:17:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe "_makeRequest", ->
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
@response = {there:"something"}
|
|
|
|
@request.callsArgWith(1, null, @response)
|
|
|
|
@opts =
|
|
|
|
method: "SOMETHIGN"
|
|
|
|
url: "http://a place on the web"
|
|
|
|
|
|
|
|
it "should process a request with a cookie jar", (done)->
|
|
|
|
@ClsiManager._makeRequest @project_id, @opts, =>
|
|
|
|
args = @request.args[0]
|
|
|
|
args[0].method.should.equal @opts.method
|
|
|
|
args[0].url.should.equal @opts.url
|
|
|
|
args[0].jar.should.equal @jar
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should set the cookie again on response as it might have changed", (done)->
|
|
|
|
@ClsiManager._makeRequest @project_id, @opts, =>
|
|
|
|
@ClsiCookieManager.setServerId.calledWith(@project_id, @response).should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-06-01 07:28:54 -04:00
|
|
|
describe "_checkRecoursesForErrors", ->
|
2016-04-20 11:17:06 -04:00
|
|
|
|
2016-06-01 07:28:54 -04:00
|
|
|
beforeEach ->
|
|
|
|
@resources = [{
|
|
|
|
path: "main.tex"
|
|
|
|
content: ["stuff"]
|
|
|
|
}, {
|
|
|
|
path: "chapters/chapter1"
|
|
|
|
content: ["other stuff"]
|
|
|
|
}, {
|
|
|
|
path: "stuff/image/image.png"
|
|
|
|
url: "#{@settings.apis.filestore.url}/project/#{@project_id}/file/1234124321312"
|
|
|
|
modified: ["more stuff"]
|
|
|
|
}]
|
|
|
|
|
2016-06-01 11:46:41 -04:00
|
|
|
it "should call _checkForDuplicatePaths and _checkForConflictingPaths", (done)->
|
2016-06-01 07:28:54 -04:00
|
|
|
|
2016-06-01 11:46:41 -04:00
|
|
|
@ClsiManager._checkForDuplicatePaths = sinon.stub().callsArgWith(1)
|
2016-06-01 07:28:54 -04:00
|
|
|
@ClsiManager._checkForConflictingPaths = sinon.stub().callsArgWith(1)
|
|
|
|
@ClsiManager._checkDocsAreUnderSizeLimit = sinon.stub().callsArgWith(1)
|
2016-06-01 11:46:41 -04:00
|
|
|
@ClsiManager._checkRecoursesForErrors @resources, (err, problems)=>
|
|
|
|
@ClsiManager._checkForDuplicatePaths.called.should.equal true
|
2016-06-01 07:28:54 -04:00
|
|
|
@ClsiManager._checkForConflictingPaths.called.should.equal true
|
|
|
|
@ClsiManager._checkDocsAreUnderSizeLimit.called.should.equal true
|
2016-06-01 11:46:41 -04:00
|
|
|
expect(problems).to.not.exist
|
2016-06-01 07:28:54 -04:00
|
|
|
done()
|
2016-04-20 11:17:06 -04:00
|
|
|
|
2016-06-01 11:46:41 -04:00
|
|
|
|
|
|
|
it "should remove undefined errors", (done)->
|
|
|
|
@ClsiManager._checkForDuplicatePaths = sinon.stub().callsArgWith(1, null, [path:"something/here"])
|
|
|
|
@ClsiManager._checkForConflictingPaths = sinon.stub().callsArgWith(1, null, [])
|
|
|
|
@ClsiManager._checkDocsAreUnderSizeLimit = sinon.stub().callsArgWith(1, null)
|
|
|
|
@ClsiManager._checkRecoursesForErrors @resources, (err, problems)=>
|
|
|
|
problems.duplicatePaths[0].path.should.equal "something/here"
|
|
|
|
expect(problems.conflictedPaths).to.not.exist
|
|
|
|
expect(problems.sizeCheck).to.not.exist
|
|
|
|
|
|
|
|
done()
|
|
|
|
|
|
|
|
describe "_checkForDuplicatePaths", ->
|
2016-04-20 11:17:06 -04:00
|
|
|
|
2016-06-01 07:28:54 -04:00
|
|
|
it "should flag up 2 nested files with same path", (done)->
|
2016-04-20 11:17:06 -04:00
|
|
|
|
2016-06-01 07:28:54 -04:00
|
|
|
@resources.push({
|
|
|
|
path: "chapters/chapter1"
|
|
|
|
url: "http://somwhere.com"
|
|
|
|
})
|
2016-04-20 11:17:06 -04:00
|
|
|
|
2016-06-01 11:46:41 -04:00
|
|
|
@ClsiManager._checkForDuplicatePaths @resources, (err, duplicateErrors)->
|
2016-06-01 07:28:54 -04:00
|
|
|
duplicateErrors.length.should.equal 1
|
|
|
|
duplicateErrors[0].path.should.equal "chapters/chapter1"
|
|
|
|
done()
|
2016-04-20 11:17:06 -04:00
|
|
|
|
2016-06-01 07:28:54 -04:00
|
|
|
describe "_checkForConflictingPaths", ->
|
2016-04-20 11:17:06 -04:00
|
|
|
|
2016-06-01 07:28:54 -04:00
|
|
|
it "should flag up when a nested file has folder with same subpath as file elsewhere", (done)->
|
|
|
|
@resources.push({
|
|
|
|
path: "stuff/image"
|
|
|
|
url: "http://somwhere.com"
|
|
|
|
})
|
2016-04-20 11:17:06 -04:00
|
|
|
|
2016-06-01 07:28:54 -04:00
|
|
|
@resources.push({
|
|
|
|
path: "chapters/chapter1.tex"
|
|
|
|
content: ["other stuff"]
|
|
|
|
})
|
2016-04-20 11:17:06 -04:00
|
|
|
|
2016-06-01 07:28:54 -04:00
|
|
|
@resources.push({
|
|
|
|
path: "chapters.tex"
|
|
|
|
content: ["other stuff"]
|
|
|
|
})
|
2016-04-20 11:17:06 -04:00
|
|
|
|
2016-06-01 07:28:54 -04:00
|
|
|
@ClsiManager._checkForConflictingPaths @resources, (err, conflictPathErrors)->
|
|
|
|
conflictPathErrors.length.should.equal 1
|
|
|
|
conflictPathErrors[0].path.should.equal "stuff/image"
|
|
|
|
done()
|
|
|
|
|
|
|
|
|
|
|
|
describe "_checkDocsAreUnderSizeLimit", ->
|
|
|
|
|
|
|
|
it "should error when there is more than 2mb of data", (done)->
|
|
|
|
|
|
|
|
@resources.push({
|
|
|
|
path: "massive.tex"
|
|
|
|
content: [require("crypto").randomBytes(1000 * 1000 * 5).toString("hex")]
|
|
|
|
})
|
|
|
|
|
|
|
|
while @resources.length < 20
|
|
|
|
@resources.push({path:"chapters/chapter1.tex",url: "http://somwhere.com"})
|
|
|
|
|
|
|
|
@ClsiManager._checkDocsAreUnderSizeLimit @resources, (err, sizeError)->
|
|
|
|
sizeError.totalSize.should.equal 10000016
|
|
|
|
sizeError.resources.length.should.equal 10
|
|
|
|
sizeError.resources[0].path.should.equal "massive.tex"
|
|
|
|
sizeError.resources[0].size.should.equal 1000 * 1000 * 10
|
|
|
|
done()
|
|
|
|
|
2016-04-20 11:17:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|