Allow box auto update pattern to be configurable
We just use the current app auto update pattern as the default. There is now only one pattern for box and app updates. Fixes #727
This commit is contained in:
+6
-28
@@ -17,40 +17,20 @@ var assert = require('assert'),
|
||||
HttpSuccess = require('connect-lastmile').HttpSuccess,
|
||||
settings = require('../settings.js');
|
||||
|
||||
function getAppAutoupdatePattern(req, res, next) {
|
||||
settings.getAppAutoupdatePattern(function (error, pattern) {
|
||||
function getAutoupdatePattern(req, res, next) {
|
||||
settings.getAutoupdatePattern(function (error, pattern) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, { pattern: pattern }));
|
||||
});
|
||||
}
|
||||
|
||||
function setAppAutoupdatePattern(req, res, next) {
|
||||
function setAutoupdatePattern(req, res, next) {
|
||||
assert.strictEqual(typeof req.body, 'object');
|
||||
|
||||
if (typeof req.body.pattern !== 'string') return next(new HttpError(400, 'pattern is required'));
|
||||
|
||||
settings.setAppAutoupdatePattern(req.body.pattern, function (error) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, {}));
|
||||
});
|
||||
}
|
||||
|
||||
function getBoxAutoupdatePattern(req, res, next) {
|
||||
settings.getBoxAutoupdatePattern(function (error, pattern) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, { pattern: pattern }));
|
||||
});
|
||||
}
|
||||
|
||||
function setBoxAutoupdatePattern(req, res, next) {
|
||||
assert.strictEqual(typeof req.body, 'object');
|
||||
|
||||
if (typeof req.body.pattern !== 'string') return next(new HttpError(400, 'pattern is required'));
|
||||
|
||||
settings.setBoxAutoupdatePattern(req.body.pattern, function (error) {
|
||||
settings.setAutoupdatePattern(req.body.pattern, function (error) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, {}));
|
||||
@@ -305,8 +285,7 @@ function get(req, res, next) {
|
||||
case settings.REGISTRY_CONFIG_KEY: return getRegistryConfig(req, res, next);
|
||||
case settings.SYSINFO_CONFIG_KEY: return getSysinfoConfig(req, res, next);
|
||||
|
||||
case settings.APP_AUTOUPDATE_PATTERN_KEY: return getAppAutoupdatePattern(req, res, next);
|
||||
case settings.BOX_AUTOUPDATE_PATTERN_KEY: return getBoxAutoupdatePattern(req, res, next);
|
||||
case settings.AUTOUPDATE_PATTERN_KEY: return getAutoupdatePattern(req, res, next);
|
||||
case settings.TIME_ZONE_KEY: return getTimeZone(req, res, next);
|
||||
|
||||
case settings.DIRECTORY_CONFIG_KEY: return getDirectoryConfig(req, res, next);
|
||||
@@ -327,8 +306,7 @@ function set(req, res, next) {
|
||||
case settings.REGISTRY_CONFIG_KEY: return setRegistryConfig(req, res, next);
|
||||
case settings.SYSINFO_CONFIG_KEY: return setSysinfoConfig(req, res, next);
|
||||
|
||||
case settings.APP_AUTOUPDATE_PATTERN_KEY: return setAppAutoupdatePattern(req, res, next);
|
||||
case settings.BOX_AUTOUPDATE_PATTERN_KEY: return setBoxAutoupdatePattern(req, res, next);
|
||||
case settings.AUTOUPDATE_PATTERN_KEY: return setAutoupdatePattern(req, res, next);
|
||||
case settings.TIME_ZONE_KEY: return setTimeZone(req, res, next);
|
||||
|
||||
case settings.DIRECTORY_CONFIG_KEY: return setDirectoryConfig(req, res, next);
|
||||
|
||||
@@ -58,9 +58,9 @@ describe('Settings API', function () {
|
||||
before(setup);
|
||||
after(cleanup);
|
||||
|
||||
describe('app_autoupdate_pattern', function () {
|
||||
describe('autoupdate_pattern', function () {
|
||||
it('can get app auto update pattern (default)', function (done) {
|
||||
superagent.get(SERVER_URL + '/api/v1/settings/app_autoupdate_pattern')
|
||||
superagent.get(SERVER_URL + '/api/v1/settings/autoupdate_pattern')
|
||||
.query({ access_token: token })
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(200);
|
||||
@@ -69,8 +69,8 @@ describe('Settings API', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot set app_autoupdate_pattern without pattern', function (done) {
|
||||
superagent.post(SERVER_URL + '/api/v1/settings/app_autoupdate_pattern')
|
||||
it('cannot set autoupdate_pattern without pattern', function (done) {
|
||||
superagent.post(SERVER_URL + '/api/v1/settings/autoupdate_pattern')
|
||||
.query({ access_token: token })
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(400);
|
||||
@@ -78,8 +78,8 @@ describe('Settings API', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('can set app_autoupdate_pattern', function (done) {
|
||||
superagent.post(SERVER_URL + '/api/v1/settings/app_autoupdate_pattern')
|
||||
it('can set autoupdate_pattern', function (done) {
|
||||
superagent.post(SERVER_URL + '/api/v1/settings/autoupdate_pattern')
|
||||
.query({ access_token: token })
|
||||
.send({ pattern: '00 30 11 * * 1-5' })
|
||||
.end(function (err, res) {
|
||||
@@ -88,8 +88,8 @@ describe('Settings API', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('can get app auto update pattern', function (done) {
|
||||
superagent.get(SERVER_URL + '/api/v1/settings/app_autoupdate_pattern')
|
||||
it('can get auto update pattern', function (done) {
|
||||
superagent.get(SERVER_URL + '/api/v1/settings/autoupdate_pattern')
|
||||
.query({ access_token: token })
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(200);
|
||||
@@ -98,8 +98,8 @@ describe('Settings API', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('can set app_autoupdate_pattern to never', function (done) {
|
||||
superagent.post(SERVER_URL + '/api/v1/settings/app_autoupdate_pattern')
|
||||
it('can set autoupdate_pattern to never', function (done) {
|
||||
superagent.post(SERVER_URL + '/api/v1/settings/autoupdate_pattern')
|
||||
.query({ access_token: token })
|
||||
.send({ pattern: constants.AUTOUPDATE_PATTERN_NEVER })
|
||||
.end(function (err, res) {
|
||||
@@ -108,8 +108,8 @@ describe('Settings API', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('can get app auto update pattern', function (done) {
|
||||
superagent.get(SERVER_URL + '/api/v1/settings/app_autoupdate_pattern')
|
||||
it('can get auto update pattern', function (done) {
|
||||
superagent.get(SERVER_URL + '/api/v1/settings/autoupdate_pattern')
|
||||
.query({ access_token: token })
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(200);
|
||||
@@ -118,79 +118,8 @@ describe('Settings API', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot set invalid app_autoupdate_pattern', function (done) {
|
||||
superagent.post(SERVER_URL + '/api/v1/settings/app_autoupdate_pattern')
|
||||
.query({ access_token: token })
|
||||
.send({ pattern: '1 3 x 5 6' })
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(400);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('box_autoupdate_pattern', function () {
|
||||
it('can get app auto update pattern (default)', function (done) {
|
||||
superagent.get(SERVER_URL + '/api/v1/settings/box_autoupdate_pattern')
|
||||
.query({ access_token: token })
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(200);
|
||||
expect(res.body.pattern).to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot set box_autoupdate_pattern without pattern', function (done) {
|
||||
superagent.post(SERVER_URL + '/api/v1/settings/box_autoupdate_pattern')
|
||||
.query({ access_token: token })
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(400);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('can set box_autoupdate_pattern', function (done) {
|
||||
superagent.post(SERVER_URL + '/api/v1/settings/box_autoupdate_pattern')
|
||||
.query({ access_token: token })
|
||||
.send({ pattern: '00 30 11 * * 1-5' })
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(200);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('can get app auto update pattern', function (done) {
|
||||
superagent.get(SERVER_URL + '/api/v1/settings/box_autoupdate_pattern')
|
||||
.query({ access_token: token })
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(200);
|
||||
expect(res.body.pattern).to.be('00 30 11 * * 1-5');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('can set box_autoupdate_pattern to never', function (done) {
|
||||
superagent.post(SERVER_URL + '/api/v1/settings/box_autoupdate_pattern')
|
||||
.query({ access_token: token })
|
||||
.send({ pattern: constants.AUTOUPDATE_PATTERN_NEVER })
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(200);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('can get app auto update pattern', function (done) {
|
||||
superagent.get(SERVER_URL + '/api/v1/settings/box_autoupdate_pattern')
|
||||
.query({ access_token: token })
|
||||
.end(function (err, res) {
|
||||
expect(res.statusCode).to.equal(200);
|
||||
expect(res.body.pattern).to.be(constants.AUTOUPDATE_PATTERN_NEVER);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot set invalid box_autoupdate_pattern', function (done) {
|
||||
superagent.post(SERVER_URL + '/api/v1/settings/box_autoupdate_pattern')
|
||||
it('cannot set invalid autoupdate_pattern', function (done) {
|
||||
superagent.post(SERVER_URL + '/api/v1/settings/autoupdate_pattern')
|
||||
.query({ access_token: token })
|
||||
.send({ pattern: '1 3 x 5 6' })
|
||||
.end(function (err, res) {
|
||||
|
||||
Reference in New Issue
Block a user