1- jest . resetModules ( ) ;
2-
3- jest . doMock ( "../../../../package.json" , ( ) => ( { version : "1.2.3" } ) ) ;
4- jest . doMock ( "../../../../bot/config" , ( ) => ( { ALLOWED_GROUPS : [ 999 ] } ) ) ;
5-
6- const versionModule = require ( "../../../../bot/handlers/commands/version" ) ;
1+ const loadModule = ( configOverrides = { } ) => {
2+ jest . resetModules ( ) ;
3+ jest . doMock ( "../../../../package.json" , ( ) => ( { version : "1.2.3" } ) ) ;
4+ jest . doMock ( "../../../../bot/config" , ( ) => ( {
5+ ALLOWED_GROUPS : [ 999 ] ,
6+ IS_TEST_BOT : false ,
7+ ...configOverrides ,
8+ } ) ) ;
9+ return require ( "../../../../bot/handlers/commands/version" ) ;
10+ } ;
711
812test ( "version replies in group when allowed" , ( ) => {
913 const replies = [ ] ;
@@ -12,8 +16,21 @@ test("version replies in group when allowed", () => {
1216 reply : ( text ) => replies . push ( text ) ,
1317 } ;
1418 const bot = { command : ( name , fn ) => fn ( ctx ) } ;
19+ const versionModule = loadModule ( ) ;
20+ versionModule ( bot ) ;
21+ expect ( replies [ 0 ] ) . toBe ( "🤖 Bot version: 1.2.3" ) ;
22+ } ) ;
23+
24+ test ( "version replies with test suffix when bot is flagged as test" , ( ) => {
25+ const replies = [ ] ;
26+ const ctx = {
27+ chat : { type : "group" , id : 999 } ,
28+ reply : ( text ) => replies . push ( text ) ,
29+ } ;
30+ const bot = { command : ( name , fn ) => fn ( ctx ) } ;
31+ const versionModule = loadModule ( { IS_TEST_BOT : true } ) ;
1532 versionModule ( bot ) ;
16- expect ( replies [ 0 ] ) . toMatch ( / B o t v e r s i o n : 1 .2 .3 / ) ;
33+ expect ( replies [ 0 ] ) . toBe ( "🤖 Bot version: 1.2.3 - test" ) ;
1734} ) ;
1835
1936test ( "version does not reply for private chat" , ( ) => {
@@ -23,6 +40,7 @@ test("version does not reply for private chat", () => {
2340 reply : ( text ) => replies . push ( text ) ,
2441 } ;
2542 const bot = { command : ( name , fn ) => fn ( ctx ) } ;
43+ const versionModule = loadModule ( ) ;
2644 versionModule ( bot ) ;
2745 expect ( replies . length ) . toBe ( 0 ) ;
2846} ) ;
0 commit comments