1- import { before , describe , it } from 'mocha' ;
1+ import { before , beforeEach , describe , it } from 'mocha' ;
22import { expect } from 'chai' ;
33import { Cache } from './dependencies' ;
44import CacheContract from '../src/models/cache-contract' ;
55import { ProvidersEnum } from '../src/models/provider' ;
6+ import {
7+ shouldGet ,
8+ shouldPersist ,
9+ shouldCheck ,
10+ shouldDelete ,
11+ shouldKeepForATime ,
12+ shouldAddTTLByStringFormat
13+ } from './base-test' ;
614
715describe ( 'Redis' , ( ) => {
816 let client : CacheContract ;
@@ -22,59 +30,27 @@ describe('Redis', () => {
2230 } ) ;
2331 } ) ;
2432
25- it ( 'Should get from redis' , async ( ) => {
26- const done = await client . add ( 'teste' , { name : 'guarda ai pf' } ) ;
27- expect ( done ) . to . be . equal ( true ) ;
28- const result = await client . get ( 'teste' ) ;
29- expect ( result ) . to . be . deep . equal ( { name : 'guarda ai pf' } ) ;
33+ it ( 'Should get' , async ( ) => {
34+ shouldGet ( client ) ;
3035 } ) ;
3136
32- it ( 'Should persist on redis' , async ( ) => {
33- const done = await client . add ( 'teste' , { name : 'guarda ai pf' } ) ;
34- expect ( done ) . to . be . equal ( true ) ;
37+ it ( 'Should persist' , async ( ) => {
38+ shouldPersist ( client ) ;
3539 } ) ;
3640
37- it ( 'Should check on redis' , async ( ) => {
38- const done = await client . add ( 'teste' , { name : 'guarda ai pf' } ) ;
39- expect ( done ) . to . be . equal ( true ) ;
40- const has = await client . has ( 'teste' ) ;
41- expect ( has ) . to . be . equal ( has ) ;
41+ it ( 'Should check if key exist' , async ( ) => {
42+ shouldCheck ( client ) ;
4243 } ) ;
4344
44- it ( 'Should delete on redis' , async ( ) => {
45- const done = await client . add ( 'teste' , { name : 'guarda ai pf' } ) ;
46- expect ( done ) . to . be . equal ( true ) ;
47- const deleted = await client . delete ( 'teste' ) ;
48- expect ( deleted ) . to . be . equal ( true ) ;
45+ it ( 'Should delete' , async ( ) => {
46+ shouldDelete ( client ) ;
4947 } ) ;
5048
51- it ( 'Should keep in redis for the given time' , async ( ) => {
52- const done = await client . add ( 'hashKey' , { name : 'Albo' } , 50 ) ;
53- expect ( done ) . to . be . equal ( true ) ;
54-
55- let result ;
56- const promise = new Promise ( resolve => {
57- setTimeout ( async ( ) => {
58- result = await client . get ( 'hashKey' ) ;
59- resolve ( result ) ;
60- } , 40 ) ;
61- } ) ;
62- result = await promise ;
63- expect ( result ) . to . be . deep . equal ( { name : 'Albo' } ) ;
49+ it ( 'Should keep for a given time' , async ( ) => {
50+ shouldKeepForATime ( client ) ;
6451 } ) ;
6552
66- it ( 'Should add ttl by string format in redis' , async ( ) => {
67- const done = await client . add ( 'hashKey' , { name : 'Albo' } , '400' ) ;
68- expect ( done ) . to . be . equal ( true ) ;
69-
70- let result ;
71- const promise = new Promise ( resolve => {
72- setTimeout ( async ( ) => {
73- result = await client . get ( 'hashKey' ) ;
74- resolve ( result ) ;
75- } , 300 ) ;
76- } ) ;
77- result = await promise ;
78- expect ( result ) . to . be . deep . equal ( { name : 'Albo' } ) ;
53+ it ( 'Should add ttl by string format' , async ( ) => {
54+ shouldAddTTLByStringFormat ( client ) ;
7955 } ) ;
8056} ) ;
0 commit comments