HealthCheckTests.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { expect } from 'chai'
  2. import settings from '@overleaf/settings'
  3. import { fetchNothing } from '@overleaf/fetch-utils'
  4. import mongodb from 'mongodb-legacy'
  5. import nock from 'nock'
  6. import * as ProjectHistoryClient from './helpers/ProjectHistoryClient.js'
  7. import * as ProjectHistoryApp from './helpers/ProjectHistoryApp.js'
  8. const { ObjectId } = mongodb
  9. const MockHistoryStore = () => nock('http://127.0.0.1:3100')
  10. const MockWeb = () => nock('http://127.0.0.1:3000')
  11. describe('Health Check', function () {
  12. beforeEach(async function () {
  13. const projectId = new ObjectId()
  14. const historyId = new ObjectId().toString()
  15. settings.history.healthCheck = { project_id: projectId }
  16. await ProjectHistoryApp.ensureRunning()
  17. MockHistoryStore().post('/api/projects').reply(200, {
  18. projectId: historyId,
  19. })
  20. MockHistoryStore()
  21. .get(`/api/projects/${historyId}/latest/history`)
  22. .reply(200, {
  23. chunk: {
  24. startVersion: 0,
  25. history: {
  26. snapshot: {},
  27. changes: [],
  28. },
  29. },
  30. })
  31. MockWeb()
  32. .get(`/project/${projectId}/details`)
  33. .reply(200, {
  34. name: 'Test Project',
  35. overleaf: {
  36. history: {
  37. id: historyId,
  38. },
  39. },
  40. })
  41. await ProjectHistoryClient.initializeProject(historyId)
  42. })
  43. it('should respond to the health check', async function () {
  44. const response = await fetchNothing('http://127.0.0.1:3054/health_check')
  45. expect(response.status).to.equal(200)
  46. })
  47. })