-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fixed isCacheValid function and added tests
- Loading branch information
1 parent
6ec1b57
commit 6e6100b
Showing
5 changed files
with
65 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { isCacheValid } from '../../src/storage/util'; | ||
|
||
describe('tests common storages', () => { | ||
it('tests isCacheValid with empty state', () => { | ||
const invalid = isCacheValid({ state: 'empty' }); | ||
|
||
expect(invalid).toBe('unknown'); | ||
}); | ||
|
||
it('tests isCacheValid with loading state', () => { | ||
const invalid = isCacheValid({ state: 'loading' }); | ||
|
||
expect(invalid).toBe('unknown'); | ||
}); | ||
|
||
it('tests isCacheValid with overdue cached state', () => { | ||
const isValid = isCacheValid({ | ||
state: 'cached', | ||
data: {} as any, // doesn't matter | ||
createdAt: Date.now() - 2000, // 2 seconds in the past | ||
ttl: 1000 // 1 second | ||
}); | ||
|
||
expect(isValid).toBe(false); | ||
}); | ||
|
||
it('tests isCacheValid with overdue cached state', () => { | ||
const isValid = isCacheValid({ | ||
state: 'cached', | ||
data: {} as any, // doesn't matter | ||
createdAt: Date.now(), | ||
ttl: 1000 // 1 second | ||
}); | ||
|
||
expect(isValid).toBe(true); | ||
}); | ||
}); |