ApiClsiTests.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* eslint-disable
  2. camelcase,
  3. max-len,
  4. no-unused-vars,
  5. node/no-deprecated-api,
  6. */
  7. // TODO: This file was created by bulk-decaffeinate.
  8. // Fix any style issues and re-enable lint.
  9. /*
  10. * decaffeinate suggestions:
  11. * DS102: Remove unnecessary code created because of implicit returns
  12. * DS207: Consider shorter variations of null checks
  13. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  14. */
  15. const { expect } = require('chai')
  16. const request = require('./helpers/request')
  17. const Settings = require('settings-sharelatex')
  18. const auth = new Buffer('sharelatex:password').toString('base64')
  19. const authed_request = request.defaults({
  20. headers: {
  21. Authorization: `Basic ${auth}`
  22. }
  23. })
  24. describe('ApiClsiTests', function() {
  25. describe('compile', function() {
  26. beforeEach(function(done) {
  27. this.compileSpec = {
  28. compile: {
  29. options: {
  30. compiler: 'pdflatex',
  31. timeout: 60
  32. },
  33. rootResourcePath: 'main.tex',
  34. resources: [
  35. {
  36. path: 'main/tex',
  37. content:
  38. '\\documentclass{article}\n\\begin{document}\nHello World\n\\end{document}'
  39. },
  40. {
  41. path: 'image.png',
  42. url: 'www.example.com/image.png',
  43. modified: 123456789
  44. }
  45. ]
  46. }
  47. }
  48. return done()
  49. })
  50. describe('valid request', function() {
  51. it('returns success and a list of output files', function(done) {
  52. return authed_request.post(
  53. {
  54. uri: '/api/clsi/compile/abcd',
  55. json: this.compileSpec
  56. },
  57. (error, response, body) => {
  58. if (error != null) {
  59. throw error
  60. }
  61. expect(response.statusCode).to.equal(200)
  62. expect(response.body).to.deep.equal({
  63. status: 'success',
  64. outputFiles: [
  65. {
  66. path: 'project.pdf',
  67. url: '/project/abcd/build/1234/output/project.pdf',
  68. type: 'pdf',
  69. build: 1234
  70. },
  71. {
  72. path: 'project.log',
  73. url: '/project/abcd/build/1234/output/project.log',
  74. type: 'log',
  75. build: 1234
  76. }
  77. ]
  78. })
  79. return done()
  80. }
  81. )
  82. })
  83. })
  84. describe('unauthorized', function() {
  85. it('returns 401', function(done) {
  86. return request.post(
  87. {
  88. uri: '/api/clsi/compile/abcd',
  89. json: this.compileSpec
  90. },
  91. (error, response, body) => {
  92. if (error != null) {
  93. throw error
  94. }
  95. expect(response.statusCode).to.equal(401)
  96. expect(response.body).to.equal('Unauthorized')
  97. return done()
  98. }
  99. )
  100. })
  101. })
  102. })
  103. describe('get output', function() {
  104. describe('valid file', function() {
  105. it('returns the file', function(done) {
  106. return authed_request.get(
  107. '/api/clsi/compile/abcd/build/1234/output/project.pdf',
  108. (error, response, body) => {
  109. if (error != null) {
  110. throw error
  111. }
  112. expect(response.statusCode).to.equal(200)
  113. expect(response.body).to.equal('mock-pdf')
  114. return done()
  115. }
  116. )
  117. })
  118. })
  119. describe('invalid file', function() {
  120. it('returns 404', function(done) {
  121. return authed_request.get(
  122. '/api/clsi/compile/abcd/build/1234/output/project.aux',
  123. (error, response, body) => {
  124. if (error != null) {
  125. throw error
  126. }
  127. expect(response.statusCode).to.equal(404)
  128. expect(response.body).to.not.equal('mock-pdf')
  129. return done()
  130. }
  131. )
  132. })
  133. })
  134. describe('unauthorized', function() {
  135. it('returns 401', function(done) {
  136. return request.get(
  137. '/api/clsi/compile/abcd/build/1234/output/project.pdf',
  138. (error, response, body) => {
  139. if (error != null) {
  140. throw error
  141. }
  142. expect(response.statusCode).to.equal(401)
  143. expect(response.body).to.not.equal('mock-pdf')
  144. return done()
  145. }
  146. )
  147. })
  148. })
  149. })
  150. })