updateInfo: move updateInfo into apps table
this has many advantages: * easy to deliver the updateInfo via the apps object * after updating, the task can clear it * when apps are deleted, the info is automatically gone otherwise, it's a mess of deps between apps/updater/apptask/rest routes box update info is still in a file
This commit is contained in:
+48
-21
@@ -5,7 +5,8 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const BoxError = require('../boxerror.js'),
|
||||
const apps = require('../apps.js'),
|
||||
BoxError = require('../boxerror.js'),
|
||||
common = require('./common.js'),
|
||||
constants = require('../constants.js'),
|
||||
expect = require('expect.js'),
|
||||
@@ -46,7 +47,7 @@ describe('updater', function () {
|
||||
|
||||
describe('box updates', function () {
|
||||
before(async function () {
|
||||
safe.fs.unlinkSync(paths.UPDATE_CHECKER_FILE);
|
||||
safe.fs.unlinkSync(paths.BOX_UPDATE_FILE);
|
||||
|
||||
await updater.setAutoupdatePattern(constants.AUTOUPDATE_PATTERN_NEVER);
|
||||
});
|
||||
@@ -59,8 +60,9 @@ describe('updater', function () {
|
||||
.query({ boxVersion: constants.VERSION, accessToken: appstoreToken, stableOnly: false })
|
||||
.reply(204, { } );
|
||||
|
||||
await updater.checkForUpdates({ stableOnly: false });
|
||||
expect(updater.getUpdateInfoSync().box).to.not.be.ok();
|
||||
await updater.checkBoxUpdate({ stableOnly: false });
|
||||
const boxUpdateInfo = await updater.getBoxUpdate();
|
||||
expect(boxUpdateInfo).to.be(null);
|
||||
expect(scope.isDone()).to.be.ok();
|
||||
});
|
||||
|
||||
@@ -72,10 +74,12 @@ describe('updater', function () {
|
||||
.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');
|
||||
await updater.checkBoxUpdate({ stableOnly: false });
|
||||
const boxUpdateInfo = await updater.getBoxUpdate();
|
||||
|
||||
expect(boxUpdateInfo).to.be.ok();
|
||||
expect(boxUpdateInfo.version).to.be(UPDATE_VERSION);
|
||||
expect(boxUpdateInfo.sourceTarballUrl).to.be('box.tar.gz');
|
||||
expect(scope.isDone()).to.be.ok();
|
||||
});
|
||||
|
||||
@@ -87,17 +91,17 @@ describe('updater', function () {
|
||||
.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');
|
||||
await safe(updater.checkBoxUpdate({ stableOnly: false })); // ignore error
|
||||
const boxUpdateInfo = await updater.getBoxUpdate();
|
||||
|
||||
expect(boxUpdateInfo.version).to.be(UPDATE_VERSION);
|
||||
expect(boxUpdateInfo.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);
|
||||
});
|
||||
|
||||
@@ -109,9 +113,12 @@ describe('updater', function () {
|
||||
.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({});
|
||||
const appUpdateInfo = await updater.checkAppUpdate(app, { stableOnly: false });
|
||||
expect(appUpdateInfo).to.eql(null);
|
||||
expect(scope.isDone()).to.be.ok();
|
||||
|
||||
const tmp = await apps.get(app.id);
|
||||
expect(tmp.updateInfo).to.be(null);
|
||||
});
|
||||
|
||||
it('bad response', async function () {
|
||||
@@ -122,8 +129,8 @@ describe('updater', function () {
|
||||
.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({});
|
||||
const [error] = await safe(updater.checkAppUpdate(app, { stableOnly: false }));
|
||||
expect(error).to.be.ok();
|
||||
expect(scope.isDone()).to.be.ok();
|
||||
});
|
||||
|
||||
@@ -135,16 +142,36 @@ describe('updater', function () {
|
||||
.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 } });
|
||||
const expectedUpdateInfo = {
|
||||
manifest: { version: '2.0.0', changelog: '* some changes' },
|
||||
unstable: false,
|
||||
isAutoUpdatable: false,
|
||||
manualUpdateReason: 'Invalid or Expired subscription'
|
||||
};
|
||||
|
||||
const appUpdateInfo = await updater.checkAppUpdate(app, { stableOnly: false });
|
||||
expect(appUpdateInfo.manifest).to.eql(expectedUpdateInfo.manifest);
|
||||
expect(scope.isDone()).to.be.ok();
|
||||
|
||||
const tmp = await apps.get(app.id);
|
||||
expect(tmp.updateInfo).to.eql(expectedUpdateInfo);
|
||||
});
|
||||
|
||||
it('does not offer old version', async function () {
|
||||
nock.cleanAll();
|
||||
|
||||
await updater._checkAppUpdates({ stableOnly: false });
|
||||
expect(updater.getUpdateInfoSync()).to.eql({ });
|
||||
const expectedUpdateInfo = {
|
||||
manifest: { version: '2.0.0', changelog: '* some changes' },
|
||||
unstable: false,
|
||||
isAutoUpdatable: false,
|
||||
manualUpdateReason: 'Invalid or Expired subscription'
|
||||
};
|
||||
|
||||
const [error] = await safe(updater.checkAppUpdate(app, { stableOnly: false }));
|
||||
expect(error).to.be.ok();
|
||||
|
||||
const tmp = await apps.get(app.id);
|
||||
expect(tmp.updateInfo).to.eql(expectedUpdateInfo);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user