@@ -116,34 +116,56 @@ describe('Hierarchical command registration', () => {
116116 const admin = registrationCommands . find (
117117 ( entry ) => entry . name === 'admin' ,
118118 ) ;
119+ const moderationGroup = admin ?. options ?. [ 0 ] as
120+ | {
121+ name : string ;
122+ options ?: Array < {
123+ name : string ;
124+ description : string ;
125+ options : Array < {
126+ name : string ;
127+ type : ApplicationCommandOptionType ;
128+ } > ;
129+ type : ApplicationCommandOptionType ;
130+ } > ;
131+ type : ApplicationCommandOptionType ;
132+ }
133+ | undefined ;
119134
120135 expect ( ping ?. type ) . toBe ( ApplicationCommandType . ChatInput ) ;
121136 expect ( admin ?. type ) . toBe ( ApplicationCommandType . ChatInput ) ;
122137 expect ( admin ?. description ) . toBe ( 'Admin' ) ;
123- expect ( admin ?. options ) . toEqual ( [
138+ expect ( moderationGroup ?. name ) . toBe ( 'moderation' ) ;
139+ expect ( moderationGroup ?. type ) . toBe (
140+ ApplicationCommandOptionType . SubcommandGroup ,
141+ ) ;
142+
143+ const normalizedSubcommands = [ ...( moderationGroup ?. options ?? [ ] ) ]
144+ . map ( ( option ) => ( {
145+ ...option ,
146+ options : [ ...( option . options ?? [ ] ) ] . sort ( ( a , b ) =>
147+ a . name . localeCompare ( b . name ) ,
148+ ) ,
149+ } ) )
150+ . sort ( ( a , b ) => a . name . localeCompare ( b . name ) ) ;
151+
152+ expect ( normalizedSubcommands ) . toEqual ( [
124153 {
125- description : 'Moderation ' ,
126- name : 'moderation ' ,
154+ description : 'Ban ' ,
155+ name : 'ban ' ,
127156 options : [
128157 {
129- description : 'Ban' ,
130- name : 'ban' ,
131- options : [
132- {
133- name : 'reason' ,
134- type : ApplicationCommandOptionType . String ,
135- } ,
136- ] ,
137- type : ApplicationCommandOptionType . Subcommand ,
138- } ,
139- {
140- description : 'Kick' ,
141- name : 'kick' ,
142- options : [ ] ,
143- type : ApplicationCommandOptionType . Subcommand ,
158+ name : 'reason' ,
159+ type : ApplicationCommandOptionType . String ,
144160 } ,
145161 ] ,
146- type : ApplicationCommandOptionType . SubcommandGroup ,
162+ type : ApplicationCommandOptionType . Subcommand ,
163+ } ,
164+ {
165+ description : 'Kick' ,
166+ name : 'kick' ,
167+ options : [ ] ,
168+ type : ApplicationCommandOptionType . Subcommand ,
147169 } ,
148170 ] ) ;
149171
0 commit comments