@@ -758,22 +758,32 @@ describe("deliverReplies", () => {
758758 expect ( runtime . error ) . not . toHaveBeenCalled ( ) ;
759759 } ) ;
760760
761- it ( "does not retry forum sends without message_thread_id" , async ( ) => {
761+ it ( "retries forum sends without message_thread_id when thread is missing " , async ( ) => {
762762 const runtime = createRuntime ( ) ;
763- const sendMessage = vi . fn ( ) . mockRejectedValue ( createThreadNotFoundError ( "sendMessage" ) ) ;
763+ const sendMessage = vi
764+ . fn ( )
765+ . mockRejectedValueOnce ( createThreadNotFoundError ( "sendMessage" ) )
766+ . mockResolvedValueOnce ( {
767+ message_id : 7 ,
768+ chat : { id : "123" } ,
769+ } ) ;
764770 const bot = createBot ( { sendMessage } ) ;
765771
766- await expect (
767- deliverWith ( {
768- replies : [ { text : "hello" } ] ,
769- runtime,
770- bot,
771- thread : { id : 42 , scope : "forum" } ,
772- } ) ,
773- ) . rejects . toThrow ( "message thread not found" ) ;
772+ await deliverWith ( {
773+ replies : [ { text : "hello" } ] ,
774+ runtime,
775+ bot,
776+ thread : { id : 42 , scope : "forum" } ,
777+ } ) ;
774778
775- expect ( sendMessage ) . toHaveBeenCalledTimes ( 1 ) ;
776- expect ( runtime . error ) . toHaveBeenCalledTimes ( 1 ) ;
779+ expect ( sendMessage ) . toHaveBeenCalledTimes ( 2 ) ;
780+ expect ( sendMessage . mock . calls [ 0 ] ?. [ 2 ] ) . toEqual (
781+ expect . objectContaining ( {
782+ message_thread_id : 42 ,
783+ } ) ,
784+ ) ;
785+ expect ( sendMessage . mock . calls [ 1 ] ?. [ 2 ] ) . not . toHaveProperty ( "message_thread_id" ) ;
786+ expect ( runtime . error ) . not . toHaveBeenCalled ( ) ;
777787 } ) ;
778788
779789 it ( "retries final text sends for wrapped pre-connect grammY HttpError envelopes" , async ( ) => {
0 commit comments