diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2020-04-07 13:24:05 +0200 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2020-04-07 13:24:05 +0200 |
| commit | f73f64394175fcd1d8c1a6911227ad600fa6e7ab (patch) | |
| tree | 3489fb232c264d2f934cd0032e154ee1a5fa232e | |
| parent | a7235017f8029d78a2934fe545ba8320b0a3f107 (diff) | |
| parent | b22ad3aa90f13832f2228e740dda02b4b045aa85 (diff) | |
| download | mullvadvpn-f73f64394175fcd1d8c1a6911227ad600fa6e7ab.tar.xz mullvadvpn-f73f64394175fcd1d8c1a6911227ad600fa6e7ab.zip | |
Merge branch 'account-data-cache-refetch-test'
| -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; + }); + }); }); |
