HealthCheckTests.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* eslint-disable
  2. no-undef,
  3. */
  4. // TODO: This file was created by bulk-decaffeinate.
  5. // Fix any style issues and re-enable lint.
  6. /*
  7. * decaffeinate suggestions:
  8. * DS102: Remove unnecessary code created because of implicit returns
  9. * DS207: Consider shorter variations of null checks
  10. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  11. */
  12. import { expect } from 'chai'
  13. import settings from '@overleaf/settings'
  14. import request from 'request'
  15. import mongodb from 'mongodb-legacy'
  16. import nock from 'nock'
  17. import * as ProjectHistoryClient from './helpers/ProjectHistoryClient.js'
  18. import * as ProjectHistoryApp from './helpers/ProjectHistoryApp.js'
  19. const { ObjectId } = mongodb
  20. const MockHistoryStore = () => nock('http://127.0.0.1:3100')
  21. const MockWeb = () => nock('http://127.0.0.1:3000')
  22. describe('Health Check', function () {
  23. beforeEach(function (done) {
  24. const projectId = new ObjectId()
  25. const historyId = new ObjectId().toString()
  26. settings.history.healthCheck = { project_id: projectId }
  27. return ProjectHistoryApp.ensureRunning(error => {
  28. if (error != null) {
  29. throw error
  30. }
  31. MockHistoryStore().post('/api/projects').reply(200, {
  32. projectId: historyId,
  33. })
  34. MockHistoryStore()
  35. .get(`/api/projects/${historyId}/latest/history`)
  36. .reply(200, {
  37. chunk: {
  38. startVersion: 0,
  39. history: {
  40. snapshot: {},
  41. changes: [],
  42. },
  43. },
  44. })
  45. MockWeb()
  46. .get(`/project/${projectId}/details`)
  47. .reply(200, {
  48. name: 'Test Project',
  49. overleaf: {
  50. history: {
  51. id: historyId,
  52. },
  53. },
  54. })
  55. return ProjectHistoryClient.initializeProject(historyId, done)
  56. })
  57. })
  58. return it('should respond to the health check', function (done) {
  59. return request.get(
  60. {
  61. url: 'http://127.0.0.1:3054/health_check',
  62. },
  63. (error, res, body) => {
  64. if (error != null) {
  65. return callback(error)
  66. }
  67. expect(res.statusCode).to.equal(200)
  68. return done()
  69. }
  70. )
  71. })
  72. })