HealthCheckTests.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 { ObjectId } from 'mongodb'
  16. import nock from 'nock'
  17. import * as ProjectHistoryClient from './helpers/ProjectHistoryClient.js'
  18. import * as ProjectHistoryApp from './helpers/ProjectHistoryApp.js'
  19. const MockHistoryStore = () => nock('http://localhost:3100')
  20. const MockWeb = () => nock('http://localhost:3000')
  21. describe('Health Check', function () {
  22. beforeEach(function (done) {
  23. const projectId = ObjectId()
  24. const historyId = ObjectId().toString()
  25. settings.history.healthCheck = { project_id: projectId }
  26. return ProjectHistoryApp.ensureRunning(error => {
  27. if (error != null) {
  28. throw error
  29. }
  30. MockHistoryStore().post('/api/projects').reply(200, {
  31. projectId: historyId,
  32. })
  33. MockHistoryStore()
  34. .get(`/api/projects/${historyId}/latest/history`)
  35. .reply(200, {
  36. chunk: {
  37. startVersion: 0,
  38. history: {
  39. snapshot: {},
  40. changes: [],
  41. },
  42. },
  43. })
  44. MockWeb()
  45. .get(`/project/${projectId}/details`)
  46. .reply(200, {
  47. name: 'Test Project',
  48. overleaf: {
  49. history: {
  50. id: historyId,
  51. },
  52. },
  53. })
  54. return ProjectHistoryClient.initializeProject(historyId, done)
  55. })
  56. })
  57. return it('should respond to the health check', function (done) {
  58. return request.get(
  59. {
  60. url: 'http://localhost:3054/health_check',
  61. },
  62. (error, res, body) => {
  63. if (error != null) {
  64. return callback(error)
  65. }
  66. expect(res.statusCode).to.equal(200)
  67. return done()
  68. }
  69. )
  70. })
  71. })