| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- const Client = require('./helpers/Client')
- const ClsiApp = require('./helpers/ClsiApp')
- const { expect } = require('chai')
- describe('AllowedImageNames', function () {
- beforeEach(function (done) {
- this.project_id = Client.randomId()
- this.request = {
- options: {
- imageName: undefined,
- },
- resources: [
- {
- path: 'main.tex',
- content: `\
- \\documentclass{article}
- \\begin{document}
- Hello world
- \\end{document}\
- `,
- },
- ],
- }
- ClsiApp.ensureRunning(done)
- })
- describe('with a valid name', function () {
- beforeEach(function (done) {
- 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)
- })
- })
- it('should return success', function () {
- expect(this.res.statusCode).to.equal(200)
- })
- it('should return a PDF', function () {
- let pdf
- try {
- pdf = Client.getOutputFile(this.body, 'pdf')
- } catch (e) {}
- expect(pdf).to.exist
- })
- })
- describe('with an invalid name', function () {
- beforeEach(function (done) {
- 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)
- })
- })
- it('should return non success', function () {
- expect(this.res.statusCode).to.not.equal(200)
- })
- it('should not return a PDF', function () {
- let pdf
- try {
- pdf = Client.getOutputFile(this.body, 'pdf')
- } catch (e) {}
- expect(pdf).to.not.exist
- })
- })
- describe('syncToCode', function () {
- beforeEach(function (done) {
- Client.compile(this.project_id, this.request, done)
- })
- it('should error out with an invalid imageName', function (done) {
- 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')
- done()
- }
- )
- })
- it('should produce a mapping a valid imageName', function (done) {
- 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: [
- {
- page: 1,
- h: 133.768356,
- v: 134.764618,
- height: 6.918498,
- width: 343.71106,
- },
- ],
- })
- done()
- }
- )
- })
- })
- describe('syncToPdf', function () {
- beforeEach(function (done) {
- Client.compile(this.project_id, this.request, done)
- })
- it('should error out with an invalid imageName', function (done) {
- 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')
- done()
- }
- )
- })
- it('should produce a mapping a valid imageName', function (done) {
- Client.syncFromPdfWithImage(
- this.project_id,
- 1,
- 100,
- 200,
- process.env.TEXLIVE_IMAGE,
- (error, result) => {
- expect(error).to.not.exist
- expect(result).to.deep.equal({
- code: [{ file: 'main.tex', line: 3, column: -1 }],
- })
- done()
- }
- )
- })
- })
- describe('wordcount', function () {
- beforeEach(function (done) {
- Client.compile(this.project_id, this.request, done)
- })
- it('should error out with an invalid imageName', function (done) {
- Client.wordcountWithImage(
- this.project_id,
- 'main.tex',
- 'something/evil:1337',
- (error, body) => {
- expect(String(error)).to.include('statusCode=400')
- expect(body).to.equal('invalid image')
- done()
- }
- )
- })
- it('should produce a texcout a valid imageName', function (done) {
- 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
- done()
- }
- )
- })
- })
- })
|