@@ -753,6 +753,97 @@ describe('Users tests', () => {
753753 } )
754754} )
755755
756+ describe ( 'getVersions' , ( ) => {
757+ let otomiStack : OtomiStack
758+
759+ beforeEach ( async ( ) => {
760+ otomiStack = new OtomiStack ( )
761+ await otomiStack . init ( )
762+ } )
763+
764+ afterEach ( ( ) => {
765+ jest . restoreAllMocks ( )
766+ } )
767+
768+ test ( 'should return versions with otomi version from settings' , ( ) => {
769+ const mockSettings = { otomi : { version : '1.2.3' } }
770+ jest . spyOn ( otomiStack , 'getSettings' ) . mockReturnValue ( mockSettings )
771+
772+ const result = ( otomiStack as any ) . getVersions ( 'abc123' )
773+
774+ expect ( result ) . toHaveProperty ( 'core' , '1.2.3' )
775+ expect ( result ) . toHaveProperty ( 'api' )
776+ expect ( result ) . toHaveProperty ( 'console' )
777+ expect ( result ) . toHaveProperty ( 'values' , 'abc123' )
778+ expect ( otomiStack . getSettings ) . toHaveBeenCalledWith ( [ 'otomi' ] )
779+ } )
780+
781+ test ( 'should fallback to env.VERSIONS.core when otomi.version is not available' , ( ) => {
782+ const mockSettings = { otomi : undefined }
783+ jest . spyOn ( otomiStack , 'getSettings' ) . mockReturnValue ( mockSettings )
784+
785+ const result = ( otomiStack as any ) . getVersions ( 'def456' )
786+
787+ expect ( result ) . toHaveProperty ( 'core' )
788+ expect ( result ) . toHaveProperty ( 'api' )
789+ expect ( result ) . toHaveProperty ( 'console' )
790+ expect ( result ) . toHaveProperty ( 'values' , 'def456' )
791+ } )
792+
793+ test ( 'should fallback to process.env.npm_package_version when env.VERSIONS.api is not available' , ( ) => {
794+ const originalNpmVersion = process . env . npm_package_version
795+ process . env . npm_package_version = '5.0.0'
796+
797+ const mockSettings = { otomi : { version : '1.2.3' } }
798+ jest . spyOn ( otomiStack , 'getSettings' ) . mockReturnValue ( mockSettings )
799+
800+ const result = ( otomiStack as any ) . getVersions ( 'ghi789' )
801+
802+ expect ( result ) . toHaveProperty ( 'core' , '1.2.3' )
803+ expect ( result ) . toHaveProperty ( 'api' )
804+ expect ( result ) . toHaveProperty ( 'console' )
805+ expect ( result ) . toHaveProperty ( 'values' , 'ghi789' )
806+
807+ process . env . npm_package_version = originalNpmVersion
808+ } )
809+
810+ test ( 'should handle undefined otomi settings gracefully' , ( ) => {
811+ const mockSettings = { }
812+ jest . spyOn ( otomiStack , 'getSettings' ) . mockReturnValue ( mockSettings )
813+
814+ const result = ( otomiStack as any ) . getVersions ( 'xyz123' )
815+
816+ expect ( result ) . toHaveProperty ( 'core' )
817+ expect ( result ) . toHaveProperty ( 'api' )
818+ expect ( result ) . toHaveProperty ( 'console' )
819+ expect ( result ) . toHaveProperty ( 'values' , 'xyz123' )
820+ } )
821+
822+ test ( 'should pass through currentSha as values field' , ( ) => {
823+ const mockSettings = { otomi : { version : '1.0.0' } }
824+ jest . spyOn ( otomiStack , 'getSettings' ) . mockReturnValue ( mockSettings )
825+
826+ const testSha = 'unique-commit-sha-123'
827+ const result = ( otomiStack as any ) . getVersions ( testSha )
828+
829+ expect ( result . values ) . toBe ( testSha )
830+ expect ( typeof result . values ) . toBe ( 'string' )
831+ } )
832+
833+ test ( 'should return all required version fields' , ( ) => {
834+ const mockSettings = { otomi : { version : '1.0.0' } }
835+ jest . spyOn ( otomiStack , 'getSettings' ) . mockReturnValue ( mockSettings )
836+
837+ const result = ( otomiStack as any ) . getVersions ( 'test-sha' )
838+
839+ expect ( Object . keys ( result ) . sort ( ) ) . toEqual ( [ 'api' , 'console' , 'core' , 'values' ] )
840+ expect ( typeof result . core ) . toBe ( 'string' )
841+ expect ( typeof result . api ) . toBe ( 'string' )
842+ expect ( typeof result . console ) . toBe ( 'string' )
843+ expect ( typeof result . values ) . toBe ( 'string' )
844+ } )
845+ } )
846+
756847describe ( 'PodService' , ( ) => {
757848 let otomiStack : OtomiStack
758849 let clientMock : {
0 commit comments