77 parseVersion,
88 stringifyVersion,
99 incrementPatchVersion,
10- getMaximumVersion ,
10+ isGreater ,
1111 getLatestAgentVersion,
1212 determineNextVersion,
1313 versionExists,
@@ -90,32 +90,33 @@ describe('version-utils', () => {
9090 } )
9191 } )
9292
93- describe ( 'getMaximumVersion ' , ( ) => {
94- it ( 'should return version with higher major version' , ( ) => {
93+ describe ( 'isGreater ' , ( ) => {
94+ it ( 'should return true when first version has higher major version' , ( ) => {
9595 const v1 = { major : 2 , minor : 0 , patch : 0 }
9696 const v2 = { major : 1 , minor : 9 , patch : 9 }
97- expect ( getMaximumVersion ( v1 , v2 ) ) . toEqual ( v1 )
98- expect ( getMaximumVersion ( v2 , v1 ) ) . toEqual ( v1 )
97+ expect ( isGreater ( v1 , v2 ) ) . toBe ( true )
98+ expect ( isGreater ( v2 , v1 ) ) . toBe ( false )
9999 } )
100100
101- it ( 'should return version with higher minor version when major is same' , ( ) => {
101+ it ( 'should return true when first version has higher minor version and same major ' , ( ) => {
102102 const v1 = { major : 1 , minor : 2 , patch : 0 }
103103 const v2 = { major : 1 , minor : 1 , patch : 9 }
104- expect ( getMaximumVersion ( v1 , v2 ) ) . toEqual ( v1 )
105- expect ( getMaximumVersion ( v2 , v1 ) ) . toEqual ( v1 )
104+ expect ( isGreater ( v1 , v2 ) ) . toBe ( true )
105+ expect ( isGreater ( v2 , v1 ) ) . toBe ( false )
106106 } )
107107
108- it ( 'should return version with higher patch version when major and minor are same' , ( ) => {
108+ it ( 'should return true when first version has higher patch version and same major/minor ' , ( ) => {
109109 const v1 = { major : 1 , minor : 2 , patch : 4 }
110110 const v2 = { major : 1 , minor : 2 , patch : 3 }
111- expect ( getMaximumVersion ( v1 , v2 ) ) . toEqual ( v1 )
112- expect ( getMaximumVersion ( v2 , v1 ) ) . toEqual ( v1 )
111+ expect ( isGreater ( v1 , v2 ) ) . toBe ( true )
112+ expect ( isGreater ( v2 , v1 ) ) . toBe ( false )
113113 } )
114114
115- it ( 'should return first version when versions are equal' , ( ) => {
115+ it ( 'should return false when versions are equal' , ( ) => {
116116 const v1 = { major : 1 , minor : 2 , patch : 3 }
117117 const v2 = { major : 1 , minor : 2 , patch : 3 }
118- expect ( getMaximumVersion ( v1 , v2 ) ) . toEqual ( v1 )
118+ expect ( isGreater ( v1 , v2 ) ) . toBe ( false )
119+ expect ( isGreater ( v2 , v1 ) ) . toBe ( false )
119120 } )
120121 } )
121122
@@ -201,7 +202,7 @@ describe('version-utils', () => {
201202 expect ( result ) . toEqual ( { major : 1 , minor : 2 , patch : 4 } )
202203 } )
203204
204- it ( 'should use provided version when higher than incremented latest' , async ( ) => {
205+ it ( 'should use provided version when higher than latest' , async ( ) => {
205206 spyOn ( versionUtils , 'getLatestAgentVersion' ) . mockResolvedValue ( {
206207 major : 0 ,
207208 minor : 0 ,
@@ -216,19 +217,32 @@ describe('version-utils', () => {
216217 expect ( result ) . toEqual ( { major : 2 , minor : 0 , patch : 0 } )
217218 } )
218219
219- it ( 'should use maximum of latest and provided version' , async ( ) => {
220+ it ( 'should throw error when provided version is not greater than latest ' , async ( ) => {
220221 spyOn ( versionUtils , 'getLatestAgentVersion' ) . mockResolvedValue ( {
221222 major : 2 ,
222223 minor : 0 ,
223224 patch : 0 ,
224225 } )
225226
226- const result = await determineNextVersion (
227- 'test-agent' ,
228- 'test-publisher' ,
229- '1.5.0' ,
227+ await expect (
228+ determineNextVersion ( 'test-agent' , 'test-publisher' , '1.5.0' ) ,
229+ ) . rejects . toThrow (
230+ 'Provided version 1.5.0 must be greater than the latest version (2.0.0)' ,
231+ )
232+ } )
233+
234+ it ( 'should throw error when provided version equals latest' , async ( ) => {
235+ spyOn ( versionUtils , 'getLatestAgentVersion' ) . mockResolvedValue ( {
236+ major : 1 ,
237+ minor : 5 ,
238+ patch : 0 ,
239+ } )
240+
241+ await expect (
242+ determineNextVersion ( 'test-agent' , 'test-publisher' , '1.5.0' ) ,
243+ ) . rejects . toThrow (
244+ 'Provided version 1.5.0 must be greater than the latest version (1.5.0)' ,
230245 )
231- expect ( result ) . toEqual ( { major : 2 , minor : 0 , patch : 1 } )
232246 } )
233247
234248 it ( 'should throw error for invalid provided version' , async ( ) => {
@@ -297,19 +311,21 @@ describe('version-utils', () => {
297311 // Test the complete flow of version operations
298312 const version1 = parseVersion ( '1.2.3' )
299313 const version2 = parseVersion ( '1.2.4' )
300- const maxVersion = getMaximumVersion ( version1 , version2 )
301- const nextVersion = incrementPatchVersion ( maxVersion )
314+ const isV2Greater = isGreater ( version2 , version1 )
315+ const nextVersion = incrementPatchVersion ( version2 )
302316 const versionString = stringifyVersion ( nextVersion )
303317
318+ expect ( isV2Greater ) . toBe ( true )
304319 expect ( versionString ) . toBe ( '1.2.5' )
305320 } )
306321
307322 it ( 'should handle edge cases with versionOne' , ( ) => {
308323 const one = versionOne ( )
309324 const incremented = incrementPatchVersion ( one )
310- const max = getMaximumVersion ( one , incremented )
325+ const isIncrementedGreater = isGreater ( incremented , one )
311326
312- expect ( max ) . toEqual ( { major : 0 , minor : 0 , patch : 2 } )
327+ expect ( isIncrementedGreater ) . toBe ( true )
328+ expect ( incremented ) . toEqual ( { major : 0 , minor : 0 , patch : 2 } )
313329 } )
314330 } )
315331} )
0 commit comments