2020-12-02 05:16:16 -05:00
|
|
|
const { expect } = require('chai')
|
|
|
|
const Settings = require('settings-sharelatex')
|
|
|
|
const User = require('./helpers/User').promises
|
|
|
|
|
|
|
|
describe('HealthCheckController', function() {
|
|
|
|
describe('SmokeTests', function() {
|
|
|
|
let user, projectId
|
|
|
|
|
|
|
|
beforeEach(async function() {
|
|
|
|
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
|
|
|
|
})
|
|
|
|
|
|
|
|
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',
|
|
|
|
json: true
|
|
|
|
})
|
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 }
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('happy path', function() {
|
|
|
|
it('should respond with a 200 and stats', async function() {
|
|
|
|
const { response, body } = await performSmokeTestRequest()
|
|
|
|
|
|
|
|
expect(body.error).to.not.exist
|
|
|
|
expect(response.statusCode).to.equal(200)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-12-09 05:12:45 -05:00
|
|
|
describe('when the request is aborted', function() {
|
|
|
|
it('should not crash', async function() {
|
|
|
|
try {
|
|
|
|
await user.doRequest('GET', {
|
|
|
|
timeout: 1,
|
|
|
|
url: '/health_check/full',
|
|
|
|
json: true
|
|
|
|
})
|
|
|
|
} catch (err) {
|
|
|
|
expect(err.code).to.equal('ESOCKETTIMEDOUT')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
expect.fail('expected request to fail with timeout error')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-12-02 05:16:16 -05:00
|
|
|
describe('when the project does not exist', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
Settings.smokeTest.projectId = '404'
|
|
|
|
})
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when the password mismatches', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
Settings.smokeTest.password = 'foo-bar'
|
|
|
|
})
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|