Skip to content

Commit

Permalink
Merge pull request wojtkowiak#22 from tkhtechnology/MX002-9288
Browse files Browse the repository at this point in the history
fix: do not download new version when desktopHCP is set to false
  • Loading branch information
StorytellerCZ committed Aug 11, 2023
2 parents d88a3e1 + bb250b7 commit f6f824a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
4 changes: 4 additions & 0 deletions skeleton/modules/autoupdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ export default class HCPClient {
* @private
*/
checkForUpdates() {
if (('desktopHCP' in this.appSettings) && !this.appSettings.desktopHCP) {
this.log.verbose(`Skipping checking for updates because desktopHCP is disabled`);
return;
}
const rootUrl = this.settings.customHCPUrl ?
this.settings.customHCPUrl : this.currentAssetBundle.getRootUrlString();

Expand Down
36 changes: 31 additions & 5 deletions tests/functional/modules/autoupdate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,16 @@ function exists(checkPath) {
* @param {boolean} printErrorLogs - Whether to print errors even if `printLogs` is false
* @param {boolean} testMode - Whether to inform autoupdate that this is a test run. Currently
* when true, autoupdate does not fire the startup timer
* @param {Object} [appSettings] - object pass as appSettings to HCPClient
*
* @returns {HCPClient}
*/
async function setUpAutoupdate(printLogs = false, onNewVersionReady, expectedVersion = 'version1',
errorCallback = Function.prototype, printErrorLogs = false,
testMode = true) {
testMode = true, appSettings = {}) {
const autoupdate = new HCPClient({
log: getFakeLogger(printLogs, printErrorLogs),
appSettings: {},
appSettings,
// fake systemEvents
eventsBus: {
on() {
Expand Down Expand Up @@ -154,10 +156,11 @@ async function setUpAutoupdate(printLogs = false, onNewVersionReady, expectedVer
* @param {boolean} printErrorLogs - Whether to print errors even if `printLogs` is false.
* @param {boolean} testMode - Whether to inform autoupdate that this is a test run. Currently
* when true, autoupdate does not fire the startup timer.
* @param {Object} [appSettings] - object pass as appSettings to HCPClient
*/
async function runAutoUpdateTests(done, testCallback, versionExpectedAfter,
versionExpectedBefore = 'version1', doNotCallDone = false,
printErrorLogs = showErrors, testMode = true) {
printErrorLogs = showErrors, testMode = true, appSettings) {
let autoupdate;
try {
autoupdate = await setUpAutoupdate(showLogs, async () => {
Expand All @@ -171,7 +174,7 @@ async function runAutoUpdateTests(done, testCallback, versionExpectedAfter,
if (!doNotCallDone) {
done();
}
}, versionExpectedBefore, undefined, printErrorLogs, testMode);
}, versionExpectedBefore, undefined, printErrorLogs, testMode, appSettings);
} catch (e) {
done(e);
}
Expand Down Expand Up @@ -236,7 +239,7 @@ function shutdownMeteorServer() {
}

function waitForTestToFail(delay, done) {
setTimeout(() => {
return setTimeout(() => {
done();
}, delay);
}
Expand Down Expand Up @@ -946,4 +949,27 @@ describe('autoupdate', () => {
autoupdate.checkForUpdates();
});
});

describe('when desktopHCP', () => {
beforeEach(async () => {
meteorServer = await serveVersion('version2');
cleanup();
});
afterEach(() => {
shutdownMeteorServer();
shutdownLocalServer();
});

it('is set to false then should not emit new version', (done) => {
const timeout = waitForTestToFail(1000, done);
runAutoUpdateTests(done, () => {
clearTimeout(timeout);
done('onVersionReady invoked unexpectedly');
}, 'version2', 'version1', true, false, true, { desktopHCP: false });
});

it('is set to true then should emit new version', (done) => {
runAutoUpdateTests(done, Function.prototype, 'version2', 'version1', false, false, true, { desktopHCP: true });
});
});
});
10 changes: 10 additions & 0 deletions tests/helpers/autoupdate/meteorServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ export default class MeteorServer {

server.use(setETag);

function versionDesktop(req, res, next) {
const parsedUrl = url.parse(req.url);
if (parsedUrl.pathname.endsWith('version.desktop.json')) {
const manifest = require(path.join(serverPath, 'manifest.json'))
res.end(JSON.stringify(manifest.version));
}
next();
}
server.use(versionDesktop);

// Serve files as static from the main directory.
server.use(serveStatic(serverPath),
{});
Expand Down

0 comments on commit f6f824a

Please sign in to comment.