Skip to content

Commit

Permalink
Migrating update-manager test
Browse files Browse the repository at this point in the history
  • Loading branch information
araujoarthur0 committed Mar 17, 2024
1 parent eed88bc commit 51e3aea
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 95 deletions.
95 changes: 0 additions & 95 deletions __tests__/__main__/update-manager.js

This file was deleted.

67 changes: 67 additions & 0 deletions __tests__/__main__/update-manager.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
'use strict';

import assert from 'assert';
import { net } from 'electron';
import { stub } from 'sinon';
import Store from 'electron-store';

import { getDateStr } from '../../js/date-aux.mjs';
import { checkForUpdates, shouldCheckForUpdates } from '../../js/update-manager.mjs';

describe('Update Manager', () =>
{
describe('shouldCheckForUpdates', () =>
{
it('Should return true when was never checked', () =>
{
const store = new Store();
store.set('update-remind-me-after', false);
assert.strictEqual(shouldCheckForUpdates(), true);
});

it('Should return true when was checked before today', () =>
{
const now = new Date();
now.setDate(now.getDate() - 1);
const store = new Store();
store.set('update-remind-me-after', getDateStr(now));
assert.strictEqual(shouldCheckForUpdates(), true);
});

it('Should return false when was checked today', () =>
{
const now = new Date();
const store = new Store();
store.set('update-remind-me-after', getDateStr(now));
assert.strictEqual(shouldCheckForUpdates(), false);
});
});

describe('checkForUpdates', () =>
{
it('should not execute when is offline', () =>
{
const netStub = stub(net, 'request').returns({
on: () => {},
end: () => {}
});
checkForUpdates();
assert.strictEqual(netStub.notCalled, true);
netStub.restore();
});

it('should not execute when is online', (done) =>
{
const netStub = stub(net, 'request').returns({
on: () =>
{
assert.strictEqual(netStub.calledOnce, true);
netStub.restore();
done();
},
end: () => {}
});
checkForUpdates();
});
});
});

0 comments on commit 51e3aea

Please sign in to comment.