1+ require ( '../setup' ) ;
12const { assert } = require ( 'chai' ) ;
23
4+ /**
5+ * @type {AsyncRedis }
6+ */
37const AsyncRedis = require ( '../../src' ) ;
48const getTestRedisConfig = require ( '../util/getTestRedisConfig' ) ;
59
@@ -14,25 +18,59 @@ describe('Commands', () => {
1418 redis . flushall ( ) ;
1519 } ) ;
1620
17- xdescribe ( 'APPEND Commands' , ( ) => {
18- it ( 'should execute append' , async ( ) => {
19- const status = await redis . append ( 'SETUSER' , 'hello' ) ;
20- assert . equal ( status , 'OK' ) ;
21+ describe ( 'Auth' , ( ) => {
22+ it ( 'should check decoration' , async ( ) => {
23+ assert . equal ( typeof redis . auth , 'function' ) ;
2124 } ) ;
2225
23- it ( 'should execute exists' , async ( ) => {
24- const status = await redis . append ( 'SETUSER' , 'world' ) ;
26+ it ( 'should test rejection' , async ( ) => {
27+ const promise = redis . auth ( 'bad_password' ) ;
28+ assert . isRejected ( promise , Error ) ;
29+ } ) ;
30+ } ) ;
31+
32+ describe ( 'CRUD - AOF (Append Only File)' , ( ) => {
33+ it ( 'should work with AOF' , async ( ) => {
34+ await redis . config ( 'set' , 'appendonly' , 'no' ) ;
35+ await redis . config ( 'rewrite' ) ;
36+ let status = await redis . bgrewriteaof ( ) ;
37+ assert . equal ( status , 'Background append only file rewriting started' ) ;
38+ status = await redis . set ( 'test' , 'value' ) ;
2539 assert . equal ( status , 'OK' ) ;
40+ status = await redis . bgsave ( ) ;
41+ await redis . bgrewriteaof ( ) ;
42+ assert . equal ( status , 'Background saving started' ) ;
2643 } ) ;
2744 } ) ;
2845
29- describe ( 'CRUD (set, get, del)' , ( ) => {
30- it ( 'should return ok' , async ( ) => {
46+ describe ( 'CRUD (append, set, get, del, exists)' , ( ) => {
47+ it ( 'should execute append' , async ( ) => {
48+ let status = await redis . append ( 'KEY' , 'hello' ) ;
49+ assert . equal ( status , 5 ) ;
50+ status = await redis . append ( 'KEY' , 'world' ) ;
51+ assert . equal ( status , 10 ) ;
52+ } ) ;
53+
54+ it ( 'should execute exists' , async ( ) => {
55+ let status = await redis . exists ( 'KEY' ) ;
56+ assert . equal ( status , 0 ) ;
57+ await redis . set ( 'KEY' , '' ) ;
58+ status = await redis . exists ( 'KEY' ) ;
59+ assert . equal ( status , 1 ) ;
60+ } ) ;
61+
62+ it ( 'should set and return ok' , async ( ) => {
3163 const status = await redis . set ( 'hello' , 'world' ) ;
3264 assert . equal ( status , "OK" ) ;
3365 } ) ;
3466
35- it ( 'should return true' , async ( ) => {
67+ it ( 'should get value' , async ( ) => {
68+ await redis . set ( 'hello' , 'world' ) ;
69+ const value = await redis . get ( 'hello' ) ;
70+ assert . equal ( value , "world" ) ;
71+ } ) ;
72+
73+ it ( 'should del and return true' , async ( ) => {
3674 await redis . set ( 'hello' , 'world' ) ;
3775 const status = await redis . del ( 'hello' ) ;
3876 assert . equal ( status , true ) ;
@@ -44,17 +82,65 @@ describe('Commands', () => {
4482 } ) ;
4583 } ) ;
4684
47- xdescribe ( 'test rejection' , ( ) => {
48- it ( 'should reject promise on throw' , async ( ) => {
49- const promise = redis . set ( 'hello' ) ;
50- assert . isRejected ( promise , Error ) ;
51- } ) ;
52- } ) ;
53-
5485 xdescribe ( 'test multi not a promise' , ( ) => {
5586 it ( 'should be not equal' , async ( ) => {
5687 const notAPromise = redis . multi ( ) ;
5788 assert . notEqual ( Promise . resolve ( notAPromise ) , notAPromise ) ;
5889 } ) ;
5990 } ) ;
91+
92+ describe ( 'PubSub' , ( ) => {
93+
94+ } ) ;
95+
96+ describe ( 'Utility' , ( ) => {
97+ it ( 'should return server info' , async ( ) => {
98+ let info = await redis . info ( ) ;
99+ assert . equal ( info . slice ( 0 , 8 ) , '# Server' ) ;
100+ } ) ;
101+
102+ it ( 'should ping' , async ( ) => {
103+ let reply = await redis . ping ( ) ;
104+ assert . equal ( reply , 'PONG' ) ;
105+ } ) ;
106+
107+ it ( 'should return db size' , async ( ) => {
108+ let status = await redis . set ( 'test' , 'value' ) ;
109+ assert . equal ( status , 'OK' ) ;
110+ status = await redis . dbsize ( ) ;
111+ assert . equal ( status , 1 ) ;
112+ } ) ;
113+
114+ it ( 'should execute debug' , async ( ) => {
115+ let status = await redis . set ( 'test' , 'value' ) ;
116+ assert . equal ( status , 'OK' ) ;
117+ status = await redis . debug ( 'object' , 'test' ) ;
118+ assert ( status ) ;
119+ } ) ;
120+
121+ it ( 'should execute monitor' , async ( ) => {
122+ const promises = [ ] ;
123+ promises . push ( new Promise ( ( resolve , reject ) => {
124+ redis . monitor ( ( error , status ) => {
125+ if ( error ) {
126+ reject ( error )
127+ } else {
128+ assert . equal ( status , 'OK' ) ;
129+ resolve ( ) ;
130+ }
131+ } ) ;
132+ } ) ) ;
133+ promises . push ( new Promise ( ( resolve ) => {
134+ redis . on ( 'monitor' , function ( time , args ) {
135+ assert . equal ( args . length , 3 ) ;
136+ assert . equal ( args [ 0 ] , 'set' ) ;
137+ assert . equal ( args [ 1 ] , 'hello' ) ;
138+ assert . equal ( args [ 2 ] , 'world' ) ;
139+ resolve ( ) ;
140+ } ) ;
141+ } ) ) ;
142+ promises . push ( redis . set ( 'hello' , 'world' ) ) ;
143+ await Promise . all ( promises ) ;
144+ } ) ;
145+ } ) ;
60146} ) ;
0 commit comments