summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2020-04-07 10:06:26 +0200
committerOskar Nyberg <oskar@mullvad.net>2020-04-07 10:06:33 +0200
commit70a16d19abbdc4d879494364287466601c003a9e (patch)
treeee77c2205d86dcafc86e5515ecb12a2fa3b0b903
parenta7235017f8029d78a2934fe545ba8320b0a3f107 (diff)
downloadmullvadvpn-70a16d19abbdc4d879494364287466601c003a9e.tar.xz
mullvadvpn-70a16d19abbdc4d879494364287466601c003a9e.zip
Add test for account-data-cache refetch when expired
-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;
+ });
+ });
});