update: add policy to update apps separately from platform
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { describe, it, before, after } from 'mocha';
|
||||
import common from './common.js';
|
||||
import constants from '../../constants.js';
|
||||
import assert from 'node:assert/strict';
|
||||
import superagent from '@cloudron/superagent';
|
||||
import updater from '../../updater.js';
|
||||
|
||||
|
||||
describe('Updater API', function () {
|
||||
@@ -11,53 +11,72 @@ describe('Updater API', function () {
|
||||
before(setup);
|
||||
after(cleanup);
|
||||
|
||||
describe('autoupdate_pattern', function () {
|
||||
it('can get app auto update pattern (default)', async function () {
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/updater/autoupdate_pattern`)
|
||||
describe('autoupdate_config', function () {
|
||||
it('can get autoupdate config (default)', async function () {
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/updater/autoupdate_config`)
|
||||
.query({ access_token: owner.token });
|
||||
assert.equal(response.status, 200);
|
||||
assert.ok(response.body.pattern);
|
||||
assert.ok(response.body.schedule);
|
||||
assert.ok(response.body.policy);
|
||||
});
|
||||
|
||||
it('cannot set autoupdate_pattern without pattern', async function () {
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/updater/autoupdate_pattern`)
|
||||
it('cannot set autoupdate_config without schedule', async function () {
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/updater/autoupdate_config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send({ policy: updater.AUTOUPDATE_POLICY_PLATFORM_AND_APPS })
|
||||
.ok(() => true);
|
||||
assert.equal(response.status, 400);
|
||||
});
|
||||
|
||||
it('can set autoupdate_pattern', async function () {
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/updater/autoupdate_pattern`)
|
||||
it('cannot set autoupdate_config without policy', async function () {
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/updater/autoupdate_config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send({ pattern: '00 30 11 * * 1-5' });
|
||||
.send({ schedule: '00 30 11 * * 1-5' })
|
||||
.ok(() => true);
|
||||
assert.equal(response.status, 400);
|
||||
});
|
||||
|
||||
it('can set autoupdate_config', async function () {
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/updater/autoupdate_config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send({ schedule: '00 30 11 * * 1-5', policy: updater.AUTOUPDATE_POLICY_APPS_ONLY });
|
||||
assert.equal(response.status, 200);
|
||||
});
|
||||
|
||||
it('can get auto update pattern', async function () {
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/updater/autoupdate_pattern`)
|
||||
it('can get autoupdate config after set', async function () {
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/updater/autoupdate_config`)
|
||||
.query({ access_token: owner.token });
|
||||
assert.equal(response.status, 200);
|
||||
assert.equal(response.body.pattern, '00 30 11 * * 1-5');
|
||||
assert.equal(response.body.schedule, '00 30 11 * * 1-5');
|
||||
assert.equal(response.body.policy, updater.AUTOUPDATE_POLICY_APPS_ONLY);
|
||||
});
|
||||
|
||||
it('can set autoupdate_pattern to never', async function () {
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/updater/autoupdate_pattern`)
|
||||
it('can set autoupdate policy to never', async function () {
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/updater/autoupdate_config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send({ pattern: constants.CRON_PATTERN_NEVER });
|
||||
.send({ schedule: '00 30 11 * * 1-5', policy: updater.AUTOUPDATE_POLICY_NEVER });
|
||||
assert.equal(response.status, 200);
|
||||
});
|
||||
|
||||
it('can get auto update pattern', async function () {
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/updater/autoupdate_pattern`)
|
||||
it('can get autoupdate config with never policy', async function () {
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/updater/autoupdate_config`)
|
||||
.query({ access_token: owner.token });
|
||||
assert.equal(response.status, 200);
|
||||
assert.equal(response.body.pattern, constants.CRON_PATTERN_NEVER);
|
||||
assert.equal(response.body.policy, updater.AUTOUPDATE_POLICY_NEVER);
|
||||
});
|
||||
|
||||
it('cannot set invalid autoupdate_pattern', async function () {
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/updater/autoupdate_pattern`)
|
||||
it('cannot set invalid autoupdate schedule', async function () {
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/updater/autoupdate_config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send({ pattern: '1 3 x 5 6' })
|
||||
.send({ schedule: '1 3 x 5 6', policy: updater.AUTOUPDATE_POLICY_PLATFORM_AND_APPS })
|
||||
.ok(() => true);
|
||||
assert.equal(response.status, 400);
|
||||
});
|
||||
|
||||
it('cannot set invalid autoupdate policy', async function () {
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/updater/autoupdate_config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send({ schedule: '00 30 11 * * 1-5', policy: 'invalid_policy' })
|
||||
.ok(() => true);
|
||||
assert.equal(response.status, 400);
|
||||
});
|
||||
|
||||
@@ -6,20 +6,20 @@ import { HttpSuccess } from '@cloudron/connect-lastmile';
|
||||
import safe from 'safetydance';
|
||||
import updater from '../updater.js';
|
||||
|
||||
|
||||
async function getAutoupdatePattern(req, res, next) {
|
||||
const [error, pattern] = await safe(updater.getAutoupdatePattern());
|
||||
async function getAutoupdateConfig(req, res, next) {
|
||||
const [error, config] = await safe(updater.getAutoupdateConfig());
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, { pattern }));
|
||||
next(new HttpSuccess(200, config));
|
||||
}
|
||||
|
||||
async function setAutoupdatePattern(req, res, next) {
|
||||
async function setAutoupdateConfig(req, res, next) {
|
||||
assert.strictEqual(typeof req.body, 'object');
|
||||
|
||||
if (typeof req.body.pattern !== 'string') return next(new HttpError(400, 'pattern is required'));
|
||||
if (typeof req.body.schedule !== 'string') return next(new HttpError(400, 'schedule is required'));
|
||||
if (typeof req.body.policy !== 'string') return next(new HttpError(400, 'policy is required'));
|
||||
|
||||
const [error] = await safe(updater.setAutoupdatePattern(req.body.pattern));
|
||||
const [error] = await safe(updater.setAutoupdateConfig(req.body));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, {}));
|
||||
@@ -54,8 +54,8 @@ async function checkBoxUpdate(req, res, next) {
|
||||
}
|
||||
|
||||
export default {
|
||||
getAutoupdatePattern,
|
||||
setAutoupdatePattern,
|
||||
getAutoupdateConfig,
|
||||
setAutoupdateConfig,
|
||||
|
||||
getBoxUpdate,
|
||||
checkBoxUpdate,
|
||||
|
||||
Reference in New Issue
Block a user