2023-01-13 07:42:29 -05:00
|
|
|
/* eslint-disable
|
|
|
|
no-undef,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
|
|
|
import { expect } from 'chai'
|
|
|
|
import settings from '@overleaf/settings'
|
|
|
|
import request from 'request'
|
2023-12-15 05:51:11 -05:00
|
|
|
import mongodb from 'mongodb-legacy'
|
2023-01-13 07:42:29 -05:00
|
|
|
import nock from 'nock'
|
|
|
|
import * as ProjectHistoryClient from './helpers/ProjectHistoryClient.js'
|
|
|
|
import * as ProjectHistoryApp from './helpers/ProjectHistoryApp.js'
|
2023-12-15 05:51:11 -05:00
|
|
|
const { ObjectId } = mongodb
|
2023-01-13 07:42:29 -05:00
|
|
|
|
2024-04-25 08:56:00 -04:00
|
|
|
const MockHistoryStore = () => nock('http://127.0.0.1:3100')
|
|
|
|
const MockWeb = () => nock('http://127.0.0.1:3000')
|
2023-01-13 07:42:29 -05:00
|
|
|
|
|
|
|
describe('Health Check', function () {
|
|
|
|
beforeEach(function (done) {
|
2023-12-15 05:51:11 -05:00
|
|
|
const projectId = new ObjectId()
|
|
|
|
const historyId = new ObjectId().toString()
|
2023-03-20 09:41:11 -04:00
|
|
|
settings.history.healthCheck = { project_id: projectId }
|
2023-01-13 07:42:29 -05:00
|
|
|
return ProjectHistoryApp.ensureRunning(error => {
|
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
MockHistoryStore().post('/api/projects').reply(200, {
|
|
|
|
projectId: historyId,
|
|
|
|
})
|
|
|
|
MockHistoryStore()
|
|
|
|
.get(`/api/projects/${historyId}/latest/history`)
|
|
|
|
.reply(200, {
|
|
|
|
chunk: {
|
|
|
|
startVersion: 0,
|
|
|
|
history: {
|
|
|
|
snapshot: {},
|
|
|
|
changes: [],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
MockWeb()
|
2023-03-20 09:41:11 -04:00
|
|
|
.get(`/project/${projectId}/details`)
|
2023-01-13 07:42:29 -05:00
|
|
|
.reply(200, {
|
|
|
|
name: 'Test Project',
|
|
|
|
overleaf: {
|
|
|
|
history: {
|
|
|
|
id: historyId,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
return ProjectHistoryClient.initializeProject(historyId, done)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
return it('should respond to the health check', function (done) {
|
|
|
|
return request.get(
|
|
|
|
{
|
2024-04-25 08:56:00 -04:00
|
|
|
url: 'http://127.0.0.1:3054/health_check',
|
2023-01-13 07:42:29 -05:00
|
|
|
},
|
|
|
|
(error, res, body) => {
|
|
|
|
if (error != null) {
|
|
|
|
return callback(error)
|
|
|
|
}
|
|
|
|
expect(res.statusCode).to.equal(200)
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|