-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eed88bc
commit 51e3aea
Showing
2 changed files
with
67 additions
and
95 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); | ||
}); |