2020-12-02 05:16:16 -05:00
|
|
|
const { expect } = require('chai')
|
2021-07-07 05:38:56 -04:00
|
|
|
const Settings = require('@overleaf/settings')
|
2020-12-02 05:16:16 -05:00
|
|
|
const User = require('./helpers/User').promises
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('HealthCheckController', function () {
|
|
|
|
describe('SmokeTests', function () {
|
2020-12-02 05:16:16 -05:00
|
|
|
let user, projectId
|
2022-01-26 06:15:19 -05:00
|
|
|
const captchaDisabledBefore = Settings.recaptcha.disabled.login
|
2020-12-02 05:16:16 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
beforeEach(async function () {
|
2020-12-02 05:16:16 -05:00
|
|
|
user = new User()
|
|
|
|
await user.login()
|
|
|
|
projectId = await user.createProject('SmokeTest')
|
|
|
|
|
|
|
|
// HACK: Inject the details into the app
|
|
|
|
Settings.smokeTest.userId = user.id
|
|
|
|
Settings.smokeTest.user = user.email
|
|
|
|
Settings.smokeTest.password = user.password
|
|
|
|
Settings.smokeTest.projectId = projectId
|
2022-01-26 06:15:19 -05:00
|
|
|
|
|
|
|
Settings.recaptcha.disabled.login = true
|
|
|
|
})
|
|
|
|
afterEach(function () {
|
|
|
|
Settings.recaptcha.disabled.login = captchaDisabledBefore
|
2020-12-02 05:16:16 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
async function performSmokeTestRequest() {
|
2020-12-09 05:12:45 -05:00
|
|
|
const start = Date.now()
|
2020-12-02 05:16:16 -05:00
|
|
|
const { response, body } = await user.doRequest('GET', {
|
|
|
|
url: '/health_check/full',
|
2021-04-27 03:52:58 -04:00
|
|
|
json: true,
|
2020-12-02 05:16:16 -05:00
|
|
|
})
|
2020-12-09 05:12:45 -05:00
|
|
|
const end = Date.now()
|
|
|
|
|
2020-12-02 05:16:16 -05:00
|
|
|
expect(body).to.exist
|
2020-12-09 05:12:45 -05:00
|
|
|
expect(body.stats).to.exist
|
|
|
|
expect(Date.parse(body.stats.start)).to.be.within(start, start + 1000)
|
|
|
|
expect(Date.parse(body.stats.end)).to.be.within(end - 1000, end)
|
|
|
|
|
|
|
|
expect(body.stats.duration).to.be.within(0, 10000)
|
|
|
|
expect(body.stats.steps).to.be.instanceof(Array)
|
2020-12-02 05:16:16 -05:00
|
|
|
return { response, body }
|
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('happy path', function () {
|
|
|
|
it('should respond with a 200 and stats', async function () {
|
2020-12-02 05:16:16 -05:00
|
|
|
const { response, body } = await performSmokeTestRequest()
|
|
|
|
|
|
|
|
expect(body.error).to.not.exist
|
|
|
|
expect(response.statusCode).to.equal(200)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when the request is aborted', function () {
|
|
|
|
it('should not crash', async function () {
|
2020-12-09 05:12:45 -05:00
|
|
|
try {
|
|
|
|
await user.doRequest('GET', {
|
|
|
|
timeout: 1,
|
|
|
|
url: '/health_check/full',
|
2021-04-27 03:52:58 -04:00
|
|
|
json: true,
|
2020-12-09 05:12:45 -05:00
|
|
|
})
|
|
|
|
} catch (err) {
|
2020-12-09 05:28:32 -05:00
|
|
|
expect(err.code).to.be.oneOf(['ETIMEDOUT', 'ESOCKETTIMEDOUT'])
|
2020-12-09 05:12:45 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
expect.fail('expected request to fail with timeout error')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when the project does not exist', function () {
|
|
|
|
beforeEach(function () {
|
2020-12-02 05:16:16 -05:00
|
|
|
Settings.smokeTest.projectId = '404'
|
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should respond with a 500 ', async function () {
|
2020-12-09 05:12:45 -05:00
|
|
|
const { response, body } = await performSmokeTestRequest()
|
2020-12-02 05:16:16 -05:00
|
|
|
|
2020-12-09 05:12:45 -05:00
|
|
|
expect(body.error).to.equal('run.101_loadEditor failed')
|
2020-12-02 05:16:16 -05:00
|
|
|
expect(response.statusCode).to.equal(500)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when the password mismatches', function () {
|
|
|
|
beforeEach(function () {
|
2020-12-02 05:16:16 -05:00
|
|
|
Settings.smokeTest.password = 'foo-bar'
|
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should respond with a 500 with mismatching password', async function () {
|
2020-12-09 05:12:45 -05:00
|
|
|
const { response, body } = await performSmokeTestRequest()
|
2020-12-02 05:16:16 -05:00
|
|
|
|
2020-12-09 05:12:45 -05:00
|
|
|
expect(body.error).to.equal('run.002_login failed')
|
2020-12-02 05:16:16 -05:00
|
|
|
expect(response.statusCode).to.equal(500)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|