diff --git a/src/test/settings-test.js b/src/test/settings-test.js index b7ad338fc..b56d620e7 100644 --- a/src/test/settings-test.js +++ b/src/test/settings-test.js @@ -54,16 +54,8 @@ describe('Settings', function () { }); }); - it('can get default app_autoupdate_pattern', function (done) { - settings.getAppAutoupdatePattern(function (error, pattern) { - expect(error).to.be(null); - expect(pattern).to.be('00 15 1,3,5,23 * * *'); - done(); - }); - }); - - it('can get default box_autoupdate_pattern', function (done) { - settings.getBoxAutoupdatePattern(function (error, pattern) { + it('can get default autoupdate_pattern', function (done) { + settings.getAutoupdatePattern(function (error, pattern) { expect(error).to.be(null); expect(pattern).to.be('00 00 1,3,5,23 * * *'); done(); @@ -119,8 +111,7 @@ describe('Settings', function () { settings.getAll(function (error, allSettings) { expect(error).to.be(null); expect(allSettings[settings.TIME_ZONE_KEY]).to.be.a('string'); - expect(allSettings[settings.APP_AUTOUPDATE_PATTERN_KEY]).to.be.a('string'); - expect(allSettings[settings.BOX_AUTOUPDATE_PATTERN_KEY]).to.be.a('string'); + expect(allSettings[settings.AUTOUPDATE_PATTERN_KEY]).to.be.a('string'); expect(allSettings[settings.CLOUDRON_NAME_KEY]).to.be.a('string'); expect(allSettings[settings.UNSTABLE_APPS_KEY]).to.be.a('boolean'); done(); diff --git a/src/test/updatechecker-test.js b/src/test/updatechecker-test.js index 19b460fb9..0cbdfa72d 100644 --- a/src/test/updatechecker-test.js +++ b/src/test/updatechecker-test.js @@ -33,6 +33,8 @@ var USER_0 = { permissions: null }; +const ADMIN_DOMAIN = 'updatechecker-test.example.com'; + const DOMAIN_0 = { domain: 'example.com', zoneName: 'example.com', @@ -78,11 +80,12 @@ describe('updatechecker - box - manual (email)', function () { database.initialize, database._clear, settings._setApiServerOrigin.bind(null, 'http://localhost:4444'), + settings.setAdminLocation.bind(null, ADMIN_DOMAIN, 'my.' + ADMIN_DOMAIN), cron.startJobs, domains.add.bind(null, DOMAIN_0.domain, DOMAIN_0, AUDIT_SOURCE), settings.setAdminLocation.bind(null, DOMAIN_0.domain, 'my.' + DOMAIN_0.domain), users.createOwner.bind(null, USER_0.username, USER_0.password, USER_0.email, USER_0.displayName, AUDIT_SOURCE), - settings.setBoxAutoupdatePattern.bind(null, constants.AUTOUPDATE_PATTERN_NEVER), + settings.setAutoupdatePattern.bind(null, constants.AUTOUPDATE_PATTERN_NEVER), settingsdb.set.bind(null, settings.CLOUDRON_TOKEN_KEY, 'atoken'), ], done); }); @@ -252,7 +255,7 @@ describe('updatechecker - app - manual (email)', function () { settings.setAdminLocation.bind(null, DOMAIN_0.domain, 'my.' + DOMAIN_0.domain), users.createOwner.bind(null, USER_0.username, USER_0.password, USER_0.email, USER_0.displayName, AUDIT_SOURCE), appdb.add.bind(null, APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.domain, apps._translatePortBindings(APP_0.portBindings, APP_0.manifest), APP_0), - settings.setAppAutoupdatePattern.bind(null, constants.AUTOUPDATE_PATTERN_NEVER), + settings.setAutoupdatePattern.bind(null, constants.AUTOUPDATE_PATTERN_NEVER), settingsdb.set.bind(null, settings.CLOUDRON_TOKEN_KEY, 'atoken'), ], done); }); @@ -267,7 +270,7 @@ describe('updatechecker - app - manual (email)', function () { .query({ boxVersion: constants.VERSION, accessToken: 'atoken', appId: APP_0.appStoreId, appVersion: APP_0.manifest.version, automatic: false }) .reply(204, { } ); - updatechecker.checkAppUpdates({ automatic: false }, function (error) { + updatechecker._checkAppUpdates({ automatic: false }, function (error) { expect(!error).to.be.ok(); expect(updatechecker.getUpdateInfo().apps).to.eql({}); expect(scope.isDone()).to.be.ok(); @@ -284,7 +287,7 @@ describe('updatechecker - app - manual (email)', function () { .query({ boxVersion: constants.VERSION, accessToken: 'atoken', appId: APP_0.appStoreId, appVersion: APP_0.manifest.version, automatic: false }) .reply(500, { update: { manifest: { version: '1.0.0', changelog: '* some changes' } } } ); - updatechecker.checkAppUpdates({ automatic: false }, function (error) { + updatechecker._checkAppUpdates({ automatic: false }, function (error) { expect(!error).to.be.ok(); expect(updatechecker.getUpdateInfo().apps).to.eql({}); expect(scope.isDone()).to.be.ok(); @@ -301,7 +304,7 @@ describe('updatechecker - app - manual (email)', function () { .query({ boxVersion: constants.VERSION, accessToken: 'atoken', appId: APP_0.appStoreId, appVersion: APP_0.manifest.version, automatic: false }) .reply(200, { manifest: { version: '2.0.0', changelog: '* some changes' } } ); - updatechecker.checkAppUpdates({ automatic: false }, function (error) { + updatechecker._checkAppUpdates({ automatic: false }, function (error) { expect(!error).to.be.ok(); expect(updatechecker.getUpdateInfo().apps).to.eql({ 'appid-0': { manifest: { version: '2.0.0', changelog: '* some changes' }, unstable: false } }); expect(scope.isDone()).to.be.ok(); @@ -313,7 +316,7 @@ describe('updatechecker - app - manual (email)', function () { it('does not offer old version', function (done) { nock.cleanAll(); - updatechecker.checkAppUpdates({ automatic: false }, function (error) { + updatechecker._checkAppUpdates({ automatic: false }, function (error) { expect(!error).to.be.ok(); expect(updatechecker.getUpdateInfo().apps).to.eql({ }); checkMails(0, done); @@ -361,7 +364,7 @@ describe('updatechecker - app - automatic (no email)', function () { settings.setAdminLocation.bind(null, DOMAIN_0.domain, 'my.' + DOMAIN_0.domain), users.createOwner.bind(null, USER_0.username, USER_0.password, USER_0.email, USER_0.displayName, AUDIT_SOURCE), appdb.add.bind(null, APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.domain, apps._translatePortBindings(APP_0.portBindings, APP_0.manifest), APP_0), - settings.setAppAutoupdatePattern.bind(null, '00 00 1,3,5,23 * * *'), + settings.setAutoupdatePattern.bind(null, '00 00 1,3,5,23 * * *'), settingsdb.set.bind(null, settings.CLOUDRON_TOKEN_KEY, 'atoken'), ], done); }); @@ -376,7 +379,7 @@ describe('updatechecker - app - automatic (no email)', function () { .query({ boxVersion: constants.VERSION, accessToken: 'atoken', appId: APP_0.appStoreId, appVersion: APP_0.manifest.version, automatic: false }) .reply(200, { manifest: { version: '2.0.0', changelog: 'c' } } ); - updatechecker.checkAppUpdates({ automatic: false }, function (error) { + updatechecker._checkAppUpdates({ automatic: false }, function (error) { expect(!error).to.be.ok(); expect(updatechecker.getUpdateInfo().apps).to.eql({ 'appid-0': { manifest: { version: '2.0.0', changelog: 'c' }, unstable: false } }); expect(scope.isDone()).to.be.ok(); @@ -426,7 +429,7 @@ describe('updatechecker - app - automatic free (email)', function () { settings.setAdminLocation.bind(null, DOMAIN_0.domain, 'my.' + DOMAIN_0.domain), users.createOwner.bind(null, USER_0.username, USER_0.password, USER_0.email, USER_0.displayName, AUDIT_SOURCE), appdb.add.bind(null, APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.domain, apps._translatePortBindings(APP_0.portBindings, APP_0.manifest), APP_0), - settings.setAppAutoupdatePattern.bind(null, '00 00 1,3,5,23 * * *'), + settings.setAutoupdatePattern.bind(null, '00 00 1,3,5,23 * * *'), settingsdb.set.bind(null, settings.CLOUDRON_TOKEN_KEY, 'atoken'), ], done); }); @@ -441,7 +444,7 @@ describe('updatechecker - app - automatic free (email)', function () { .query({ boxVersion: constants.VERSION, accessToken: 'atoken', appId: APP_0.appStoreId, appVersion: APP_0.manifest.version, automatic: false }) .reply(200, { manifest: { version: '2.0.0', changelog: 'c' } } ); - updatechecker.checkAppUpdates({ automatic: false }, function (error) { + updatechecker._checkAppUpdates({ automatic: false }, function (error) { expect(!error).to.be.ok(); expect(updatechecker.getUpdateInfo().apps).to.eql({ 'appid-0': { manifest: { version: '2.0.0', changelog: 'c' }, unstable: false } }); expect(scope.isDone()).to.be.ok(); diff --git a/src/updatechecker.js b/src/updatechecker.js index 97cac6f31..52a952128 100644 --- a/src/updatechecker.js +++ b/src/updatechecker.js @@ -7,7 +7,8 @@ exports = module.exports = { resetUpdateInfo, resetAppUpdateInfo, - _setUpdateInfo: setUpdateInfo + _setUpdateInfo: setUpdateInfo, + _checkAppUpdates: checkAppUpdates }; var apps = require('./apps.js'), @@ -71,7 +72,7 @@ function checkAppUpdates(options, callback) { var oldState = loadState(); var newState = { }; // create new state so that old app ids are removed - settings.getAppAutoupdatePattern(function (error, result) { + settings.getAutoupdatePattern(function (error, result) { if (error) return callback(error); const autoupdatesEnabled = (result !== constants.AUTOUPDATE_PATTERN_NEVER); @@ -175,13 +176,13 @@ function checkForUpdates(options, callback) { assert.strictEqual(typeof options, 'object'); assert.strictEqual(typeof callback, 'function'); - checkBoxUpdates(options, function (error) { - if (error) debug('checkForUpdates: error checking for box updates:', error); + checkBoxUpdates(options, function (boxError) { + if (boxError) debug('checkForUpdates: error checking for box updates:', boxError); - checkAppUpdates(options, function (error) { - if (error) debug('checkForUpdates: error checking for app updates:', error); + checkAppUpdates(options, function (appError) { + if (appError) debug('checkForUpdates: error checking for app updates:', appError); - callback(); + callback(boxError || appError || null); }); });