2020-02-19 06:15:37 -05:00
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
|
const sinon = require('sinon')
|
2020-06-26 08:17:45 -04:00
|
|
|
const { expect } = require('chai')
|
2020-02-19 06:15:37 -05:00
|
|
|
const modulePath = require('path').join(
|
|
|
|
__dirname,
|
|
|
|
'../../../app/js/CompileController'
|
|
|
|
)
|
2020-02-19 06:15:08 -05:00
|
|
|
|
2021-03-30 08:22:11 -04:00
|
|
|
function tryImageNameValidation(method, imageNameField) {
|
|
|
|
describe('when allowedImages is set', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.Settings.clsi = { docker: {} }
|
|
|
|
this.Settings.clsi.docker.allowedImages = [
|
|
|
|
'repo/image:tag1',
|
2021-07-13 07:04:48 -04:00
|
|
|
'repo/image:tag2',
|
2021-03-30 08:22:11 -04:00
|
|
|
]
|
|
|
|
this.res.send = sinon.stub()
|
|
|
|
this.res.status = sinon.stub().returns({ send: this.res.send })
|
|
|
|
|
|
|
|
this.CompileManager[method].reset()
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with an invalid image', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.req.query[imageNameField] = 'something/evil:1337'
|
|
|
|
this.CompileController[method](this.req, this.res, this.next)
|
|
|
|
})
|
|
|
|
it('should return a 400', function () {
|
|
|
|
expect(this.res.status.calledWith(400)).to.equal(true)
|
|
|
|
})
|
|
|
|
it('should not run the query', function () {
|
|
|
|
expect(this.CompileManager[method].called).to.equal(false)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with a valid image', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.req.query[imageNameField] = 'repo/image:tag1'
|
|
|
|
this.CompileController[method](this.req, this.res, this.next)
|
|
|
|
})
|
|
|
|
it('should not return a 400', function () {
|
|
|
|
expect(this.res.status.calledWith(400)).to.equal(false)
|
|
|
|
})
|
|
|
|
it('should run the query', function () {
|
|
|
|
expect(this.CompileManager[method].called).to.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('CompileController', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
this.CompileController = SandboxedModule.require(modulePath, {
|
|
|
|
requires: {
|
|
|
|
'./CompileManager': (this.CompileManager = {}),
|
|
|
|
'./RequestParser': (this.RequestParser = {}),
|
2021-07-12 12:47:21 -04:00
|
|
|
'@overleaf/settings': (this.Settings = {
|
2020-02-19 06:15:37 -05:00
|
|
|
apis: {
|
|
|
|
clsi: {
|
2022-05-25 06:56:10 -04:00
|
|
|
url: 'http://clsi.example.com',
|
|
|
|
outputUrlPrefix: '/zone/b',
|
2021-07-13 07:04:48 -04:00
|
|
|
},
|
|
|
|
},
|
2020-02-19 06:15:37 -05:00
|
|
|
}),
|
2023-05-23 04:10:44 -04:00
|
|
|
'@overleaf/metrics': {
|
|
|
|
Timer: sinon.stub().returns({ done: sinon.stub() }),
|
|
|
|
},
|
2021-07-13 07:04:48 -04:00
|
|
|
'./ProjectPersistenceManager': (this.ProjectPersistenceManager = {}),
|
|
|
|
},
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
this.Settings.externalUrl = 'http://www.example.com'
|
|
|
|
this.req = {}
|
|
|
|
this.res = {}
|
2022-06-06 07:41:07 -04:00
|
|
|
this.next = sinon.stub()
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
2020-02-19 06:15:08 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('compile', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
this.req.body = {
|
2021-07-13 07:04:48 -04:00
|
|
|
compile: 'mock-body',
|
2020-02-19 06:15:37 -05:00
|
|
|
}
|
|
|
|
this.req.params = { project_id: (this.project_id = 'project-id-123') }
|
|
|
|
this.request = {
|
2021-07-13 07:04:48 -04:00
|
|
|
compile: 'mock-parsed-request',
|
2020-02-19 06:15:37 -05:00
|
|
|
}
|
|
|
|
this.request_with_project_id = {
|
|
|
|
compile: this.request.compile,
|
2021-07-13 07:04:48 -04:00
|
|
|
project_id: this.project_id,
|
2020-02-19 06:15:37 -05:00
|
|
|
}
|
|
|
|
this.output_files = [
|
|
|
|
{
|
|
|
|
path: 'output.pdf',
|
|
|
|
type: 'pdf',
|
2021-06-22 07:14:33 -04:00
|
|
|
size: 1337,
|
2021-07-13 07:04:48 -04:00
|
|
|
build: 1234,
|
2020-02-19 06:15:37 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'output.log',
|
|
|
|
type: 'log',
|
2021-07-13 07:04:48 -04:00
|
|
|
build: 1234,
|
|
|
|
},
|
2020-02-19 06:15:37 -05:00
|
|
|
]
|
|
|
|
this.RequestParser.parse = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(1, null, this.request)
|
|
|
|
this.ProjectPersistenceManager.markProjectAsJustAccessed = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArg(1)
|
2021-05-13 09:07:54 -04:00
|
|
|
this.stats = { foo: 1 }
|
|
|
|
this.timings = { bar: 2 }
|
2020-02-19 06:15:37 -05:00
|
|
|
this.res.status = sinon.stub().returnsThis()
|
2022-06-06 07:41:07 -04:00
|
|
|
this.res.send = sinon.stub()
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
2020-02-19 06:15:08 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('successfully', function () {
|
|
|
|
beforeEach(function () {
|
2022-07-07 08:27:20 -04:00
|
|
|
this.CompileManager.doCompileWithLock = sinon.stub().yields(null, {
|
|
|
|
outputFiles: this.output_files,
|
|
|
|
stats: this.stats,
|
|
|
|
timings: this.timings,
|
|
|
|
})
|
2022-06-06 07:41:07 -04:00
|
|
|
this.CompileController.compile(this.req, this.res)
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
2020-02-19 06:15:08 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
it('should parse the request', function () {
|
2022-06-06 07:41:07 -04:00
|
|
|
this.RequestParser.parse.calledWith(this.req.body).should.equal(true)
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
2020-02-19 06:15:08 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
it('should run the compile for the specified project', function () {
|
2022-06-06 07:41:07 -04:00
|
|
|
this.CompileManager.doCompileWithLock
|
2020-02-19 06:15:37 -05:00
|
|
|
.calledWith(this.request_with_project_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
2020-02-19 06:15:08 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
it('should mark the project as accessed', function () {
|
2022-06-06 07:41:07 -04:00
|
|
|
this.ProjectPersistenceManager.markProjectAsJustAccessed
|
2020-02-19 06:15:37 -05:00
|
|
|
.calledWith(this.project_id)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
2020-02-19 06:15:08 -05:00
|
|
|
|
2022-06-06 07:41:07 -04:00
|
|
|
it('should return the JSON response', function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
this.res.status.calledWith(200).should.equal(true)
|
2024-05-16 13:39:31 -04:00
|
|
|
this.res.send
|
|
|
|
.calledWith({
|
|
|
|
compile: {
|
2020-02-19 06:15:37 -05:00
|
|
|
status: 'success',
|
2020-12-28 08:16:31 -05:00
|
|
|
error: null,
|
2021-05-13 09:07:54 -04:00
|
|
|
stats: this.stats,
|
|
|
|
timings: this.timings,
|
2022-05-25 06:56:10 -04:00
|
|
|
outputUrlPrefix: '/zone/b',
|
2024-05-16 13:39:31 -04:00
|
|
|
outputFiles: this.output_files.map(file => ({
|
|
|
|
url: `${this.Settings.apis.clsi.url}/project/${this.project_id}/build/${file.build}/output/${file.path}`,
|
|
|
|
...file,
|
|
|
|
})),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.should.equal(true)
|
2022-05-25 06:56:10 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('without a outputUrlPrefix', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.Settings.apis.clsi.outputUrlPrefix = ''
|
2022-07-07 08:27:20 -04:00
|
|
|
this.CompileManager.doCompileWithLock = sinon.stub().yields(null, {
|
|
|
|
outputFiles: this.output_files,
|
|
|
|
stats: this.stats,
|
|
|
|
timings: this.timings,
|
|
|
|
})
|
2022-05-25 06:56:10 -04:00
|
|
|
this.CompileController.compile(this.req, this.res)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should return the JSON response with empty outputUrlPrefix', function () {
|
|
|
|
this.res.status.calledWith(200).should.equal(true)
|
|
|
|
this.res.send
|
|
|
|
.calledWith({
|
|
|
|
compile: {
|
|
|
|
status: 'success',
|
|
|
|
error: null,
|
|
|
|
stats: this.stats,
|
|
|
|
timings: this.timings,
|
|
|
|
outputUrlPrefix: '',
|
2024-05-16 13:39:31 -04:00
|
|
|
outputFiles: this.output_files.map(file => ({
|
|
|
|
url: `${this.Settings.apis.clsi.url}/project/${this.project_id}/build/${file.build}/output/${file.path}`,
|
|
|
|
...file,
|
|
|
|
})),
|
2021-07-13 07:04:48 -04:00
|
|
|
},
|
2020-12-28 08:16:31 -05:00
|
|
|
})
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with user provided fake_output.pdf', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.output_files = [
|
|
|
|
{
|
|
|
|
path: 'fake_output.pdf',
|
|
|
|
type: 'pdf',
|
2021-07-13 07:04:48 -04:00
|
|
|
build: 1234,
|
2020-12-28 08:16:31 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'output.log',
|
|
|
|
type: 'log',
|
2021-07-13 07:04:48 -04:00
|
|
|
build: 1234,
|
|
|
|
},
|
2020-12-28 08:16:31 -05:00
|
|
|
]
|
2022-07-07 08:27:20 -04:00
|
|
|
this.CompileManager.doCompileWithLock = sinon.stub().yields(null, {
|
|
|
|
outputFiles: this.output_files,
|
|
|
|
stats: this.stats,
|
|
|
|
timings: this.timings,
|
|
|
|
})
|
2020-12-28 08:16:31 -05:00
|
|
|
this.CompileController.compile(this.req, this.res)
|
|
|
|
})
|
|
|
|
|
2021-06-22 07:14:33 -04:00
|
|
|
it('should return the JSON response with status failure', function () {
|
|
|
|
this.res.status.calledWith(200).should.equal(true)
|
|
|
|
this.res.send
|
|
|
|
.calledWith({
|
|
|
|
compile: {
|
|
|
|
status: 'failure',
|
|
|
|
error: null,
|
|
|
|
stats: this.stats,
|
|
|
|
timings: this.timings,
|
2022-05-25 06:56:10 -04:00
|
|
|
outputUrlPrefix: '/zone/b',
|
2024-05-16 13:39:31 -04:00
|
|
|
outputFiles: this.output_files.map(file => ({
|
|
|
|
url: `${this.Settings.apis.clsi.url}/project/${this.project_id}/build/${file.build}/output/${file.path}`,
|
|
|
|
...file,
|
|
|
|
})),
|
2021-07-13 07:04:48 -04:00
|
|
|
},
|
2021-06-22 07:14:33 -04:00
|
|
|
})
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with an empty output.pdf', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.output_files = [
|
|
|
|
{
|
|
|
|
path: 'output.pdf',
|
|
|
|
type: 'pdf',
|
|
|
|
size: 0,
|
2021-07-13 07:04:48 -04:00
|
|
|
build: 1234,
|
2021-06-22 07:14:33 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'output.log',
|
|
|
|
type: 'log',
|
2021-07-13 07:04:48 -04:00
|
|
|
build: 1234,
|
|
|
|
},
|
2021-06-22 07:14:33 -04:00
|
|
|
]
|
2022-07-07 08:27:20 -04:00
|
|
|
this.CompileManager.doCompileWithLock = sinon.stub().yields(null, {
|
|
|
|
outputFiles: this.output_files,
|
|
|
|
stats: this.stats,
|
|
|
|
timings: this.timings,
|
|
|
|
})
|
2021-06-22 07:14:33 -04:00
|
|
|
this.CompileController.compile(this.req, this.res)
|
|
|
|
})
|
|
|
|
|
2020-12-28 08:16:31 -05:00
|
|
|
it('should return the JSON response with status failure', function () {
|
|
|
|
this.res.status.calledWith(200).should.equal(true)
|
|
|
|
this.res.send
|
|
|
|
.calledWith({
|
|
|
|
compile: {
|
|
|
|
status: 'failure',
|
2020-02-19 06:15:37 -05:00
|
|
|
error: null,
|
2021-05-13 09:07:54 -04:00
|
|
|
stats: this.stats,
|
|
|
|
timings: this.timings,
|
2022-05-25 06:56:10 -04:00
|
|
|
outputUrlPrefix: '/zone/b',
|
2024-05-16 13:39:31 -04:00
|
|
|
outputFiles: this.output_files.map(file => ({
|
|
|
|
url: `${this.Settings.apis.clsi.url}/project/${this.project_id}/build/${file.build}/output/${file.path}`,
|
|
|
|
...file,
|
|
|
|
})),
|
2021-07-13 07:04:48 -04:00
|
|
|
},
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
2020-02-19 06:15:08 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('with an error', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
this.CompileManager.doCompileWithLock = sinon
|
|
|
|
.stub()
|
2024-05-16 13:39:31 -04:00
|
|
|
.callsArgWith(1, new Error((this.message = 'error message')), null)
|
2022-06-06 07:41:07 -04:00
|
|
|
this.CompileController.compile(this.req, this.res)
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
2014-05-19 07:18:57 -04:00
|
|
|
|
2022-06-06 07:41:07 -04:00
|
|
|
it('should return the JSON response with the error', function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
this.res.status.calledWith(500).should.equal(true)
|
2022-06-06 07:41:07 -04:00
|
|
|
this.res.send
|
2020-02-19 06:15:37 -05:00
|
|
|
.calledWith({
|
|
|
|
compile: {
|
|
|
|
status: 'error',
|
|
|
|
error: this.message,
|
2022-05-25 06:56:10 -04:00
|
|
|
outputUrlPrefix: '/zone/b',
|
2021-05-13 09:07:54 -04:00
|
|
|
outputFiles: [],
|
|
|
|
// JSON.stringify will omit these
|
|
|
|
stats: undefined,
|
2021-07-13 07:04:48 -04:00
|
|
|
timings: undefined,
|
|
|
|
},
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
2020-02-19 06:15:08 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('when the request times out', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
this.error = new Error((this.message = 'container timed out'))
|
|
|
|
this.error.timedout = true
|
|
|
|
this.CompileManager.doCompileWithLock = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(1, this.error, null)
|
2022-06-06 07:41:07 -04:00
|
|
|
this.CompileController.compile(this.req, this.res)
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
2020-02-19 06:15:08 -05:00
|
|
|
|
2022-06-06 07:41:07 -04:00
|
|
|
it('should return the JSON response with the timeout status', function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
this.res.status.calledWith(200).should.equal(true)
|
2022-06-06 07:41:07 -04:00
|
|
|
this.res.send
|
2020-02-19 06:15:37 -05:00
|
|
|
.calledWith({
|
|
|
|
compile: {
|
|
|
|
status: 'timedout',
|
|
|
|
error: this.message,
|
2022-05-25 06:56:10 -04:00
|
|
|
outputUrlPrefix: '/zone/b',
|
2021-05-13 09:07:54 -04:00
|
|
|
outputFiles: [],
|
|
|
|
// JSON.stringify will omit these
|
|
|
|
stats: undefined,
|
2021-07-13 07:04:48 -04:00
|
|
|
timings: undefined,
|
|
|
|
},
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
2020-02-19 06:15:08 -05:00
|
|
|
|
2022-06-06 07:41:07 -04:00
|
|
|
describe('when the request returns no output files', function () {
|
2020-08-10 12:01:11 -04:00
|
|
|
beforeEach(function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
this.CompileManager.doCompileWithLock = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(1, null, [])
|
2022-06-06 07:41:07 -04:00
|
|
|
this.CompileController.compile(this.req, this.res)
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
2020-02-19 06:15:08 -05:00
|
|
|
|
2022-06-06 07:41:07 -04:00
|
|
|
it('should return the JSON response with the failure status', function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
this.res.status.calledWith(200).should.equal(true)
|
2022-06-06 07:41:07 -04:00
|
|
|
this.res.send
|
2020-02-19 06:15:37 -05:00
|
|
|
.calledWith({
|
|
|
|
compile: {
|
|
|
|
error: null,
|
|
|
|
status: 'failure',
|
2022-05-25 06:56:10 -04:00
|
|
|
outputUrlPrefix: '/zone/b',
|
2021-05-13 09:07:54 -04:00
|
|
|
outputFiles: [],
|
|
|
|
// JSON.stringify will omit these
|
|
|
|
stats: undefined,
|
2021-07-13 07:04:48 -04:00
|
|
|
timings: undefined,
|
|
|
|
},
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2020-02-19 06:15:08 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('syncFromCode', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
this.file = 'main.tex'
|
|
|
|
this.line = 42
|
|
|
|
this.column = 5
|
|
|
|
this.project_id = 'mock-project-id'
|
|
|
|
this.req.params = { project_id: this.project_id }
|
|
|
|
this.req.query = {
|
|
|
|
file: this.file,
|
|
|
|
line: this.line.toString(),
|
2021-07-13 07:04:48 -04:00
|
|
|
column: this.column.toString(),
|
2020-02-19 06:15:37 -05:00
|
|
|
}
|
|
|
|
this.res.json = sinon.stub()
|
2020-02-19 06:15:08 -05:00
|
|
|
|
2020-02-19 06:15:37 -05:00
|
|
|
this.CompileManager.syncFromCode = sinon
|
|
|
|
.stub()
|
2021-03-30 08:22:11 -04:00
|
|
|
.yields(null, (this.pdfPositions = ['mock-positions']))
|
2022-06-06 07:41:07 -04:00
|
|
|
this.CompileController.syncFromCode(this.req, this.res, this.next)
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
2020-02-19 06:15:08 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
it('should find the corresponding location in the PDF', function () {
|
2022-06-06 07:41:07 -04:00
|
|
|
this.CompileManager.syncFromCode
|
2020-02-19 06:15:37 -05:00
|
|
|
.calledWith(
|
|
|
|
this.project_id,
|
|
|
|
undefined,
|
|
|
|
this.file,
|
|
|
|
this.line,
|
|
|
|
this.column
|
|
|
|
)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
2020-02-19 06:15:08 -05:00
|
|
|
|
2021-03-30 08:22:11 -04:00
|
|
|
it('should return the positions', function () {
|
2022-06-06 07:41:07 -04:00
|
|
|
this.res.json
|
2020-02-19 06:15:37 -05:00
|
|
|
.calledWith({
|
2021-07-13 07:04:48 -04:00
|
|
|
pdf: this.pdfPositions,
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
2021-03-30 08:22:11 -04:00
|
|
|
|
|
|
|
tryImageNameValidation('syncFromCode', 'imageName')
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
2020-02-19 06:15:08 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('syncFromPdf', function () {
|
|
|
|
beforeEach(function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
this.page = 5
|
|
|
|
this.h = 100.23
|
|
|
|
this.v = 45.67
|
|
|
|
this.project_id = 'mock-project-id'
|
|
|
|
this.req.params = { project_id: this.project_id }
|
|
|
|
this.req.query = {
|
|
|
|
page: this.page.toString(),
|
|
|
|
h: this.h.toString(),
|
2021-07-13 07:04:48 -04:00
|
|
|
v: this.v.toString(),
|
2020-02-19 06:15:37 -05:00
|
|
|
}
|
|
|
|
this.res.json = sinon.stub()
|
2020-02-19 06:15:08 -05:00
|
|
|
|
2020-02-19 06:15:37 -05:00
|
|
|
this.CompileManager.syncFromPdf = sinon
|
|
|
|
.stub()
|
2021-03-30 08:22:11 -04:00
|
|
|
.yields(null, (this.codePositions = ['mock-positions']))
|
2022-06-06 07:41:07 -04:00
|
|
|
this.CompileController.syncFromPdf(this.req, this.res, this.next)
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
2020-02-19 06:15:08 -05:00
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
it('should find the corresponding location in the code', function () {
|
2022-06-06 07:41:07 -04:00
|
|
|
this.CompileManager.syncFromPdf
|
2020-02-19 06:15:37 -05:00
|
|
|
.calledWith(this.project_id, undefined, this.page, this.h, this.v)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
2020-02-19 06:15:08 -05:00
|
|
|
|
2021-03-30 08:22:11 -04:00
|
|
|
it('should return the positions', function () {
|
2022-06-06 07:41:07 -04:00
|
|
|
this.res.json
|
2020-02-19 06:15:37 -05:00
|
|
|
.calledWith({
|
2021-07-13 07:04:48 -04:00
|
|
|
code: this.codePositions,
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
2021-03-30 08:22:11 -04:00
|
|
|
|
|
|
|
tryImageNameValidation('syncFromPdf', 'imageName')
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
|
2022-06-06 07:41:07 -04:00
|
|
|
describe('wordcount', function () {
|
2020-08-10 12:01:11 -04:00
|
|
|
beforeEach(function () {
|
2020-02-19 06:15:37 -05:00
|
|
|
this.file = 'main.tex'
|
|
|
|
this.project_id = 'mock-project-id'
|
|
|
|
this.req.params = { project_id: this.project_id }
|
|
|
|
this.req.query = {
|
|
|
|
file: this.file,
|
2021-07-13 07:04:48 -04:00
|
|
|
image: (this.image = 'example.com/image'),
|
2020-02-19 06:15:37 -05:00
|
|
|
}
|
|
|
|
this.res.json = sinon.stub()
|
|
|
|
|
|
|
|
this.CompileManager.wordcount = sinon
|
|
|
|
.stub()
|
|
|
|
.callsArgWith(4, null, (this.texcount = ['mock-texcount']))
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
it('should return the word count of a file', function () {
|
2020-06-26 08:17:45 -04:00
|
|
|
this.CompileController.wordcount(this.req, this.res, this.next)
|
2022-06-06 07:41:07 -04:00
|
|
|
this.CompileManager.wordcount
|
2020-02-19 06:15:37 -05:00
|
|
|
.calledWith(this.project_id, undefined, this.file, this.image)
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
it('should return the texcount info', function () {
|
2020-06-26 08:17:45 -04:00
|
|
|
this.CompileController.wordcount(this.req, this.res, this.next)
|
2022-06-06 07:41:07 -04:00
|
|
|
this.res.json
|
2020-02-19 06:15:37 -05:00
|
|
|
.calledWith({
|
2021-07-13 07:04:48 -04:00
|
|
|
texcount: this.texcount,
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
.should.equal(true)
|
|
|
|
})
|
2020-06-26 08:17:45 -04:00
|
|
|
|
2021-03-30 08:22:11 -04:00
|
|
|
tryImageNameValidation('wordcount', 'image')
|
2020-02-19 06:15:37 -05:00
|
|
|
})
|
|
|
|
})
|