diff options
Diffstat (limited to 'gui')
| -rw-r--r-- | gui/test/account-data-cache.spec.ts | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/gui/test/account-data-cache.spec.ts b/gui/test/account-data-cache.spec.ts index 1395df448a..4d3dfc2ed3 100644 --- a/gui/test/account-data-cache.spec.ts +++ b/gui/test/account-data-cache.spec.ts @@ -1,6 +1,6 @@ import AccountDataCache, { AccountFetchRetryAction } from '../src/main/account-data-cache'; import { IAccountData } from '../src/shared/daemon-rpc-types'; -import * as sinon from 'sinon'; +import sinon from 'sinon'; import { expect, spy } from 'chai'; describe('IAccountData cache', () => { @@ -65,7 +65,7 @@ describe('IAccountData cache', () => { ); cache.fetch(dummyAccountToken, { - onFinish: spy(), + onFinish: () => {}, onError: (_error: Error) => { reject(); return AccountFetchRetryAction.stop; @@ -94,7 +94,7 @@ describe('IAccountData cache', () => { cache.fetch(dummyAccountToken, { onFinish: () => reject(), - onError: spy((_error: Error) => AccountFetchRetryAction.retry), + onError: (_error: Error) => AccountFetchRetryAction.retry, }); }); @@ -120,8 +120,8 @@ describe('IAccountData cache', () => { setTimeout(resolve, 12000); cache.fetch(dummyAccountToken, { - onFinish: spy(), - onError: spy((_error: Error) => AccountFetchRetryAction.stop), + onFinish: () => {}, + onError: (_error: Error) => AccountFetchRetryAction.stop, }); }); @@ -173,4 +173,42 @@ describe('IAccountData cache', () => { return; }); }); + + it('should refetch if account has expired', async () => { + const expiredSpy = spy(); + const nonExpiredSpy = spy(); + + const update = new Promise((resolve, reject) => { + let firstAttempt = true; + const fetch = () => { + if (firstAttempt) { + expiredSpy(); + firstAttempt = false; + setTimeout(() => clock.tick(60_000), 0); + return Promise.resolve({ + expiry: new Date('1969-01-01').toISOString(), + }); + } else { + nonExpiredSpy(); + resolve(); + return Promise.resolve(dummyAccountData); + } + }; + + const cache = new AccountDataCache(fetch, () => {}); + + cache.fetch(dummyAccountToken, { + onFinish: () => {}, + onError: (_error: Error) => { + reject(); + return AccountFetchRetryAction.stop; + }, + }); + }); + + return expect(update).to.eventually.be.fulfilled.then(() => { + expect(expiredSpy).to.have.been.called.once; + expect(nonExpiredSpy).to.have.been.called.once; + }); + }); }); |
