@@ -30,25 +30,89 @@ describe("The 'client' method", function () {
30
30
} ) ;
31
31
32
32
it ( "lists connected clients when invoked with multi's chaining syntax" , function ( done ) {
33
- client . multi ( ) . client ( 'list' ) . exec ( function ( err , results ) {
34
- assert ( pattern . test ( results [ 0 ] ) , "expected string '" + results + "' to match " + pattern . toString ( ) ) ;
35
- return done ( ) ;
36
- } ) ;
33
+ client . multi ( ) . client ( 'list' , helper . isType . string ( ) ) . exec ( helper . match ( pattern , done ) ) ;
37
34
} ) ;
38
35
39
36
it ( 'lists connected clients when invoked with array syntax on client' , function ( done ) {
40
- client . multi ( ) . client ( [ 'list' ] ) . exec ( function ( err , results ) {
41
- assert ( pattern . test ( results [ 0 ] ) , "expected string '" + results + "' to match " + pattern . toString ( ) ) ;
42
- return done ( ) ;
43
- } ) ;
37
+ client . multi ( ) . client ( [ 'list' ] ) . exec ( helper . match ( pattern , done ) ) ;
44
38
} ) ;
45
39
46
40
it ( "lists connected clients when invoked with multi's array syntax" , function ( done ) {
47
41
client . multi ( [
48
42
[ 'client' , 'list' ]
49
- ] ) . exec ( function ( err , results ) {
50
- assert ( pattern . test ( results [ 0 ] ) , "expected string '" + results + "' to match " + pattern . toString ( ) ) ;
51
- return done ( ) ;
43
+ ] ) . exec ( helper . match ( pattern , done ) ) ;
44
+ } ) ;
45
+ } ) ;
46
+
47
+ describe ( 'reply' , function ( ) {
48
+ describe ( 'as normal command' , function ( ) {
49
+ it ( 'on' , function ( done ) {
50
+ helper . serverVersionAtLeast . call ( this , client , [ 3 , 2 , 0 ] ) ;
51
+ assert . strictEqual ( client . reply , 'ON' ) ;
52
+ client . client ( 'reply' , 'on' , helper . isString ( 'OK' ) ) ;
53
+ assert . strictEqual ( client . reply , 'ON' ) ;
54
+ client . set ( 'foo' , 'bar' , done ) ;
55
+ } ) ;
56
+
57
+ it ( 'off' , function ( done ) {
58
+ helper . serverVersionAtLeast . call ( this , client , [ 3 , 2 , 0 ] ) ;
59
+ assert . strictEqual ( client . reply , 'ON' ) ;
60
+ client . client ( new Buffer ( 'REPLY' ) , 'OFF' , helper . isUndefined ( ) ) ;
61
+ assert . strictEqual ( client . reply , 'OFF' ) ;
62
+ client . set ( 'foo' , 'bar' , helper . isUndefined ( done ) ) ;
63
+ } ) ;
64
+
65
+ it ( 'skip' , function ( done ) {
66
+ helper . serverVersionAtLeast . call ( this , client , [ 3 , 2 , 0 ] ) ;
67
+ assert . strictEqual ( client . reply , 'ON' ) ;
68
+ client . client ( 'REPLY' , new Buffer ( 'SKIP' ) , helper . isUndefined ( ) ) ;
69
+ assert . strictEqual ( client . reply , 'SKIP_ONE_MORE' ) ;
70
+ client . set ( 'foo' , 'bar' , helper . isUndefined ( ) ) ;
71
+ client . get ( 'foo' , helper . isString ( 'bar' , done ) ) ;
72
+ } ) ;
73
+ } ) ;
74
+
75
+ describe ( 'in a batch context' , function ( ) {
76
+ it ( 'on' , function ( done ) {
77
+ helper . serverVersionAtLeast . call ( this , client , [ 3 , 2 , 0 ] ) ;
78
+ var batch = client . batch ( ) ;
79
+ assert . strictEqual ( client . reply , 'ON' ) ;
80
+ batch . client ( 'reply' , 'on' , helper . isString ( 'OK' ) ) ;
81
+ assert . strictEqual ( client . reply , 'ON' ) ;
82
+ batch . set ( 'foo' , 'bar' ) ;
83
+ batch . exec ( function ( err , res ) {
84
+ assert . deepEqual ( res , [ 'OK' , 'OK' ] ) ;
85
+ done ( err ) ;
86
+ } ) ;
87
+ } ) ;
88
+
89
+ it ( 'off' , function ( done ) {
90
+ helper . serverVersionAtLeast . call ( this , client , [ 3 , 2 , 0 ] ) ;
91
+ var batch = client . batch ( ) ;
92
+ assert . strictEqual ( client . reply , 'ON' ) ;
93
+ batch . set ( 'hello' , 'world' ) ;
94
+ batch . client ( new Buffer ( 'REPLY' ) , new Buffer ( 'OFF' ) , helper . isUndefined ( ) ) ;
95
+ batch . set ( 'foo' , 'bar' , helper . isUndefined ( ) ) ;
96
+ batch . exec ( function ( err , res ) {
97
+ assert . strictEqual ( client . reply , 'OFF' ) ;
98
+ assert . deepEqual ( res , [ 'OK' , undefined , undefined ] ) ;
99
+ done ( err ) ;
100
+ } ) ;
101
+ } ) ;
102
+
103
+ it ( 'skip' , function ( done ) {
104
+ helper . serverVersionAtLeast . call ( this , client , [ 3 , 2 , 0 ] ) ;
105
+ assert . strictEqual ( client . reply , 'ON' ) ;
106
+ client . batch ( )
107
+ . set ( 'hello' , 'world' )
108
+ . client ( 'REPLY' , 'SKIP' , helper . isUndefined ( ) )
109
+ . set ( 'foo' , 'bar' , helper . isUndefined ( ) )
110
+ . get ( 'foo' )
111
+ . exec ( function ( err , res ) {
112
+ assert . strictEqual ( client . reply , 'ON' ) ;
113
+ assert . deepEqual ( res , [ 'OK' , undefined , undefined , 'bar' ] ) ;
114
+ done ( err ) ;
115
+ } ) ;
52
116
} ) ;
53
117
} ) ;
54
118
} ) ;
0 commit comments