2018-10-24 21:42:33 +08:00
|
|
|
'use strict';
|
|
|
|
|
2014-08-27 00:40:58 +08:00
|
|
|
require('../helper');
|
|
|
|
require('../support/assert');
|
|
|
|
|
2015-05-13 17:21:44 +08:00
|
|
|
var assert = require('assert');
|
2019-10-04 00:24:39 +08:00
|
|
|
var server = require('../../lib/server')();
|
2014-08-27 00:40:58 +08:00
|
|
|
|
2015-05-13 17:21:44 +08:00
|
|
|
describe('health checks', function() {
|
2014-08-27 00:40:58 +08:00
|
|
|
|
|
|
|
beforeEach(function(done) {
|
|
|
|
global.settings.health = {
|
2015-04-06 22:44:01 +08:00
|
|
|
enabled: true
|
|
|
|
//username: 'vizzuality',
|
|
|
|
//query: 'select 1::text'
|
2014-08-27 00:40:58 +08:00
|
|
|
};
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2014-08-27 23:09:59 +08:00
|
|
|
var healthCheckRequest = {
|
|
|
|
url: '/api/v1/health',
|
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
host: 'vizzuality.localhost'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-05-13 17:21:44 +08:00
|
|
|
it('returns 200 and ok=true with disabled configuration', function(done) {
|
2014-08-27 00:40:58 +08:00
|
|
|
global.settings.health.enabled = false;
|
|
|
|
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server,
|
2014-08-27 23:09:59 +08:00
|
|
|
healthCheckRequest,
|
2014-08-27 00:40:58 +08:00
|
|
|
{
|
|
|
|
status: 200
|
|
|
|
},
|
2016-09-26 20:37:40 +08:00
|
|
|
function(err, res) {
|
2014-08-27 00:40:58 +08:00
|
|
|
assert.ok(!err);
|
|
|
|
|
|
|
|
var parsed = JSON.parse(res.body);
|
|
|
|
|
|
|
|
assert.equal(parsed.enabled, false);
|
|
|
|
assert.ok(parsed.ok);
|
|
|
|
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2015-05-13 17:21:44 +08:00
|
|
|
it('returns 200 and ok=true with enabled configuration', function(done) {
|
2016-09-15 02:54:24 +08:00
|
|
|
assert.response(server,
|
2014-08-27 23:09:59 +08:00
|
|
|
healthCheckRequest,
|
2014-08-27 00:40:58 +08:00
|
|
|
{
|
|
|
|
status: 200
|
|
|
|
},
|
2016-09-26 20:37:40 +08:00
|
|
|
function(err, res) {
|
2014-08-27 00:40:58 +08:00
|
|
|
assert.ok(!err);
|
|
|
|
|
|
|
|
var parsed = JSON.parse(res.body);
|
|
|
|
|
|
|
|
assert.ok(parsed.enabled);
|
|
|
|
assert.ok(parsed.ok);
|
|
|
|
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|