AllowedImageNamesTests.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. const Client = require('./helpers/Client')
  2. const ClsiApp = require('./helpers/ClsiApp')
  3. const { expect } = require('chai')
  4. describe('AllowedImageNames', function () {
  5. beforeEach(async function () {
  6. this.project_id = Client.randomId()
  7. this.request = {
  8. options: {
  9. imageName: undefined,
  10. },
  11. resources: [
  12. {
  13. path: 'main.tex',
  14. content: `\
  15. \\documentclass{article}
  16. \\begin{document}
  17. Hello world
  18. \\end{document}\
  19. `,
  20. },
  21. ],
  22. }
  23. await ClsiApp.ensureRunning()
  24. })
  25. describe('with a valid name', function () {
  26. beforeEach(async function () {
  27. this.request.options.imageName = process.env.TEXLIVE_IMAGE
  28. try {
  29. this.body = await Client.compile(this.project_id, this.request)
  30. } catch (error) {
  31. this.error = error
  32. }
  33. })
  34. it('should return success', function () {
  35. expect(this.error).not.to.exist
  36. })
  37. it('should return a PDF', function () {
  38. let pdf
  39. try {
  40. pdf = Client.getOutputFile(this.body, 'pdf')
  41. } catch (e) {}
  42. expect(pdf).to.exist
  43. })
  44. })
  45. describe('with an invalid name', function () {
  46. beforeEach(async function () {
  47. this.request.options.imageName = 'something/evil:1337'
  48. try {
  49. this.body = await Client.compile(this.project_id, this.request)
  50. } catch (error) {
  51. this.error = error
  52. }
  53. })
  54. it('should return non success', function () {
  55. expect(this.error.response.status).to.equal(500)
  56. })
  57. it('should not return a PDF', function () {
  58. let pdf
  59. try {
  60. pdf = Client.getOutputFile(this.body, 'pdf')
  61. } catch (e) {}
  62. expect(pdf).to.not.exist
  63. })
  64. })
  65. describe('syncToCode', function () {
  66. beforeEach(async function () {
  67. await Client.compile(this.project_id, this.request)
  68. })
  69. it('should error out with an invalid imageName', async function () {
  70. const rejects = () =>
  71. expect(
  72. Client.syncFromCodeWithImage(
  73. this.project_id,
  74. 'main.tex',
  75. 3,
  76. 5,
  77. 'something/evil:1337'
  78. )
  79. ).to.eventually.be.rejected
  80. await rejects().and.have.property('body', 'invalid image')
  81. await rejects().and.have.property('info').to.contain({ status: 400 })
  82. })
  83. it('should produce a mapping a valid imageName', async function () {
  84. const result = await Client.syncFromCodeWithImage(
  85. this.project_id,
  86. 'main.tex',
  87. 3,
  88. 5,
  89. process.env.TEXLIVE_IMAGE
  90. )
  91. expect(result).to.deep.equal({
  92. pdf: [
  93. {
  94. page: 1,
  95. h: 133.768356,
  96. v: 134.764618,
  97. height: 6.918498,
  98. width: 343.71106,
  99. },
  100. ],
  101. downloadedFromCache: false,
  102. })
  103. })
  104. })
  105. describe('syncToPdf', function () {
  106. beforeEach(async function () {
  107. await Client.compile(this.project_id, this.request)
  108. })
  109. it('should error out with an invalid imageName', async function () {
  110. const rejects = () =>
  111. expect(
  112. Client.syncFromPdfWithImage(
  113. this.project_id,
  114. 'main.tex',
  115. 100,
  116. 200,
  117. 'something/evil:1337'
  118. )
  119. ).to.eventually.be.rejected
  120. await rejects().and.have.property('body', 'invalid image')
  121. await rejects().and.have.property('info').to.contain({ status: 400 })
  122. })
  123. it('should produce a mapping a valid imageName', async function () {
  124. const result = await Client.syncFromPdfWithImage(
  125. this.project_id,
  126. 1,
  127. 100,
  128. 200,
  129. process.env.TEXLIVE_IMAGE
  130. )
  131. expect(result).to.deep.equal({
  132. code: [{ file: 'main.tex', line: 3, column: -1 }],
  133. downloadedFromCache: false,
  134. })
  135. })
  136. })
  137. describe('wordcount', function () {
  138. beforeEach(async function () {
  139. await Client.compile(this.project_id, this.request)
  140. })
  141. it('should error out with an invalid imageName', async function () {
  142. const rejects = () =>
  143. expect(
  144. Client.wordcountWithImage(
  145. this.project_id,
  146. 'main.tex',
  147. 'something/evil:1337'
  148. )
  149. ).to.eventually.be.rejected
  150. await rejects().and.have.property('body', 'invalid image')
  151. await rejects().and.have.property('info').to.contain({ status: 400 })
  152. })
  153. it('should produce a texcout a valid imageName', async function () {
  154. const result = await Client.wordcountWithImage(
  155. this.project_id,
  156. 'main.tex',
  157. process.env.TEXLIVE_IMAGE
  158. )
  159. expect(result).to.exist
  160. expect(result.texcount).to.exist
  161. })
  162. })
  163. })