@@ -7,33 +7,55 @@ import {
7
7
} from '../../../src/utils/redisCache' ;
8
8
9
9
describe ( 'Redis' , ( ) => {
10
- describe ( 'getCacheKeySafely' , ( ) => {
10
+ describe ( 'getCacheKeySafely (single arg) ' , ( ) => {
11
11
it ( 'should return an empty string if there are no command arguments' , ( ) => {
12
- const result = getCacheKeySafely ( [ ] ) ;
12
+ const result = getCacheKeySafely ( 'get' , [ ] ) ;
13
13
expect ( result ) . toBe ( '' ) ;
14
14
} ) ;
15
15
16
16
it ( 'should return a string representation of a single argument' , ( ) => {
17
17
const cmdArgs = [ 'key1' ] ;
18
- const result = getCacheKeySafely ( cmdArgs ) ;
18
+ const result = getCacheKeySafely ( 'get' , cmdArgs ) ;
19
19
expect ( result ) . toBe ( 'key1' ) ;
20
20
} ) ;
21
21
22
- it ( 'should return a comma-separated string for multiple arguments' , ( ) => {
23
- const cmdArgs = [ 'key1' , 'key2' , 'key3 '] ;
24
- const result = getCacheKeySafely ( cmdArgs ) ;
25
- expect ( result ) . toBe ( 'key1, key2, key3 ' ) ;
22
+ it ( 'should return only the key for multiple arguments' , ( ) => {
23
+ const cmdArgs = [ 'key1' , 'the-value ' ] ;
24
+ const result = getCacheKeySafely ( 'get' , cmdArgs ) ;
25
+ expect ( result ) . toBe ( 'key1' ) ;
26
26
} ) ;
27
27
28
28
it ( 'should handle number arguments' , ( ) => {
29
- const cmdArgs = [ 1 , 2 , 3 ] ;
30
- const result = getCacheKeySafely ( cmdArgs ) ;
31
- expect ( result ) . toBe ( '1, 2, 3' ) ;
29
+ const cmdArgs = [ 1 , 'the-value' ] ;
30
+ const result = getCacheKeySafely ( 'get' , cmdArgs ) ;
31
+ expect ( result ) . toBe ( '1' ) ;
32
+ } ) ;
33
+
34
+ it ( 'should handle Buffer arguments' , ( ) => {
35
+ const cmdArgs = [ Buffer . from ( 'key1' ) , Buffer . from ( 'key2' ) ] ;
36
+ const result = getCacheKeySafely ( 'get' , cmdArgs ) ;
37
+ expect ( result ) . toBe ( 'key1' ) ;
38
+ } ) ;
39
+
40
+ it ( 'should return <unknown> if the arg type is not supported' , ( ) => {
41
+ const cmdArgs = [ Symbol ( 'key1' ) ] ;
42
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
43
+ // @ts -ignore
44
+ const result = getCacheKeySafely ( 'get' , cmdArgs ) ;
45
+ expect ( result ) . toBe ( '<unknown>' ) ;
46
+ } ) ;
47
+ } ) ;
48
+
49
+ describe ( 'getCacheKeySafely (multiple args)' , ( ) => {
50
+ it ( 'should return a comma-separated string for multiple arguments with mget command' , ( ) => {
51
+ const cmdArgs = [ 'key1' , 'key2' , 'key3' ] ;
52
+ const result = getCacheKeySafely ( 'mget' , cmdArgs ) ;
53
+ expect ( result ) . toBe ( 'key1, key2, key3' ) ;
32
54
} ) ;
33
55
34
56
it ( 'should handle Buffer arguments' , ( ) => {
35
57
const cmdArgs = [ Buffer . from ( 'key1' ) , Buffer . from ( 'key2' ) ] ;
36
- const result = getCacheKeySafely ( cmdArgs ) ;
58
+ const result = getCacheKeySafely ( 'mget' , cmdArgs ) ;
37
59
expect ( result ) . toBe ( 'key1, key2' ) ;
38
60
} ) ;
39
61
@@ -42,30 +64,30 @@ describe('Redis', () => {
42
64
[ 'key1' , 'key2' ] ,
43
65
[ 'key3' , 'key4' ] ,
44
66
] ;
45
- const result = getCacheKeySafely ( cmdArgs ) ;
67
+ const result = getCacheKeySafely ( 'mget' , cmdArgs ) ;
46
68
expect ( result ) . toBe ( 'key1, key2, key3, key4' ) ;
47
69
} ) ;
48
70
49
71
it ( 'should handle mixed type arguments' , ( ) => {
50
72
const cmdArgs = [ Buffer . from ( 'key1' ) , [ 'key2' , 'key3' ] , [ Buffer . from ( 'key4' ) , 'key5' , 'key6' , 7 , [ 'key8' ] ] ] ;
51
- const result = getCacheKeySafely ( cmdArgs ) ;
73
+ const result = getCacheKeySafely ( 'mget' , cmdArgs ) ;
52
74
expect ( result ) . toBe ( 'key1, key2, key3, key4, key5, key6, 7, key8' ) ;
53
75
} ) ;
54
76
55
- it ( 'should handle nested arrays in arguments' , ( ) => {
77
+ it ( 'should handle nested arrays with mixed types in arguments' , ( ) => {
56
78
const cmdArgs = [
57
79
[ 'key1' , 'key2' ] ,
58
- [ 'key3' , 'key4' , [ 'key5' , [ 'key6' ] ] ] ,
80
+ [ 'key3' , 'key4' , [ Buffer . from ( 'key5' ) , [ 'key6' ] ] ] ,
59
81
] ;
60
- const result = getCacheKeySafely ( cmdArgs ) ;
82
+ const result = getCacheKeySafely ( 'mget' , cmdArgs ) ;
61
83
expect ( result ) . toBe ( 'key1, key2, key3, key4, key5, key6' ) ;
62
84
} ) ;
63
85
64
86
it ( 'should return <unknown> if the arg type is not supported' , ( ) => {
65
87
const cmdArgs = [ Symbol ( 'key1' ) ] ;
66
88
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
67
89
// @ts -ignore
68
- const result = getCacheKeySafely ( cmdArgs ) ;
90
+ const result = getCacheKeySafely ( 'mget' , cmdArgs ) ;
69
91
expect ( result ) . toBe ( '<unknown>' ) ;
70
92
} ) ;
71
93
} ) ;
0 commit comments