HealthCheckControllerTests.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. const { expect } = require('chai')
  2. const Settings = require('settings-sharelatex')
  3. const User = require('./helpers/User').promises
  4. describe('HealthCheckController', function () {
  5. describe('SmokeTests', function () {
  6. let user, projectId
  7. beforeEach(async function () {
  8. user = new User()
  9. await user.login()
  10. projectId = await user.createProject('SmokeTest')
  11. // HACK: Inject the details into the app
  12. Settings.smokeTest.userId = user.id
  13. Settings.smokeTest.user = user.email
  14. Settings.smokeTest.password = user.password
  15. Settings.smokeTest.projectId = projectId
  16. })
  17. async function performSmokeTestRequest() {
  18. const start = Date.now()
  19. const { response, body } = await user.doRequest('GET', {
  20. url: '/health_check/full',
  21. json: true,
  22. })
  23. const end = Date.now()
  24. expect(body).to.exist
  25. expect(body.stats).to.exist
  26. expect(Date.parse(body.stats.start)).to.be.within(start, start + 1000)
  27. expect(Date.parse(body.stats.end)).to.be.within(end - 1000, end)
  28. expect(body.stats.duration).to.be.within(0, 10000)
  29. expect(body.stats.steps).to.be.instanceof(Array)
  30. return { response, body }
  31. }
  32. describe('happy path', function () {
  33. it('should respond with a 200 and stats', async function () {
  34. const { response, body } = await performSmokeTestRequest()
  35. expect(body.error).to.not.exist
  36. expect(response.statusCode).to.equal(200)
  37. })
  38. })
  39. describe('when the request is aborted', function () {
  40. it('should not crash', async function () {
  41. try {
  42. await user.doRequest('GET', {
  43. timeout: 1,
  44. url: '/health_check/full',
  45. json: true,
  46. })
  47. } catch (err) {
  48. expect(err.code).to.be.oneOf(['ETIMEDOUT', 'ESOCKETTIMEDOUT'])
  49. return
  50. }
  51. expect.fail('expected request to fail with timeout error')
  52. })
  53. })
  54. describe('when the project does not exist', function () {
  55. beforeEach(function () {
  56. Settings.smokeTest.projectId = '404'
  57. })
  58. it('should respond with a 500 ', async function () {
  59. const { response, body } = await performSmokeTestRequest()
  60. expect(body.error).to.equal('run.101_loadEditor failed')
  61. expect(response.statusCode).to.equal(500)
  62. })
  63. })
  64. describe('when the password mismatches', function () {
  65. beforeEach(function () {
  66. Settings.smokeTest.password = 'foo-bar'
  67. })
  68. it('should respond with a 500 with mismatching password', async function () {
  69. const { response, body } = await performSmokeTestRequest()
  70. expect(body.error).to.equal('run.002_login failed')
  71. expect(response.statusCode).to.equal(500)
  72. })
  73. })
  74. })
  75. })