Files
cloudron-box/src/test/updatechecker-test.js

130 lines
5.3 KiB
JavaScript
Raw Normal View History

2016-01-23 15:57:56 -08:00
/* global it:false */
/* global describe:false */
/* global before:false */
/* global after:false */
'use strict';
2021-06-03 12:20:44 -07:00
const common = require('./common.js'),
2017-01-27 09:40:46 -08:00
constants = require('../constants.js'),
2016-01-23 15:57:56 -08:00
expect = require('expect.js'),
nock = require('nock'),
2017-02-06 16:33:55 -08:00
paths = require('../paths.js'),
safe = require('safetydance'),
semver = require('semver'),
updatechecker = require('../updatechecker.js'),
updater = require('../updater.js');
2016-01-23 15:57:56 -08:00
const UPDATE_VERSION = semver.inc(constants.VERSION, 'major');
2021-06-03 12:20:44 -07:00
describe('updatechecker', function () {
2021-08-13 10:41:10 -07:00
const { setup, cleanup, app, appstoreToken, mockApiServerOrigin } = common;
before(setup);
after(cleanup);
2021-06-03 12:20:44 -07:00
describe('box', function () {
2021-08-19 13:24:38 -07:00
before(async function () {
2021-06-03 12:20:44 -07:00
safe.fs.unlinkSync(paths.UPDATE_CHECKER_FILE);
2016-01-23 15:57:56 -08:00
await updater.setAutoupdatePattern(constants.AUTOUPDATE_PATTERN_NEVER);
2016-01-24 00:06:32 -08:00
});
2021-08-18 15:54:53 -07:00
it('no updates', async function () {
2021-06-03 12:20:44 -07:00
nock.cleanAll();
2021-08-18 15:54:53 -07:00
const scope = nock(mockApiServerOrigin)
2021-06-03 12:20:44 -07:00
.get('/api/v1/boxupdate')
2021-08-13 10:41:10 -07:00
.query({ boxVersion: constants.VERSION, accessToken: appstoreToken, automatic: false })
2021-06-03 12:20:44 -07:00
.reply(204, { } );
2016-04-12 13:15:40 -07:00
2021-08-18 15:54:53 -07:00
await updatechecker.checkForUpdates({ automatic: false });
expect(updatechecker.getUpdateInfo().box).to.not.be.ok();
expect(scope.isDone()).to.be.ok();
2016-01-24 00:06:32 -08:00
});
2021-08-18 15:54:53 -07:00
it('new version', async function () {
2021-06-03 12:20:44 -07:00
nock.cleanAll();
2021-08-18 15:54:53 -07:00
const scope = nock(mockApiServerOrigin)
2021-06-03 12:20:44 -07:00
.get('/api/v1/boxupdate')
2021-08-13 10:41:10 -07:00
.query({ boxVersion: constants.VERSION, accessToken: appstoreToken, automatic: false })
2024-06-03 19:34:22 +02:00
.reply(200, { version: UPDATE_VERSION, changelog: [''], sourceTarballUrl: 'box.tar.gz', sourceTarballSigUrl: 'box.tar.gz.sig', boxVersionsUrl: 'box.versions', boxVersionsSigUrl: 'box.versions.sig', unstable: false } );
2021-06-03 12:20:44 -07:00
2021-08-18 15:54:53 -07:00
await updatechecker.checkForUpdates({ automatic: false });
2024-06-03 19:34:22 +02:00
expect(updatechecker.getUpdateInfo().box).to.be.ok();
2021-08-18 15:54:53 -07:00
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();
});
2021-08-18 15:54:53 -07:00
it('bad response offers whatever was last valid', async function () {
2021-06-03 12:20:44 -07:00
nock.cleanAll();
2021-08-18 15:54:53 -07:00
const scope = nock(mockApiServerOrigin)
2021-06-03 12:20:44 -07:00
.get('/api/v1/boxupdate')
2021-08-13 10:41:10 -07:00
.query({ boxVersion: constants.VERSION, accessToken: appstoreToken, automatic: false })
2021-06-03 12:20:44 -07:00
.reply(404, { version: '2.0.0-pre.0', changelog: [''], sourceTarballUrl: 'box-pre.tar.gz' } );
2021-08-18 15:54:53 -07:00
await updatechecker.checkForUpdates({ automatic: 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();
2021-06-03 12:20:44 -07:00
});
2016-01-24 00:44:46 -08:00
});
2021-06-03 12:20:44 -07:00
describe('app', function () {
2021-08-19 13:24:38 -07:00
before(async function () {
2021-06-03 12:20:44 -07:00
safe.fs.unlinkSync(paths.UPDATE_CHECKER_FILE);
2016-01-24 00:44:46 -08:00
await updater.setAutoupdatePattern(constants.AUTOUPDATE_PATTERN_NEVER);
2021-06-03 12:20:44 -07:00
});
2016-01-24 00:44:46 -08:00
2021-08-18 15:54:53 -07:00
it('no updates', async function () {
2021-06-03 12:20:44 -07:00
nock.cleanAll();
2016-01-24 00:44:46 -08:00
2021-08-18 15:54:53 -07:00
const scope = nock(mockApiServerOrigin)
2021-06-03 12:20:44 -07:00
.get('/api/v1/appupdate')
2021-08-13 10:41:10 -07:00
.query({ boxVersion: constants.VERSION, accessToken: appstoreToken, appId: app.appStoreId, appVersion: app.manifest.version, automatic: false })
2021-06-03 12:20:44 -07:00
.reply(204, { } );
2017-01-27 09:40:46 -08:00
2021-08-18 15:54:53 -07:00
await updatechecker._checkAppUpdates({ automatic: false });
expect(updatechecker.getUpdateInfo()).to.eql({});
expect(scope.isDone()).to.be.ok();
2016-01-24 00:44:46 -08:00
});
2021-08-18 15:54:53 -07:00
it('bad response', async function () {
2021-06-03 12:20:44 -07:00
nock.cleanAll();
2016-01-24 00:44:46 -08:00
2021-08-18 15:54:53 -07:00
const scope = nock(mockApiServerOrigin)
2021-06-03 12:20:44 -07:00
.get('/api/v1/appupdate')
2021-08-13 10:41:10 -07:00
.query({ boxVersion: constants.VERSION, accessToken: appstoreToken, appId: app.appStoreId, appVersion: app.manifest.version, automatic: false })
2021-06-03 12:20:44 -07:00
.reply(500, { update: { manifest: { version: '1.0.0', changelog: '* some changes' } } } );
2017-01-27 09:40:46 -08:00
2021-08-18 15:54:53 -07:00
await updatechecker._checkAppUpdates({ automatic: false });
expect(updatechecker.getUpdateInfo()).to.eql({});
expect(scope.isDone()).to.be.ok();
2016-01-24 00:44:46 -08:00
});
2021-08-18 15:54:53 -07:00
it('offers new version', async function () {
2021-06-03 12:20:44 -07:00
nock.cleanAll();
2016-01-24 00:44:46 -08:00
2021-08-18 15:54:53 -07:00
const scope = nock(mockApiServerOrigin)
2021-06-03 12:20:44 -07:00
.get('/api/v1/appupdate')
2021-08-13 10:41:10 -07:00
.query({ boxVersion: constants.VERSION, accessToken: appstoreToken, appId: app.appStoreId, appVersion: app.manifest.version, automatic: false })
2021-06-03 12:20:44 -07:00
.reply(200, { manifest: { version: '2.0.0', changelog: '* some changes' } } );
2017-01-27 09:40:46 -08:00
2021-08-18 15:54:53 -07:00
await updatechecker._checkAppUpdates({ automatic: false });
expect(updatechecker.getUpdateInfo()).to.eql({ 'appid': { manifest: { version: '2.0.0', changelog: '* some changes' }, unstable: false } });
expect(scope.isDone()).to.be.ok();
2016-01-24 00:44:46 -08:00
});
2021-08-18 15:54:53 -07:00
it('does not offer old version', async function () {
2021-06-03 12:20:44 -07:00
nock.cleanAll();
2016-01-24 00:44:46 -08:00
2021-08-18 15:54:53 -07:00
await updatechecker._checkAppUpdates({ automatic: false });
expect(updatechecker.getUpdateInfo()).to.eql({ });
2016-01-24 00:44:46 -08:00
});
});
});