@@ -680,27 +680,35 @@ describe("sendMessageDiscord", () => {
680680 expect ( body ) . not . toHaveProperty ( "flags" ) ;
681681 } ) ;
682682
683- it ( "rewrites cached @username mentions to id-based mentions" , async ( ) => {
684- rememberDiscordDirectoryUser ( {
685- accountId : "default" ,
686- userId : "123456789012345678" ,
687- handles : [ "Alice" ] ,
688- } ) ;
689- const { rest, postMock, getMock } = makeDiscordRest ( ) ;
690- getMock . mockResolvedValueOnce ( { type : ChannelType . GuildText } ) ;
691- postMock . mockResolvedValue ( {
692- id : "msg1" ,
693- channel_id : "789" ,
694- } ) ;
695- await sendMessageDiscord ( "channel:789" , "ping @Alice" , {
696- rest,
697- token : "t" ,
698- cfg : DISCORD_TEST_CFG ,
699- accountId : "default" ,
700- } ) ;
701- expectRestRoute ( postMock , 0 , Routes . channelMessages ( "789" ) ) ;
702- expect ( requireRestBody ( postMock ) . content ) . toBe ( "ping <@123456789012345678>" ) ;
703- } ) ;
683+ it . each ( [
684+ { input : "ping @Alice" , expected : "ping <@123456789012345678>" } ,
685+ { input : "Run `notify @Alice" , expected : "Run `notify @Alice" } ,
686+ { input : "literal \\` ping @Alice" , expected : "literal \\` ping <@123456789012345678>" } ,
687+ { input : "literal \\\\` inside @Alice" , expected : "literal \\\\` inside @Alice" } ,
688+ ] ) (
689+ "rewrites cached @username mentions only outside code: $input" ,
690+ async ( { input, expected } ) => {
691+ rememberDiscordDirectoryUser ( {
692+ accountId : "default" ,
693+ userId : "123456789012345678" ,
694+ handles : [ "Alice" ] ,
695+ } ) ;
696+ const { rest, postMock, getMock } = makeDiscordRest ( ) ;
697+ getMock . mockResolvedValueOnce ( { type : ChannelType . GuildText } ) ;
698+ postMock . mockResolvedValue ( {
699+ id : "msg1" ,
700+ channel_id : "789" ,
701+ } ) ;
702+ await sendMessageDiscord ( "channel:789" , input , {
703+ rest,
704+ token : "t" ,
705+ cfg : DISCORD_TEST_CFG ,
706+ accountId : "default" ,
707+ } ) ;
708+ expectRestRoute ( postMock , 0 , Routes . channelMessages ( "789" ) ) ;
709+ expect ( requireRestBody ( postMock ) . content ) . toBe ( expected ) ;
710+ } ,
711+ ) ;
704712
705713 it ( "rewrites configured @username aliases to id-based mentions" , async ( ) => {
706714 const { rest, postMock, getMock } = makeDiscordRest ( ) ;
0 commit comments