@@ -10,53 +10,53 @@ describe('Redis', () => {
10
10
describe ( 'getCacheKeySafely (single arg)' , ( ) => {
11
11
it ( 'should return an empty string if there are no command arguments' , ( ) => {
12
12
const result = getCacheKeySafely ( 'get' , [ ] ) ;
13
- expect ( result ) . toBe ( '' ) ;
13
+ expect ( result ) . toBe ( undefined ) ;
14
14
} ) ;
15
15
16
16
it ( 'should return a string representation of a single argument' , ( ) => {
17
17
const cmdArgs = [ 'key1' ] ;
18
18
const result = getCacheKeySafely ( 'get' , cmdArgs ) ;
19
- expect ( result ) . toBe ( 'key1' ) ;
19
+ expect ( result ) . toStrictEqual ( [ 'key1' ] ) ;
20
20
} ) ;
21
21
22
22
it ( 'should return only the key for multiple arguments' , ( ) => {
23
23
const cmdArgs = [ 'key1' , 'the-value' ] ;
24
24
const result = getCacheKeySafely ( 'get' , cmdArgs ) ;
25
- expect ( result ) . toBe ( 'key1' ) ;
25
+ expect ( result ) . toStrictEqual ( [ 'key1' ] ) ;
26
26
} ) ;
27
27
28
28
it ( 'should handle number arguments' , ( ) => {
29
29
const cmdArgs = [ 1 , 'the-value' ] ;
30
30
const result = getCacheKeySafely ( 'get' , cmdArgs ) ;
31
- expect ( result ) . toBe ( '1' ) ;
31
+ expect ( result ) . toStrictEqual ( [ '1' ] ) ;
32
32
} ) ;
33
33
34
34
it ( 'should handle Buffer arguments' , ( ) => {
35
35
const cmdArgs = [ Buffer . from ( 'key1' ) , Buffer . from ( 'key2' ) ] ;
36
36
const result = getCacheKeySafely ( 'get' , cmdArgs ) ;
37
- expect ( result ) . toBe ( 'key1' ) ;
37
+ expect ( result ) . toStrictEqual ( [ 'key1' ] ) ;
38
38
} ) ;
39
39
40
40
it ( 'should return <unknown> if the arg type is not supported' , ( ) => {
41
41
const cmdArgs = [ Symbol ( 'key1' ) ] ;
42
42
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
43
43
// @ts -ignore
44
44
const result = getCacheKeySafely ( 'get' , cmdArgs ) ;
45
- expect ( result ) . toBe ( '<unknown>' ) ;
45
+ expect ( result ) . toStrictEqual ( [ '<unknown>' ] ) ;
46
46
} ) ;
47
47
} ) ;
48
48
49
49
describe ( 'getCacheKeySafely (multiple args)' , ( ) => {
50
50
it ( 'should return a comma-separated string for multiple arguments with mget command' , ( ) => {
51
51
const cmdArgs = [ 'key1' , 'key2' , 'key3' ] ;
52
52
const result = getCacheKeySafely ( 'mget' , cmdArgs ) ;
53
- expect ( result ) . toBe ( 'key1, key2, key3' ) ;
53
+ expect ( result ) . toStrictEqual ( [ 'key1' , ' key2' , ' key3'] ) ;
54
54
} ) ;
55
55
56
56
it ( 'should handle Buffer arguments' , ( ) => {
57
57
const cmdArgs = [ Buffer . from ( 'key1' ) , Buffer . from ( 'key2' ) ] ;
58
58
const result = getCacheKeySafely ( 'mget' , cmdArgs ) ;
59
- expect ( result ) . toBe ( 'key1, key2' ) ;
59
+ expect ( result ) . toStrictEqual ( [ 'key1' , ' key2'] ) ;
60
60
} ) ;
61
61
62
62
it ( 'should handle array arguments' , ( ) => {
@@ -65,13 +65,13 @@ describe('Redis', () => {
65
65
[ 'key3' , 'key4' ] ,
66
66
] ;
67
67
const result = getCacheKeySafely ( 'mget' , cmdArgs ) ;
68
- expect ( result ) . toBe ( 'key1, key2, key3, key4' ) ;
68
+ expect ( result ) . toStrictEqual ( [ 'key1' , ' key2' , ' key3' , ' key4'] ) ;
69
69
} ) ;
70
70
71
71
it ( 'should handle mixed type arguments' , ( ) => {
72
72
const cmdArgs = [ Buffer . from ( 'key1' ) , [ 'key2' , 'key3' ] , [ Buffer . from ( 'key4' ) , 'key5' , 'key6' , 7 , [ 'key8' ] ] ] ;
73
73
const result = getCacheKeySafely ( 'mget' , cmdArgs ) ;
74
- expect ( result ) . toBe ( 'key1, key2, key3, key4, key5, key6, 7, key8' ) ;
74
+ expect ( result ) . toStrictEqual ( [ 'key1' , ' key2' , ' key3' , ' key4' , ' key5' , ' key6' , '7' , ' key8'] ) ;
75
75
} ) ;
76
76
77
77
it ( 'should handle nested arrays with mixed types in arguments' , ( ) => {
@@ -80,15 +80,15 @@ describe('Redis', () => {
80
80
[ 'key3' , 'key4' , [ Buffer . from ( 'key5' ) , [ 'key6' ] ] ] ,
81
81
] ;
82
82
const result = getCacheKeySafely ( 'mget' , cmdArgs ) ;
83
- expect ( result ) . toBe ( 'key1, key2, key3, key4, key5, key6' ) ;
83
+ expect ( result ) . toStrictEqual ( [ 'key1' , ' key2' , ' key3' , ' key4' , ' key5' , ' key6'] ) ;
84
84
} ) ;
85
85
86
86
it ( 'should return <unknown> if the arg type is not supported' , ( ) => {
87
87
const cmdArgs = [ Symbol ( 'key1' ) ] ;
88
88
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
89
89
// @ts -ignore
90
90
const result = getCacheKeySafely ( 'mget' , cmdArgs ) ;
91
- expect ( result ) . toBe ( '<unknown>' ) ;
91
+ expect ( result ) . toStrictEqual ( [ '<unknown>' ] ) ;
92
92
} ) ;
93
93
} ) ;
94
94
@@ -137,7 +137,7 @@ describe('Redis', () => {
137
137
it ( 'should return false for non-cache commands' , ( ) => {
138
138
const command = 'EXISTS' ;
139
139
const commandLowercase = 'exists' ;
140
- const key = 'cache:test-key' ;
140
+ const key = [ 'cache:test-key' ] ;
141
141
const result1 = shouldConsiderForCache ( command , key , prefixes ) ;
142
142
const result2 = shouldConsiderForCache ( commandLowercase , key , prefixes ) ;
143
143
expect ( result1 ) . toBe ( false ) ;
@@ -146,35 +146,35 @@ describe('Redis', () => {
146
146
147
147
it ( 'should return true for cache commands with matching prefix' , ( ) => {
148
148
const command = 'get' ;
149
- const key = 'cache:test-key' ;
149
+ const key = [ 'cache:test-key' ] ;
150
150
const result = shouldConsiderForCache ( command , key , prefixes ) ;
151
151
expect ( result ) . toBe ( true ) ;
152
152
} ) ;
153
153
154
154
it ( 'should return false for cache commands without matching prefix' , ( ) => {
155
155
const command = 'get' ;
156
- const key = 'test-key' ;
156
+ const key = [ 'test-key' ] ;
157
157
const result = shouldConsiderForCache ( command , key , prefixes ) ;
158
158
expect ( result ) . toBe ( false ) ;
159
159
} ) ;
160
160
161
161
it ( 'should return true for multiple keys with at least one matching prefix' , ( ) => {
162
162
const command = 'mget' ;
163
- const key = 'test-key, cache:test-key' ;
163
+ const key = [ 'test-key' , ' cache:test-key'] ;
164
164
const result = shouldConsiderForCache ( command , key , prefixes ) ;
165
165
expect ( result ) . toBe ( true ) ;
166
166
} ) ;
167
167
168
168
it ( 'should return false for multiple keys without any matching prefix' , ( ) => {
169
169
const command = 'mget' ;
170
- const key = 'test-key, test-key2' ;
170
+ const key = [ 'test-key' , ' test-key2'] ;
171
171
const result = shouldConsiderForCache ( command , key , prefixes ) ;
172
172
expect ( result ) . toBe ( false ) ;
173
173
} ) ;
174
174
175
175
GET_COMMANDS . concat ( SET_COMMANDS ) . forEach ( command => {
176
176
it ( `should return true for ${ command } command with matching prefix` , ( ) => {
177
- const key = 'cache:test-key' ;
177
+ const key = [ 'cache:test-key' ] ;
178
178
const result = shouldConsiderForCache ( command , key , prefixes ) ;
179
179
expect ( result ) . toBe ( true ) ;
180
180
} ) ;
0 commit comments