merge updatechecker into updater
This commit is contained in:
@@ -1,130 +0,0 @@
|
||||
/* global it:false */
|
||||
/* global describe:false */
|
||||
/* global before:false */
|
||||
/* global after:false */
|
||||
|
||||
'use strict';
|
||||
|
||||
const common = require('./common.js'),
|
||||
constants = require('../constants.js'),
|
||||
expect = require('expect.js'),
|
||||
nock = require('nock'),
|
||||
paths = require('../paths.js'),
|
||||
safe = require('safetydance'),
|
||||
semver = require('semver'),
|
||||
updatechecker = require('../updatechecker.js'),
|
||||
updater = require('../updater.js');
|
||||
|
||||
const UPDATE_VERSION = semver.inc(constants.VERSION, 'major');
|
||||
|
||||
describe('updatechecker', function () {
|
||||
const { setup, cleanup, app, appstoreToken, mockApiServerOrigin } = common;
|
||||
|
||||
before(setup);
|
||||
before(() => { if (!nock.isActive()) nock.activate(); });
|
||||
after(cleanup);
|
||||
|
||||
describe('box', function () {
|
||||
before(async function () {
|
||||
safe.fs.unlinkSync(paths.UPDATE_CHECKER_FILE);
|
||||
|
||||
await updater.setAutoupdatePattern(constants.AUTOUPDATE_PATTERN_NEVER);
|
||||
});
|
||||
|
||||
it('no updates', async function () {
|
||||
nock.cleanAll();
|
||||
|
||||
const scope = nock(mockApiServerOrigin)
|
||||
.get('/api/v1/boxupdate')
|
||||
.query({ boxVersion: constants.VERSION, accessToken: appstoreToken, stableOnly: false })
|
||||
.reply(204, { } );
|
||||
|
||||
await updatechecker.checkForUpdates({ stableOnly: false });
|
||||
expect(updatechecker.getUpdateInfo().box).to.not.be.ok();
|
||||
expect(scope.isDone()).to.be.ok();
|
||||
});
|
||||
|
||||
it('new version', async function () {
|
||||
nock.cleanAll();
|
||||
|
||||
const scope = nock(mockApiServerOrigin)
|
||||
.get('/api/v1/boxupdate')
|
||||
.query({ boxVersion: constants.VERSION, accessToken: appstoreToken, stableOnly: false })
|
||||
.reply(200, { version: UPDATE_VERSION, changelog: [''], sourceTarballUrl: 'box.tar.gz', sourceTarballSigUrl: 'box.tar.gz.sig', boxVersionsUrl: 'box.versions', boxVersionsSigUrl: 'box.versions.sig', unstable: false } );
|
||||
|
||||
await updatechecker.checkForUpdates({ stableOnly: false });
|
||||
expect(updatechecker.getUpdateInfo().box).to.be.ok();
|
||||
expect(updatechecker.getUpdateInfo().box.version).to.be(UPDATE_VERSION);
|
||||
expect(updatechecker.getUpdateInfo().box.sourceTarballUrl).to.be('box.tar.gz');
|
||||
expect(scope.isDone()).to.be.ok();
|
||||
});
|
||||
|
||||
it('bad response offers whatever was last valid', async function () {
|
||||
nock.cleanAll();
|
||||
|
||||
const scope = nock(mockApiServerOrigin)
|
||||
.get('/api/v1/boxupdate')
|
||||
.query({ boxVersion: constants.VERSION, accessToken: appstoreToken, stableOnly: false })
|
||||
.reply(404, { version: '2.0.0-pre.0', changelog: [''], sourceTarballUrl: 'box-pre.tar.gz' } );
|
||||
|
||||
await updatechecker.checkForUpdates({ stableOnly: false });
|
||||
expect(updatechecker.getUpdateInfo().box.version).to.be(UPDATE_VERSION);
|
||||
expect(updatechecker.getUpdateInfo().box.sourceTarballUrl).to.be('box.tar.gz');
|
||||
expect(scope.isDone()).to.be.ok();
|
||||
});
|
||||
});
|
||||
|
||||
describe('app', function () {
|
||||
before(async function () {
|
||||
safe.fs.unlinkSync(paths.UPDATE_CHECKER_FILE);
|
||||
|
||||
await updater.setAutoupdatePattern(constants.AUTOUPDATE_PATTERN_NEVER);
|
||||
});
|
||||
|
||||
it('no updates', async function () {
|
||||
nock.cleanAll();
|
||||
|
||||
const scope = nock(mockApiServerOrigin)
|
||||
.get('/api/v1/appupdate')
|
||||
.query({ boxVersion: constants.VERSION, accessToken: appstoreToken, appId: app.appStoreId, appVersion: app.manifest.version, stableOnly: false })
|
||||
.reply(204, { } );
|
||||
|
||||
await updatechecker._checkAppUpdates({ stableOnly: false });
|
||||
expect(updatechecker.getUpdateInfo()).to.eql({});
|
||||
expect(scope.isDone()).to.be.ok();
|
||||
});
|
||||
|
||||
it('bad response', async function () {
|
||||
nock.cleanAll();
|
||||
|
||||
const scope = nock(mockApiServerOrigin)
|
||||
.get('/api/v1/appupdate')
|
||||
.query({ boxVersion: constants.VERSION, accessToken: appstoreToken, appId: app.appStoreId, appVersion: app.manifest.version, stableOnly: false })
|
||||
.reply(500, { update: { manifest: { version: '1.0.0', changelog: '* some changes' } } } );
|
||||
|
||||
await updatechecker._checkAppUpdates({ stableOnly: false });
|
||||
expect(updatechecker.getUpdateInfo()).to.eql({});
|
||||
expect(scope.isDone()).to.be.ok();
|
||||
});
|
||||
|
||||
it('offers new version', async function () {
|
||||
nock.cleanAll();
|
||||
|
||||
const scope = nock(mockApiServerOrigin)
|
||||
.get('/api/v1/appupdate')
|
||||
.query({ boxVersion: constants.VERSION, accessToken: appstoreToken, appId: app.appStoreId, appVersion: app.manifest.version, stableOnly: false })
|
||||
.reply(200, { manifest: { version: '2.0.0', changelog: '* some changes' } } );
|
||||
|
||||
await updatechecker._checkAppUpdates({ stableOnly: false });
|
||||
expect(updatechecker.getUpdateInfo()).to.eql({ 'appid': { manifest: { version: '2.0.0', changelog: '* some changes' }, unstable: false } });
|
||||
expect(scope.isDone()).to.be.ok();
|
||||
});
|
||||
|
||||
it('does not offer old version', async function () {
|
||||
nock.cleanAll();
|
||||
|
||||
await updatechecker._checkAppUpdates({ stableOnly: false });
|
||||
expect(updatechecker.getUpdateInfo()).to.eql({ });
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -7,27 +7,145 @@
|
||||
|
||||
const BoxError = require('../boxerror.js'),
|
||||
common = require('./common.js'),
|
||||
constants = require('../constants.js'),
|
||||
expect = require('expect.js'),
|
||||
nock = require('nock'),
|
||||
paths = require('../paths.js'),
|
||||
safe = require('safetydance'),
|
||||
semver = require('semver'),
|
||||
updater = require('../updater.js');
|
||||
|
||||
const UPDATE_VERSION = semver.inc(constants.VERSION, 'major');
|
||||
|
||||
describe('updater', function () {
|
||||
const { setup, cleanup } = common;
|
||||
const { setup, cleanup, app, appstoreToken, mockApiServerOrigin } = common;
|
||||
|
||||
before(setup);
|
||||
after(cleanup);
|
||||
describe('settings', function () {
|
||||
before(setup);
|
||||
after(cleanup);
|
||||
|
||||
it('can get default autoupdate_pattern', async function () {
|
||||
const pattern = await updater.getAutoupdatePattern();
|
||||
expect(pattern).to.be('00 00 1,3,5,23 * * *');
|
||||
it('can get default autoupdate_pattern', async function () {
|
||||
const pattern = await updater.getAutoupdatePattern();
|
||||
expect(pattern).to.be('00 00 1,3,5,23 * * *');
|
||||
});
|
||||
|
||||
it('cannot set invalid autoupdate_pattern', async function () {
|
||||
const [error] = await safe(updater.setAutoupdatePattern('02 * 1 *'));
|
||||
expect(error.reason).to.be(BoxError.BAD_FIELD);
|
||||
});
|
||||
|
||||
it('can set default autoupdate_pattern', async function () {
|
||||
await updater.setAutoupdatePattern('02 * 1-5 * * *');
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot set invalid autoupdate_pattern', async function () {
|
||||
const [error] = await safe(updater.setAutoupdatePattern('02 * 1 *'));
|
||||
expect(error.reason).to.be(BoxError.BAD_FIELD);
|
||||
});
|
||||
describe('checker', function () {
|
||||
before(setup);
|
||||
before(() => { if (!nock.isActive()) nock.activate(); });
|
||||
after(cleanup);
|
||||
|
||||
it('can set default autoupdate_pattern', async function () {
|
||||
await updater.setAutoupdatePattern('02 * 1-5 * * *');
|
||||
describe('box updates', function () {
|
||||
before(async function () {
|
||||
safe.fs.unlinkSync(paths.UPDATE_CHECKER_FILE);
|
||||
|
||||
await updater.setAutoupdatePattern(constants.AUTOUPDATE_PATTERN_NEVER);
|
||||
});
|
||||
|
||||
it('no updates', async function () {
|
||||
nock.cleanAll();
|
||||
|
||||
const scope = nock(mockApiServerOrigin)
|
||||
.get('/api/v1/boxupdate')
|
||||
.query({ boxVersion: constants.VERSION, accessToken: appstoreToken, stableOnly: false })
|
||||
.reply(204, { } );
|
||||
|
||||
await updater.checkForUpdates({ stableOnly: false });
|
||||
expect(updater.getUpdateInfoSync().box).to.not.be.ok();
|
||||
expect(scope.isDone()).to.be.ok();
|
||||
});
|
||||
|
||||
it('new version', async function () {
|
||||
nock.cleanAll();
|
||||
|
||||
const scope = nock(mockApiServerOrigin)
|
||||
.get('/api/v1/boxupdate')
|
||||
.query({ boxVersion: constants.VERSION, accessToken: appstoreToken, stableOnly: false })
|
||||
.reply(200, { version: UPDATE_VERSION, changelog: [''], sourceTarballUrl: 'box.tar.gz', sourceTarballSigUrl: 'box.tar.gz.sig', boxVersionsUrl: 'box.versions', boxVersionsSigUrl: 'box.versions.sig', unstable: false } );
|
||||
|
||||
await updater.checkForUpdates({ stableOnly: false });
|
||||
expect(updater.getUpdateInfoSync().box).to.be.ok();
|
||||
expect(updater.getUpdateInfoSync().box.version).to.be(UPDATE_VERSION);
|
||||
expect(updater.getUpdateInfoSync().box.sourceTarballUrl).to.be('box.tar.gz');
|
||||
expect(scope.isDone()).to.be.ok();
|
||||
});
|
||||
|
||||
it('bad response offers whatever was last valid', async function () {
|
||||
nock.cleanAll();
|
||||
|
||||
const scope = nock(mockApiServerOrigin)
|
||||
.get('/api/v1/boxupdate')
|
||||
.query({ boxVersion: constants.VERSION, accessToken: appstoreToken, stableOnly: false })
|
||||
.reply(404, { version: '2.0.0-pre.0', changelog: [''], sourceTarballUrl: 'box-pre.tar.gz' } );
|
||||
|
||||
await updater.checkForUpdates({ stableOnly: false });
|
||||
expect(updater.getUpdateInfoSync().box.version).to.be(UPDATE_VERSION);
|
||||
expect(updater.getUpdateInfoSync().box.sourceTarballUrl).to.be('box.tar.gz');
|
||||
expect(scope.isDone()).to.be.ok();
|
||||
});
|
||||
});
|
||||
|
||||
describe('app updates', function () {
|
||||
before(async function () {
|
||||
safe.fs.unlinkSync(paths.UPDATE_CHECKER_FILE);
|
||||
|
||||
await updater.setAutoupdatePattern(constants.AUTOUPDATE_PATTERN_NEVER);
|
||||
});
|
||||
|
||||
it('no updates', async function () {
|
||||
nock.cleanAll();
|
||||
|
||||
const scope = nock(mockApiServerOrigin)
|
||||
.get('/api/v1/appupdate')
|
||||
.query({ boxVersion: constants.VERSION, accessToken: appstoreToken, appId: app.appStoreId, appVersion: app.manifest.version, stableOnly: false })
|
||||
.reply(204, { } );
|
||||
|
||||
await updater._checkAppUpdates({ stableOnly: false });
|
||||
expect(updater.getUpdateInfoSync()).to.eql({});
|
||||
expect(scope.isDone()).to.be.ok();
|
||||
});
|
||||
|
||||
it('bad response', async function () {
|
||||
nock.cleanAll();
|
||||
|
||||
const scope = nock(mockApiServerOrigin)
|
||||
.get('/api/v1/appupdate')
|
||||
.query({ boxVersion: constants.VERSION, accessToken: appstoreToken, appId: app.appStoreId, appVersion: app.manifest.version, stableOnly: false })
|
||||
.reply(500, { update: { manifest: { version: '1.0.0', changelog: '* some changes' } } } );
|
||||
|
||||
await updater._checkAppUpdates({ stableOnly: false });
|
||||
expect(updater.getUpdateInfoSync()).to.eql({});
|
||||
expect(scope.isDone()).to.be.ok();
|
||||
});
|
||||
|
||||
it('offers new version', async function () {
|
||||
nock.cleanAll();
|
||||
|
||||
const scope = nock(mockApiServerOrigin)
|
||||
.get('/api/v1/appupdate')
|
||||
.query({ boxVersion: constants.VERSION, accessToken: appstoreToken, appId: app.appStoreId, appVersion: app.manifest.version, stableOnly: false })
|
||||
.reply(200, { manifest: { version: '2.0.0', changelog: '* some changes' } } );
|
||||
|
||||
await updater._checkAppUpdates({ stableOnly: false });
|
||||
expect(updater.getUpdateInfoSync()).to.eql({ 'appid': { manifest: { version: '2.0.0', changelog: '* some changes' }, unstable: false } });
|
||||
expect(scope.isDone()).to.be.ok();
|
||||
});
|
||||
|
||||
it('does not offer old version', async function () {
|
||||
nock.cleanAll();
|
||||
|
||||
await updater._checkAppUpdates({ stableOnly: false });
|
||||
expect(updater.getUpdateInfoSync()).to.eql({ });
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user