summaryrefslogtreecommitdiffhomepage
path: root/gui
diff options
context:
space:
mode:
Diffstat (limited to 'gui')
-rw-r--r--gui/test/account-data-cache.spec.ts40
1 files changed, 39 insertions, 1 deletions
diff --git a/gui/test/account-data-cache.spec.ts b/gui/test/account-data-cache.spec.ts
index 1395df448a..71a9b458d1 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', () => {
@@ -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;
+ });
+ });
});