diff options
Diffstat (limited to 'gui/test')
| -rw-r--r-- | gui/test/account-data-cache.spec.ts | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/gui/test/account-data-cache.spec.ts b/gui/test/account-data-cache.spec.ts index fd79a2a697..6ed10c6908 100644 --- a/gui/test/account-data-cache.spec.ts +++ b/gui/test/account-data-cache.spec.ts @@ -226,4 +226,92 @@ describe('IAccountData cache', () => { return expect(update).to.eventually.be.fulfilled; }); + + it('should invalidate after 60 seconds', async () => { + const fetchSpy = spy(); + const expiry = new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(); + + const update = new Promise<void>((resolve, reject) => { + const cache = new AccountDataCache( + (_accountToken) => { + fetchSpy(); + return Promise.resolve({ expiry }); + }, + () => {}, + ); + + cache.fetch(dummyAccountToken, { + onFinish: async () => { + clock.tick(59_000); + // Timeout to let asynchronous tasks finish + await new Promise((resolve) => setTimeout(resolve)); + + cache.fetch(dummyAccountToken, { + onFinish: async () => { + clock.tick(1_000); + // Timeout to let asynchronous tasks finish + await new Promise((resolve) => setTimeout(resolve)); + + cache.fetch(dummyAccountToken, { + onFinish: async () => { + resolve(); + }, + onError: (_error: Error) => reject(), + }); + }, + onError: (_error: Error) => reject(), + }); + }, + onError: (_error: Error) => reject(), + }); + }); + + return expect(update).to.eventually.be.fulfilled.then(() => { + expect(fetchSpy).to.have.been.called.twice; + }); + }); + + it('should invalidate after 10 seconds when epired', async () => { + const fetchSpy = spy(); + const expiry = new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString(); + + const update = new Promise<void>((resolve, reject) => { + const cache = new AccountDataCache( + (_accountToken) => { + fetchSpy(); + return Promise.resolve({ expiry }); + }, + () => {}, + ); + + cache.fetch(dummyAccountToken, { + onFinish: async () => { + clock.tick(9_000); + // Timeout to let asynchronous tasks finish + await new Promise((resolve) => setTimeout(resolve)); + + cache.fetch(dummyAccountToken, { + onFinish: async () => { + clock.tick(1_000); + // Timeout to let asynchronous tasks finish + await new Promise((resolve) => setTimeout(resolve)); + + cache.fetch(dummyAccountToken, { + onFinish: async () => { + resolve(); + }, + onError: (_error: Error) => reject(), + }); + }, + onError: (_error: Error) => reject(), + }); + }, + onError: (_error: Error) => reject(), + }); + }); + + return expect(update).to.eventually.be.fulfilled.then(() => { + expect(fetchSpy).to.have.been.called.twice; + }); + }); }); |
