11import test from 'ava' ;
2- import factory from '../src/factory '
2+ import createCache from '../src/'
33import UnityCacheError from '../src/error' ;
4- import localforageStub from './localforage.stub' ;
54
65test . beforeEach ( t => {
7- t . context . cache = factory ( localforageStub ) ( [ 'store' , 'store2' ] ) ;
6+ t . context . cache = createCache ( [ 'store' , 'store2' , 'drop_store '] ) ;
87} ) ;
98
109test ( 'set/get val with default expiration period' , async t => {
11- await t . context . cache . set ( 'store' , 'key' , 'val' ) ;
12- const cachedVal = await t . context . cache . get ( 'store' , 'key' ) ;
10+ await t . context . cache . set ( 'store' , 'key-not-expired ' , 'val' ) ;
11+ const cachedVal = await t . context . cache . get ( 'store' , 'key-not-expired ' ) ;
1312 t . is ( cachedVal , 'val' ) ;
1413} ) ;
1514
1615test ( 'set/get val with set expiration period' , async t => {
17- await t . context . cache . set ( 'store' , 'key ' , 'val ' , 1000 ) ;
18- const cachedVal = await t . context . cache . get ( 'store' , 'key ' ) ;
19- t . is ( cachedVal , 'val ' ) ;
16+ await t . context . cache . set ( 'store' , 'key2 ' , 'val2 ' , 1000 ) ;
17+ const cachedVal = await t . context . cache . get ( 'store' , 'key2 ' ) ;
18+ t . is ( cachedVal , 'val2 ' ) ;
2019} ) ;
2120
2221test ( 'set/get expired val' , async t => {
23- await t . context . cache . set ( 'store' , 'key' , 'val' , 0 ) ;
24- const cachedVal = await t . context . cache . get ( 'store' , 'key' ) ;
22+ await t . context . cache . set ( 'store' , 'key-expired' , 'val' , 0 ) ;
23+ const cachedVal = await t . context . cache . get ( 'store' , 'key-expired' ) ;
24+
2525 t . is ( cachedVal , null ) ;
2626} ) ;
2727
2828test ( 'set/get expired val without validation' , async t => {
29- await t . context . cache . set ( 'store' , 'key' , 'val' ) ;
30- const cachedVal = await t . context . cache . get ( 'store' , 'key' , false ) ;
29+ await t . context . cache . set ( 'store' , 'key-expired-2 ' , 'val' , 0 ) ;
30+ const cachedVal = await t . context . cache . get ( 'store' , 'key-expired-2 ' , false ) ;
3131 t . is ( cachedVal , 'val' ) ;
3232} ) ;
3333
3434test ( 'get non-existent val' , async t => {
35- const cachedVal = await t . context . cache . get ( 'store' , 'key' ) ;
35+ const cachedVal = await t . context . cache . get ( 'store' , 'key-non-exist ' ) ;
3636 t . is ( cachedVal , null ) ;
3737} ) ;
3838
@@ -50,17 +50,21 @@ test('remove val', async t => {
5050} ) ;
5151
5252test ( 'remove non-existent key' , async t => {
53- t . doesNotThrow ( async ( ) => await t . context . cache . remove ( 'store' , 'key-not-exist' ) ) ;
53+ t . notThrows ( async ( ) => await t . context . cache . remove ( 'store' , 'key-not-exist' ) ) ;
5454} ) ;
5555
5656test ( 'remove val on non-existent store' , async t => {
5757 t . throws ( t . context . cache . remove ( 'store-not-exist' , 'key' ) , Error ) ;
5858} ) ;
5959
6060test ( 'illegal store name' , async t => {
61- t . throws ( ( ) => factory ( localforageStub ) ( [ 'with spaces' ] ) , UnityCacheError ) ;
61+ t . throws ( ( ) => createCache ( [ 'with spaces' ] ) , UnityCacheError ) ;
6262} ) ;
6363
6464test ( 'does not throw on cache params' , async t => {
65- t . doesNotThrow ( ( ) => factory ( localforageStub ) ( [ 'store' ] , 'test' , 'test database' , 'localStorage' ) ) ;
65+ t . notThrows ( ( ) => createCache ( [ 'store' ] , 'test' , 'test database' , 'localStorageWrapper' ) ) ;
66+ } ) ;
67+
68+ test ( 'drop store' , async t => {
69+ t . notThrows ( async ( ) => await t . context . cache . drop ( [ 'drop_store' ] ) ) ;
6670} ) ;
0 commit comments