Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
Remove unused vars
Browse files Browse the repository at this point in the history
  • Loading branch information
slaweet committed Nov 16, 2017
1 parent ea8a19e commit aef3e51
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 36 deletions.
2 changes: 1 addition & 1 deletion app/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ ipcMain.on('request-locale', () => {
localeHandler.send({ storage });
});

customAutoUpdater({ autoUpdater, dialog: electron.dialog }, app, process);
customAutoUpdater({ autoUpdater, dialog: electron.dialog });
2 changes: 1 addition & 1 deletion app/src/modules/autoUpdater.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import i18n from './../i18n';

export default ({ autoUpdater, dialog }, app, process) => { // eslint-disable-line no-unused-vars
export default ({ autoUpdater, dialog }) => {
try {
autoUpdater.checkForUpdates();
setInterval(() => {
Expand Down
60 changes: 26 additions & 34 deletions app/src/modules/autoUpdater.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,16 @@ import sinon, { spy } from 'sinon'; // eslint-disable-line import/no-extraneous-
import autoUpdater from './autoUpdater';

describe('autoUpdater', () => {
const win = {
getVersion() {
return 'VERSION_NUMBER';
},
};
const process = {
platform: 'mac',
};
const event = {};
const releaseNotes = '';
const releaseName = '1.2.3';
let electron;
let params;
let callbacks;
let clock;

beforeEach(() => {
callbacks = {};
electron = {
params = {
autoUpdater: {
checkForUpdates: spy(),
on: (name, callback) => {
Expand All @@ -44,70 +36,70 @@ describe('autoUpdater', () => {
clock.restore();
});

it('should call electron.autoUpdater.checkForUpdates', () => {
autoUpdater(electron, win, process);
expect(electron.autoUpdater.checkForUpdates).to.have.been.calledWithExactly();
it('should call params.autoUpdater.checkForUpdates', () => {
autoUpdater(params);
expect(params.autoUpdater.checkForUpdates).to.have.been.calledWithExactly();
});

it('should call electron.autoUpdater.checkForUpdates every 24 hours', () => {
autoUpdater(electron, win, process);
expect(electron.autoUpdater.checkForUpdates).to.have.callCount(1);
it('should call params.autoUpdater.checkForUpdates every 24 hours', () => {
autoUpdater(params);
expect(params.autoUpdater.checkForUpdates).to.have.callCount(1);
clock.tick(24 * 60 * 60 * 1000);
expect(electron.autoUpdater.checkForUpdates).to.have.callCount(2);
expect(params.autoUpdater.checkForUpdates).to.have.callCount(2);
clock.tick(24 * 60 * 60 * 1000);
expect(electron.autoUpdater.checkForUpdates).to.have.callCount(3);
expect(params.autoUpdater.checkForUpdates).to.have.callCount(3);
});

it('should call electron.autoUpdater.on with "update-downloaded" and "error"', () => {
autoUpdater(electron, win, process);
it('should call params.autoUpdater.on with "update-downloaded" and "error"', () => {
autoUpdater(params);
expect(callbacks['update-downloaded']).to.be.a('function');
expect(callbacks.error).to.be.a('function');
});

it('should call electron.dialog.showMessageBox on electron.autoUpdater.on("update-downloaded", ...) ', () => {
const dialogSpy = spy(electron.dialog, 'showMessageBox');
it('should call params.dialog.showMessageBox on params.autoUpdater.on("update-downloaded", ...) ', () => {
const dialogSpy = spy(params.dialog, 'showMessageBox');

autoUpdater(electron, win, process);
autoUpdater(params);
callbacks['update-downloaded'](event, releaseNotes, releaseName);

expect(dialogSpy).to.have.been.calledWith();
});

it('should electron.autoUpdater.quitAndInstall() in electron.dialog.showMessageBox callback if the first button was pressed', () => {
autoUpdater(electron, win, process);
it('should params.autoUpdater.quitAndInstall() in params.dialog.showMessageBox callback if the first button was pressed', () => {
autoUpdater(params);
callbacks['update-downloaded'](event, releaseNotes, releaseName);
callbacks.dialog(0);

expect(electron.autoUpdater.quitAndInstall).to.have.been.calledWithExactly();
expect(params.autoUpdater.quitAndInstall).to.have.been.calledWithExactly();
});

it('should not electron.autoUpdater.quitAndInstall() in electron.dialog.showMessageBox callback if the second button was pressed', () => {
autoUpdater(electron, win, process);
it('should not params.autoUpdater.quitAndInstall() in params.dialog.showMessageBox callback if the second button was pressed', () => {
autoUpdater(params);
callbacks['update-downloaded'](event, releaseNotes, releaseName);
callbacks.dialog(1);

expect(electron.autoUpdater.quitAndInstall).to.not.have.been.calledWith();
expect(params.autoUpdater.quitAndInstall).to.not.have.been.calledWith();
});

it('should console.error any error from electron.autoUpdater.on("error", ...) ', () => {
it('should console.error any error from params.autoUpdater.on("error", ...) ', () => {
const error = new Error('Error: Can not find Squirrel');
const consoleSpy = spy(console, 'error');

autoUpdater(electron, win, process);
autoUpdater(params);
callbacks.error(error);

expect(consoleSpy).to.have.been.calledWith('There was a problem updating the application');
expect(consoleSpy).to.have.been.calledWith(error);
consoleSpy.restore();
});

it('should console.log if electron.autoUpdater throws error due to unsigned package', () => {
it('should console.log if params.autoUpdater throws error due to unsigned package', () => {
const error = new Error('Error: Could not get code signature for running application');
electron.autoUpdater.checkForUpdates = () => {
params.autoUpdater.checkForUpdates = () => {
throw error;
};
const consoleSpy = spy(console, 'log');
autoUpdater(electron, win, process);
autoUpdater(params);

expect(consoleSpy).to.have.been.calledWith(error);
consoleSpy.restore();
Expand Down

0 comments on commit aef3e51

Please sign in to comment.