1
1
import { strict as assert } from 'assert' ;
2
2
import testUtils , { GLOBAL } from '../test-utils' ;
3
3
import { transformArguments , transformReply } from './HSCAN' ;
4
+ import { RedisCommandArguments } from "./index" ;
4
5
5
6
describe ( 'HSCAN' , ( ) => {
6
7
describe ( 'transformArguments' , ( ) => {
@@ -29,6 +30,18 @@ describe('HSCAN', () => {
29
30
) ;
30
31
} ) ;
31
32
33
+ it ( 'with NOVALUES' , ( ) => {
34
+ const expectedReply : RedisCommandArguments = [ 'HSCAN' , 'key' , '0' , 'NOVALUES' ] ;
35
+ expectedReply . preserve = true ;
36
+
37
+ assert . deepEqual (
38
+ transformArguments ( 'key' , 0 , {
39
+ NOVALUES : true
40
+ } ) ,
41
+ expectedReply
42
+ ) ;
43
+ } ) ;
44
+
32
45
it ( 'with MATCH & COUNT' , ( ) => {
33
46
assert . deepEqual (
34
47
transformArguments ( 'key' , 0 , {
@@ -38,6 +51,20 @@ describe('HSCAN', () => {
38
51
[ 'HSCAN' , 'key' , '0' , 'MATCH' , 'pattern' , 'COUNT' , '1' ]
39
52
) ;
40
53
} ) ;
54
+
55
+ it ( 'with MATCH & COUNT & NOVALUES' , ( ) => {
56
+ const expectedReply : RedisCommandArguments = [ 'HSCAN' , 'key' , '0' , 'MATCH' , 'pattern' , 'COUNT' , '1' , 'NOVALUES' ] ;
57
+ expectedReply . preserve = true ;
58
+
59
+ assert . deepEqual (
60
+ transformArguments ( 'key' , 0 , {
61
+ MATCH : 'pattern' ,
62
+ COUNT : 1 ,
63
+ NOVALUES : true
64
+ } ) ,
65
+ expectedReply
66
+ ) ;
67
+ } ) ;
41
68
} ) ;
42
69
43
70
describe ( 'transformReply' , ( ) => {
@@ -51,6 +78,16 @@ describe('HSCAN', () => {
51
78
) ;
52
79
} ) ;
53
80
81
+ it ( 'without keys' , ( ) => {
82
+ assert . deepEqual (
83
+ transformReply ( [ '0' , [ ] ] , true ) ,
84
+ {
85
+ cursor : 0 ,
86
+ keys : [ ]
87
+ }
88
+ ) ;
89
+ } ) ;
90
+
54
91
it ( 'with tuples' , ( ) => {
55
92
assert . deepEqual (
56
93
transformReply ( [ '0' , [ 'field' , 'value' ] ] ) ,
@@ -63,6 +100,16 @@ describe('HSCAN', () => {
63
100
}
64
101
) ;
65
102
} ) ;
103
+
104
+ it ( 'with keys' , ( ) => {
105
+ assert . deepEqual (
106
+ transformReply ( [ '0' , [ 'key1' , 'key2' ] ] , true ) ,
107
+ {
108
+ cursor : 0 ,
109
+ keys : [ 'key1' , 'key2' ]
110
+ }
111
+ ) ;
112
+ } ) ;
66
113
} ) ;
67
114
68
115
testUtils . testWithClient ( 'client.hScan' , async client => {
@@ -73,5 +120,34 @@ describe('HSCAN', () => {
73
120
tuples : [ ]
74
121
}
75
122
) ;
123
+
124
+ assert . deepEqual (
125
+ await client . hScan ( 'key' , 0 , { NOVALUES : true } ) ,
126
+ {
127
+ cursor : 0 ,
128
+ keys : [ ]
129
+ }
130
+ ) ;
131
+
132
+ await Promise . all ( [
133
+ client . hSet ( 'key' , 'a' , '1' ) ,
134
+ client . hSet ( 'key' , 'b' , '2' )
135
+ ] ) ;
136
+
137
+ assert . deepEqual (
138
+ await client . hScan ( 'key' , 0 ) ,
139
+ {
140
+ cursor : 0 ,
141
+ tuples : [ { field : 'a' , value : '1' } , { field : 'b' , value : '2' } ]
142
+ }
143
+ ) ;
144
+
145
+ assert . deepEqual (
146
+ await client . hScan ( 'key' , 0 , { NOVALUES : true } ) ,
147
+ {
148
+ cursor : 0 ,
149
+ keys : [ 'a' , 'b' ]
150
+ }
151
+ ) ;
76
152
} , GLOBAL . SERVERS . OPEN ) ;
77
153
} ) ;
0 commit comments