SimpleLatexFileTests.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // TODO: This file was created by bulk-decaffeinate.
  2. // Fix any style issues and re-enable lint.
  3. /*
  4. * decaffeinate suggestions:
  5. * DS102: Remove unnecessary code created because of implicit returns
  6. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  7. */
  8. const Client = require('./helpers/Client')
  9. const request = require('request')
  10. const ClsiApp = require('./helpers/ClsiApp')
  11. const Settings = require('@overleaf/settings')
  12. describe('Simple LaTeX file', function () {
  13. before(function (done) {
  14. this.project_id = Client.randomId()
  15. this.request = {
  16. resources: [
  17. {
  18. path: 'main.tex',
  19. content: `\
  20. \\documentclass{article}
  21. \\begin{document}
  22. Hello world
  23. \\end{document}\
  24. `,
  25. },
  26. ],
  27. options: {
  28. metricsPath: 'clsi-perf',
  29. metricsMethod: 'priority',
  30. },
  31. }
  32. return ClsiApp.ensureRunning(() => {
  33. return Client.compile(
  34. this.project_id,
  35. this.request,
  36. (error, res, body) => {
  37. this.error = error
  38. this.res = res
  39. this.body = body
  40. return done()
  41. }
  42. )
  43. })
  44. })
  45. it('should return the PDF', function () {
  46. const pdf = Client.getOutputFile(this.body, 'pdf')
  47. return pdf.type.should.equal('pdf')
  48. })
  49. it('should return the log', function () {
  50. const log = Client.getOutputFile(this.body, 'log')
  51. return log.type.should.equal('log')
  52. })
  53. it('should provide the pdf for download', function (done) {
  54. const pdf = Client.getOutputFile(this.body, 'pdf')
  55. return request.get(pdf.url, (error, res, body) => {
  56. if (error) return done(error)
  57. res.statusCode.should.equal(200)
  58. return done()
  59. })
  60. })
  61. it('should provide the log for download', function (done) {
  62. const log = Client.getOutputFile(this.body, 'pdf')
  63. return request.get(log.url, (error, res, body) => {
  64. if (error) return done(error)
  65. res.statusCode.should.equal(200)
  66. return done()
  67. })
  68. })
  69. it('should gather personalized metrics', function (done) {
  70. request.get(`${Settings.apis.clsi.url}/metrics`, (err, res, body) => {
  71. if (err) return done(err)
  72. body
  73. .split('\n')
  74. .some(line => {
  75. return (
  76. line.startsWith('compile') &&
  77. line.includes('path="clsi-perf"') &&
  78. line.includes('method="priority"')
  79. )
  80. })
  81. .should.equal(true)
  82. done()
  83. })
  84. })
  85. })