@@ -14,11 +14,7 @@ import { createServerCommandHandlerFactory } from "./handler";
1414describe ( "createServerCommandHandler" , ( ) => {
1515 const chance = new Chance ( ) ;
1616
17- // Helper to get a non-Santiago region for tests
18- const getTestRegion = ( ) => {
19- const nonSantiagoRegions = Object . values ( Region ) . filter ( r => r !== Region . SA_SANTIAGO_1 ) ;
20- return chance . pickone ( nonSantiagoRegions ) ;
21- } ;
17+ const getTestRegion = ( ) => chance . pickone ( Object . values ( Region ) ) ;
2218
2319 const createHandler = ( ) => {
2420 const interaction = mock < ChatInputCommandInteraction > ( ) ;
@@ -353,35 +349,57 @@ describe("createServerCommandHandler", () => {
353349 expect ( backgroundTaskQueue . enqueue ) . not . toHaveBeenCalled ( ) ;
354350 } ) ;
355351
356- it ( "should only show variants with matching guildId or no guildId " , async ( ) => {
352+ it ( "should only show variants for the requesting guild " , async ( ) => {
357353 const { handler, interaction } = createHandler ( ) ;
358354 const region = getTestRegion ( ) ;
359355 const guildId = interaction . guildId ;
360356
361- const variants = getVariantConfigs ( ) ;
357+ const allVariants = getVariantConfigs ( ) ;
358+ const guildSpecificVariants = allVariants . filter ( v => v . config . guildId === guildId ) ;
359+ const sharedVariants = allVariants . filter ( v => ! v . config . guildId ) ;
360+
361+ const expectedVariants = guildSpecificVariants . length > 0
362+ ? guildSpecificVariants
363+ : sharedVariants ;
364+
365+ const expectedLabels = expectedVariants . map ( v => v . config . displayName || v . name ) ;
362366
363- const variantsWithGuildId = variants . filter ( v => v . config . guildId === guildId ) ;
364- const variantsWithoutGuildId = variants . filter ( v => ! v . config . guildId ) ;
365- const expectedVariants = [ ...variantsWithoutGuildId ]
366- . map ( v => v . config . displayName || v . name ) ;
367- const expectedHiddenVariants = variantsWithGuildId . map ( v => v . config . displayName || v . name ) ;
368367 when ( interaction . options . getString )
369368 . calledWith ( "region" )
370369 . thenReturn ( region ) ;
371370
372371 interaction . reply = vi . fn ( ) . mockResolvedValue ( undefined ) as any ;
373- // Use the message and collector from createHandler
374372
375- // Call the command handler
376373 await handler ( interaction ) ;
377- // Check that only the correct variants are shown
374+
378375 const replyCall = ( interaction . reply as any ) . mock . calls [ 0 ] [ 0 ] ;
379- expect ( replyCall . components . flatMap ( ( row : any ) => row . components . map ( ( btn : any ) => btn . data . label ) ) ) . toEqual (
380- expect . arrayContaining ( expectedVariants )
381- ) ;
382- expect ( replyCall . components . flatMap ( ( row : any ) => row . components . map ( ( btn : any ) => btn . data . label ) ) ) . not . toContain (
383- expectedHiddenVariants
384- ) ;
376+ const displayedVariants = replyCall . components . flatMap ( ( row : any ) => row . components . map ( ( btn : any ) => btn . data . label ) ) ;
377+
378+ expect ( displayedVariants ) . toEqual ( expectedLabels ) ;
379+ } ) ;
380+
381+ it ( "should show all default variants if a guild has no specific variants" , async ( ) => {
382+ const { handler, interaction } = createHandler ( ) ;
383+ const region = getTestRegion ( ) ;
384+ const randomGuildId = chance . guid ( ) ;
385+ interaction . guildId = randomGuildId ;
386+
387+ const allVariants = getVariantConfigs ( ) ;
388+ const sharedVariants = allVariants . filter ( v => ! v . config . guildId ) ;
389+ const expectedLabels = sharedVariants . map ( v => v . config . displayName || v . name ) ;
390+
391+ when ( interaction . options . getString )
392+ . calledWith ( "region" )
393+ . thenReturn ( region ) ;
394+
395+ interaction . reply = vi . fn ( ) . mockResolvedValue ( undefined ) as any ;
396+
397+ await handler ( interaction ) ;
398+
399+ const replyCall = ( interaction . reply as any ) . mock . calls [ 0 ] [ 0 ] ;
400+ const displayedVariants = replyCall . components . flatMap ( ( row : any ) => row . components . map ( ( btn : any ) => btn . data . label ) ) ;
401+
402+ expect ( displayedVariants ) . toEqual ( expectedLabels ) ;
385403 } ) ;
386404
387405 it ( "should reply with abort message if server creation is aborted by the user" , async ( ) => {
@@ -465,24 +483,5 @@ describe("createServerCommandHandler", () => {
465483
466484
467485
468- it ( "it should only show 64bit variants for Santiago" , async ( ) => {
469- const { handler, interaction } = createHandler ( ) ;
470-
471- interaction . guildId = "1323509685264842752" // InsertCoin
472-
473- when ( interaction . options . getString )
474- . calledWith ( "region" )
475- . thenReturn ( Region . SA_SANTIAGO_1 ) ;
476-
477- // Mock admin permissions to bypass the Santiago block
478-
479- interaction . reply = vi . fn ( ) . mockResolvedValue ( undefined ) as any ;
480-
481- await handler ( interaction ) ;
482486
483- const replyCall = ( interaction . reply as any ) . mock . calls [ 0 ] [ 0 ] ;
484- const displayedVariants = replyCall . components . flatMap ( ( row : any ) => row . components . map ( ( btn : any ) => btn . data . label ) ) ;
485-
486- expect ( displayedVariants ) . toEqual ( [ 'Standard Competitive' , 'InsertCoin Mixes' ] ) ;
487- } ) ;
488487} ) ;
0 commit comments