2020-06-26 07:29:49 -04:00
|
|
|
const Client = require('./helpers/Client')
|
|
|
|
const ClsiApp = require('./helpers/ClsiApp')
|
|
|
|
const { expect } = require('chai')
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('AllowedImageNames', function () {
|
|
|
|
beforeEach(function (done) {
|
2020-06-26 07:29:49 -04:00
|
|
|
this.project_id = Client.randomId()
|
|
|
|
this.request = {
|
|
|
|
options: {
|
2021-07-13 07:04:48 -04:00
|
|
|
imageName: undefined,
|
2020-06-26 07:29:49 -04:00
|
|
|
},
|
|
|
|
resources: [
|
|
|
|
{
|
|
|
|
path: 'main.tex',
|
|
|
|
content: `\
|
|
|
|
\\documentclass{article}
|
|
|
|
\\begin{document}
|
|
|
|
Hello world
|
|
|
|
\\end{document}\
|
2021-07-13 07:04:48 -04:00
|
|
|
`,
|
|
|
|
},
|
|
|
|
],
|
2020-06-26 07:29:49 -04:00
|
|
|
}
|
|
|
|
ClsiApp.ensureRunning(done)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('with a valid name', function () {
|
|
|
|
beforeEach(function (done) {
|
2020-06-26 07:29:49 -04:00
|
|
|
this.request.options.imageName = process.env.TEXLIVE_IMAGE
|
|
|
|
|
|
|
|
Client.compile(this.project_id, this.request, (error, res, body) => {
|
|
|
|
this.error = error
|
|
|
|
this.res = res
|
|
|
|
this.body = body
|
|
|
|
done(error)
|
|
|
|
})
|
|
|
|
})
|
2020-08-10 12:01:11 -04:00
|
|
|
it('should return success', function () {
|
2020-06-26 07:29:49 -04:00
|
|
|
expect(this.res.statusCode).to.equal(200)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
it('should return a PDF', function () {
|
2020-06-26 07:29:49 -04:00
|
|
|
let pdf
|
|
|
|
try {
|
|
|
|
pdf = Client.getOutputFile(this.body, 'pdf')
|
|
|
|
} catch (e) {}
|
|
|
|
expect(pdf).to.exist
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('with an invalid name', function () {
|
|
|
|
beforeEach(function (done) {
|
2020-06-26 07:29:49 -04:00
|
|
|
this.request.options.imageName = 'something/evil:1337'
|
|
|
|
Client.compile(this.project_id, this.request, (error, res, body) => {
|
|
|
|
this.error = error
|
|
|
|
this.res = res
|
|
|
|
this.body = body
|
|
|
|
done(error)
|
|
|
|
})
|
|
|
|
})
|
2020-08-10 12:01:11 -04:00
|
|
|
it('should return non success', function () {
|
2020-06-26 07:29:49 -04:00
|
|
|
expect(this.res.statusCode).to.not.equal(200)
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
it('should not return a PDF', function () {
|
2020-06-26 07:29:49 -04:00
|
|
|
let pdf
|
|
|
|
try {
|
|
|
|
pdf = Client.getOutputFile(this.body, 'pdf')
|
|
|
|
} catch (e) {}
|
|
|
|
expect(pdf).to.not.exist
|
|
|
|
})
|
|
|
|
})
|
2020-06-26 08:17:45 -04:00
|
|
|
|
2021-03-30 08:22:11 -04:00
|
|
|
describe('syncToCode', function () {
|
|
|
|
beforeEach(function (done) {
|
|
|
|
Client.compile(this.project_id, this.request, done)
|
|
|
|
})
|
2021-05-25 05:24:49 -04:00
|
|
|
it('should error out with an invalid imageName', function (done) {
|
2021-03-30 08:22:11 -04:00
|
|
|
Client.syncFromCodeWithImage(
|
|
|
|
this.project_id,
|
|
|
|
'main.tex',
|
|
|
|
3,
|
|
|
|
5,
|
|
|
|
'something/evil:1337',
|
|
|
|
(error, body) => {
|
|
|
|
expect(String(error)).to.include('statusCode=400')
|
|
|
|
expect(body).to.equal('invalid image')
|
2021-05-25 05:24:49 -04:00
|
|
|
done()
|
2021-03-30 08:22:11 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-05-25 05:24:49 -04:00
|
|
|
it('should produce a mapping a valid imageName', function (done) {
|
2021-03-30 08:22:11 -04:00
|
|
|
Client.syncFromCodeWithImage(
|
|
|
|
this.project_id,
|
|
|
|
'main.tex',
|
|
|
|
3,
|
|
|
|
5,
|
|
|
|
process.env.TEXLIVE_IMAGE,
|
|
|
|
(error, result) => {
|
|
|
|
expect(error).to.not.exist
|
|
|
|
expect(result).to.deep.equal({
|
|
|
|
pdf: [
|
2021-07-13 07:04:48 -04:00
|
|
|
{ page: 1, h: 133.77, v: 134.76, height: 6.92, width: 343.71 },
|
|
|
|
],
|
2021-03-30 08:22:11 -04:00
|
|
|
})
|
2021-05-25 05:24:49 -04:00
|
|
|
done()
|
2021-03-30 08:22:11 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('syncToPdf', function () {
|
|
|
|
beforeEach(function (done) {
|
|
|
|
Client.compile(this.project_id, this.request, done)
|
|
|
|
})
|
2021-05-25 05:24:49 -04:00
|
|
|
it('should error out with an invalid imageName', function (done) {
|
2021-03-30 08:22:11 -04:00
|
|
|
Client.syncFromPdfWithImage(
|
|
|
|
this.project_id,
|
|
|
|
'main.tex',
|
|
|
|
100,
|
|
|
|
200,
|
|
|
|
'something/evil:1337',
|
|
|
|
(error, body) => {
|
|
|
|
expect(String(error)).to.include('statusCode=400')
|
|
|
|
expect(body).to.equal('invalid image')
|
2021-05-25 05:24:49 -04:00
|
|
|
done()
|
2021-03-30 08:22:11 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-05-25 05:24:49 -04:00
|
|
|
it('should produce a mapping a valid imageName', function (done) {
|
2021-03-30 08:22:11 -04:00
|
|
|
Client.syncFromPdfWithImage(
|
|
|
|
this.project_id,
|
|
|
|
1,
|
|
|
|
100,
|
|
|
|
200,
|
|
|
|
process.env.TEXLIVE_IMAGE,
|
|
|
|
(error, result) => {
|
|
|
|
expect(error).to.not.exist
|
|
|
|
expect(result).to.deep.equal({
|
2021-07-13 07:04:48 -04:00
|
|
|
code: [{ file: 'main.tex', line: 3, column: -1 }],
|
2021-03-30 08:22:11 -04:00
|
|
|
})
|
2021-05-25 05:24:49 -04:00
|
|
|
done()
|
2021-03-30 08:22:11 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-08-10 12:01:11 -04:00
|
|
|
describe('wordcount', function () {
|
|
|
|
beforeEach(function (done) {
|
2020-06-26 08:17:45 -04:00
|
|
|
Client.compile(this.project_id, this.request, done)
|
|
|
|
})
|
2021-05-25 05:24:49 -04:00
|
|
|
it('should error out with an invalid imageName', function (done) {
|
2020-06-26 08:17:45 -04:00
|
|
|
Client.wordcountWithImage(
|
|
|
|
this.project_id,
|
|
|
|
'main.tex',
|
|
|
|
'something/evil:1337',
|
2021-03-30 08:22:11 -04:00
|
|
|
(error, body) => {
|
2020-06-26 08:17:45 -04:00
|
|
|
expect(String(error)).to.include('statusCode=400')
|
2021-03-30 08:22:11 -04:00
|
|
|
expect(body).to.equal('invalid image')
|
2021-05-25 05:24:49 -04:00
|
|
|
done()
|
2020-06-26 08:17:45 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-05-25 05:24:49 -04:00
|
|
|
it('should produce a texcout a valid imageName', function (done) {
|
2020-06-26 08:17:45 -04:00
|
|
|
Client.wordcountWithImage(
|
|
|
|
this.project_id,
|
|
|
|
'main.tex',
|
|
|
|
process.env.TEXLIVE_IMAGE,
|
|
|
|
(error, result) => {
|
|
|
|
expect(error).to.not.exist
|
|
|
|
expect(result).to.exist
|
|
|
|
expect(result.texcount).to.exist
|
2021-05-25 05:24:49 -04:00
|
|
|
done()
|
2020-06-26 08:17:45 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
2020-06-26 07:29:49 -04:00
|
|
|
})
|