150 lines
5.9 KiB
JavaScript
150 lines
5.9 KiB
JavaScript
/* 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'),
|
|
settings = require('../settings.js'),
|
|
updatechecker = require('../updatechecker.js');
|
|
|
|
const { APP, APPSTORE_TOKEN, MOCK_API_SERVER_ORIGIN } = common;
|
|
|
|
const UPDATE_VERSION = semver.inc(constants.VERSION, 'major');
|
|
|
|
describe('updatechecker', function () {
|
|
before(common.setup);
|
|
after(common.cleanup);
|
|
|
|
describe('box', function () {
|
|
before(function (done) {
|
|
safe.fs.unlinkSync(paths.UPDATE_CHECKER_FILE);
|
|
|
|
settings.setAutoupdatePattern(constants.AUTOUPDATE_PATTERN_NEVER, done);
|
|
});
|
|
|
|
it('no updates', function (done) {
|
|
nock.cleanAll();
|
|
|
|
var scope = nock(MOCK_API_SERVER_ORIGIN)
|
|
.get('/api/v1/boxupdate')
|
|
.query({ boxVersion: constants.VERSION, accessToken: APPSTORE_TOKEN, automatic: false })
|
|
.reply(204, { } );
|
|
|
|
updatechecker.checkForUpdates({ automatic: false }, function (error) {
|
|
expect(!error).to.be.ok();
|
|
expect(updatechecker.getUpdateInfo().box).to.not.be.ok();
|
|
expect(scope.isDone()).to.be.ok();
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('new version', function (done) {
|
|
nock.cleanAll();
|
|
|
|
var scope = nock(MOCK_API_SERVER_ORIGIN)
|
|
.get('/api/v1/boxupdate')
|
|
.query({ boxVersion: constants.VERSION, accessToken: APPSTORE_TOKEN, automatic: false })
|
|
.reply(200, { version: UPDATE_VERSION, changelog: [''], sourceTarballUrl: 'box.tar.gz', sourceTarballSigUrl: 'box.tar.gz.sig', boxVersionsUrl: 'box.versions', boxVersionsSigUrl: 'box.versions.sig' } );
|
|
|
|
updatechecker.checkForUpdates({ automatic: false }, function (error) {
|
|
expect(!error).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();
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('bad response offers whatever was last valid', function (done) {
|
|
nock.cleanAll();
|
|
|
|
var scope = nock(MOCK_API_SERVER_ORIGIN)
|
|
.get('/api/v1/boxupdate')
|
|
.query({ boxVersion: constants.VERSION, accessToken: APPSTORE_TOKEN, automatic: false })
|
|
.reply(404, { version: '2.0.0-pre.0', changelog: [''], sourceTarballUrl: 'box-pre.tar.gz' } );
|
|
|
|
updatechecker.checkForUpdates({ automatic: false }, function (error) {
|
|
expect(error).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();
|
|
done();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('app', function () {
|
|
before(function (done) {
|
|
safe.fs.unlinkSync(paths.UPDATE_CHECKER_FILE);
|
|
|
|
settings.setAutoupdatePattern(constants.AUTOUPDATE_PATTERN_NEVER, done);
|
|
});
|
|
|
|
it('no updates', function (done) {
|
|
nock.cleanAll();
|
|
|
|
var scope = nock(MOCK_API_SERVER_ORIGIN)
|
|
.get('/api/v1/appupdate')
|
|
.query({ boxVersion: constants.VERSION, accessToken: APPSTORE_TOKEN, appId: APP.appStoreId, appVersion: APP.manifest.version, automatic: false })
|
|
.reply(204, { } );
|
|
|
|
updatechecker._checkAppUpdates({ automatic: false }, function (error) {
|
|
expect(!error).to.be.ok();
|
|
expect(updatechecker.getUpdateInfo()).to.eql({});
|
|
expect(scope.isDone()).to.be.ok();
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('bad response', function (done) {
|
|
nock.cleanAll();
|
|
|
|
var scope = nock(MOCK_API_SERVER_ORIGIN)
|
|
.get('/api/v1/appupdate')
|
|
.query({ boxVersion: constants.VERSION, accessToken: APPSTORE_TOKEN, appId: APP.appStoreId, appVersion: APP.manifest.version, automatic: false })
|
|
.reply(500, { update: { manifest: { version: '1.0.0', changelog: '* some changes' } } } );
|
|
|
|
updatechecker._checkAppUpdates({ automatic: false }, function (error) {
|
|
expect(!error).to.be.ok();
|
|
expect(updatechecker.getUpdateInfo()).to.eql({});
|
|
expect(scope.isDone()).to.be.ok();
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('offers new version', function (done) {
|
|
nock.cleanAll();
|
|
|
|
var scope = nock(MOCK_API_SERVER_ORIGIN)
|
|
.get('/api/v1/appupdate')
|
|
.query({ boxVersion: constants.VERSION, accessToken: APPSTORE_TOKEN, appId: APP.appStoreId, appVersion: APP.manifest.version, automatic: false })
|
|
.reply(200, { manifest: { version: '2.0.0', changelog: '* some changes' } } );
|
|
|
|
updatechecker._checkAppUpdates({ automatic: false }, function (error) {
|
|
expect(!error).to.be.ok();
|
|
expect(updatechecker.getUpdateInfo()).to.eql({ 'appid': { manifest: { version: '2.0.0', changelog: '* some changes' }, unstable: false } });
|
|
expect(scope.isDone()).to.be.ok();
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('does not offer old version', function (done) {
|
|
nock.cleanAll();
|
|
|
|
updatechecker._checkAppUpdates({ automatic: false }, function (error) {
|
|
expect(!error).to.be.ok();
|
|
expect(updatechecker.getUpdateInfo()).to.eql({ });
|
|
done();
|
|
});
|
|
});
|
|
});
|
|
});
|