@@ -19,6 +19,8 @@ import {
1919 GlideClusterClient ,
2020 GlideFt ,
2121 GlideJson ,
22+ GlideRecord ,
23+ GlideString ,
2224 InfoOptions ,
2325 JsonGetOptions ,
2426 ProtocolVersion ,
@@ -3235,5 +3237,66 @@ describe("Server Module Tests", () => {
32353237 newIndex ,
32363238 ) ;
32373239 } ) ;
3240+
3241+ it ( "FT._ALIASLIST test" , async ( ) => {
3242+ client = await GlideClusterClient . createClient (
3243+ getClientConfigurationOption (
3244+ cluster . getAddresses ( ) ,
3245+ ProtocolVersion . RESP3 ,
3246+ ) ,
3247+ ) ;
3248+ const index1 = uuidv4 ( ) ;
3249+ const alias1 = uuidv4 ( ) + "-alias" ;
3250+ const index2 = uuidv4 ( ) ;
3251+ const alias2 = uuidv4 ( ) + "-alias" ;
3252+
3253+ //Create the 2 test indexes.
3254+ expect (
3255+ await GlideFt . create ( client , index1 , [
3256+ { type : "NUMERIC" , name : "published_at" } ,
3257+ { type : "TAG" , name : "category" } ,
3258+ ] ) ,
3259+ ) . toEqual ( "OK" ) ;
3260+ expect (
3261+ await GlideFt . create ( client , index2 , [
3262+ { type : "NUMERIC" , name : "published_at" } ,
3263+ { type : "TAG" , name : "category" } ,
3264+ ] ) ,
3265+ ) . toEqual ( "OK" ) ;
3266+
3267+ //Check if the two indexes created successfully.
3268+ expect ( await client . customCommand ( [ "FT._LIST" ] ) ) . toContain ( index1 ) ;
3269+ expect ( await client . customCommand ( [ "FT._LIST" ] ) ) . toContain ( index2 ) ;
3270+
3271+ //Add aliases to the 2 indexes.
3272+ expect ( await GlideFt . aliasadd ( client , index1 , alias1 ) ) . toBe ( "OK" ) ;
3273+ expect ( await GlideFt . aliasadd ( client , index2 , alias2 ) ) . toBe ( "OK" ) ;
3274+
3275+ //Test if the aliaslist command return the added alias.
3276+ const result = await GlideFt . aliaslist ( client ) ;
3277+ const expected : GlideRecord < GlideString > = [
3278+ {
3279+ key : alias2 ,
3280+ value : index2 ,
3281+ } ,
3282+ {
3283+ key : alias1 ,
3284+ value : index1 ,
3285+ } ,
3286+ ] ;
3287+
3288+ const compareFunction = function (
3289+ a : { key : GlideString ; value : GlideString } ,
3290+ b : { key : GlideString ; value : GlideString } ,
3291+ ) {
3292+ return a . key . toString ( ) . localeCompare ( b . key . toString ( ) ) > 0
3293+ ? 1
3294+ : - 1 ;
3295+ } ;
3296+
3297+ expect ( result . sort ( compareFunction ) ) . toEqual (
3298+ expected . sort ( compareFunction ) ,
3299+ ) ;
3300+ } ) ;
32383301 } ) ;
32393302} ) ;
0 commit comments