11import { describe , it , expect , vi , beforeEach , afterEach } from 'vitest' ;
22import { displayStartupBanner } from '../../../src/utils/banner' ;
33import type { FastifyBaseLogger } from 'fastify' ;
4+ import { getVersionString } from '../../../src/config/version' ;
5+
6+ // Get version dynamically from version config
7+ const CURRENT_VERSION = getVersionString ( ) ;
48
59// Helper function to strip ANSI color codes from strings
610const stripAnsiCodes = ( str : string ) : string => {
@@ -11,6 +15,14 @@ describe('banner.ts', () => {
1115 let mockLogger : FastifyBaseLogger ;
1216 let originalEnv : NodeJS . ProcessEnv ;
1317
18+ describe ( 'Version Management' , ( ) => {
19+ it ( 'should read version from version config' , ( ) => {
20+ expect ( CURRENT_VERSION ) . toBeDefined ( ) ;
21+ expect ( typeof CURRENT_VERSION ) . toBe ( 'string' ) ;
22+ expect ( CURRENT_VERSION ) . toMatch ( / ^ \d + \. \d + \. \d + / ) ;
23+ } ) ;
24+ } ) ;
25+
1426 beforeEach ( ( ) => {
1527 // Create mock logger
1628 mockLogger = {
@@ -44,7 +56,7 @@ describe('banner.ts', () => {
4456 const logCall = ( mockLogger . info as any ) . mock . calls [ 0 ] ;
4557 expect ( logCall [ 0 ] ) . toEqual ( {
4658 port : testPort ,
47- version : '0.20.9' ,
59+ version : CURRENT_VERSION ,
4860 environment : 'test' ,
4961 operation : 'startup_banner'
5062 } ) ;
@@ -98,8 +110,8 @@ describe('banner.ts', () => {
98110 const logCall = ( mockLogger . info as any ) . mock . calls [ 0 ] ;
99111 const bannerOutput = logCall [ 1 ] as string ;
100112 // Should use the version from version.ts (which reads from package.json in development)
101- expect ( bannerOutput ) . toContain ( 'v0.20.9' ) ;
102- expect ( logCall [ 0 ] . version ) . toBe ( '0.20.9' ) ;
113+ expect ( bannerOutput ) . toContain ( `v ${ CURRENT_VERSION } ` ) ;
114+ expect ( logCall [ 0 ] . version ) . toBe ( CURRENT_VERSION ) ;
103115 } ) ;
104116
105117 it ( 'should display current NODE_ENV' , ( ) => {
@@ -231,9 +243,9 @@ describe('banner.ts', () => {
231243 const logCall = ( mockLogger . info as any ) . mock . calls [ 0 ] ;
232244 const bannerOutput = logCall [ 1 ] as string ;
233245 const cleanOutput = stripAnsiCodes ( bannerOutput ) ;
234- expect ( cleanOutput ) . toContain ( 'v0.20.9' ) ; // Should use version.ts data
246+ expect ( cleanOutput ) . toContain ( `v ${ CURRENT_VERSION } ` ) ; // Should use version.ts data
235247 expect ( cleanOutput ) . toContain ( 'Environment: development' ) ; // Should fallback to default
236- expect ( logCall [ 0 ] . version ) . toBe ( '0.20.9' ) ;
248+ expect ( logCall [ 0 ] . version ) . toBe ( CURRENT_VERSION ) ;
237249 expect ( logCall [ 0 ] . environment ) . toBe ( 'development' ) ;
238250
239251 // Restore original environment variables
0 commit comments