@@ -2,26 +2,29 @@ import { describe, it, expect } from 'vitest';
22import TelegramBot from '../src/telegram_bot' ;
33
44describe ( 'telegram bot' , ( ) => {
5- it ( 'inline response' , async ( ) => {
6- const bot = new TelegramBot ( '123456789' ) . on ( ':message' , async ( ) => {
7- return new Response ( 'ok' ) ;
8- } ) ;
9- const request = new Request ( 'http://example.com/123456789' , {
10- method : 'POST' ,
11- body : JSON . stringify ( { inline_query : { query : 'hello' } } ) ,
12- } ) ;
13- expect ( await ( await bot . handle ( request ) ) . text ( ) ) . toBe ( 'ok' ) ;
14- expect ( bot . currentContext . update_type ) . toBe ( 'inline' ) ;
15- } ) ;
16- it ( 'message response' , async ( ) => {
17- const bot = new TelegramBot ( '123456789' ) . on ( ':message' , async ( ) => {
18- return new Response ( 'ok' ) ;
19- } ) ;
20- const request = new Request ( 'http://example.com/123456789' , {
21- method : 'POST' ,
22- body : JSON . stringify ( { message : { text : 'hello' } } ) ,
23- } ) ;
24- expect ( await ( await bot . handle ( request ) ) . text ( ) ) . toBe ( 'ok' ) ;
25- expect ( bot . currentContext . update_type ) . toBe ( 'message' ) ;
26- } ) ;
5+ // Test for inline query handling
6+ it ( 'inline response' , async ( ) => {
7+ const bot = new TelegramBot ( '123456789' ) . on ( ':message' , async ( ) => {
8+ return Promise . resolve ( new Response ( 'ok' ) ) ;
9+ } ) ;
10+ const request = new Request ( 'http://example.com/123456789' , {
11+ method : 'POST' ,
12+ body : JSON . stringify ( { inline_query : { query : 'hello' } } ) ,
13+ } ) ;
14+ expect ( await ( await bot . handle ( request ) ) . text ( ) ) . toBe ( 'ok' ) ;
15+ expect ( bot . currentContext . update_type ) . toBe ( 'inline' ) ;
16+ } ) ;
17+
18+ // Test for message handling
19+ it ( 'message response' , async ( ) => {
20+ const bot = new TelegramBot ( '123456789' ) . on ( ':message' , async ( ) => {
21+ return Promise . resolve ( new Response ( 'ok' ) ) ;
22+ } ) ;
23+ const request = new Request ( 'http://example.com/123456789' , {
24+ method : 'POST' ,
25+ body : JSON . stringify ( { message : { text : 'hello' } } ) ,
26+ } ) ;
27+ expect ( await ( await bot . handle ( request ) ) . text ( ) ) . toBe ( 'ok' ) ;
28+ expect ( bot . currentContext . update_type ) . toBe ( 'message' ) ;
29+ } ) ;
2730} ) ;
0 commit comments