@@ -2,7 +2,8 @@ import * as updateMetadata from './update_metadata'
22
33test ( 'it returns an empty array for a blank string' , async ( ) => {
44 const getAlert = async ( ) => Promise . resolve ( { alertState : 'DISMISSED' , ghsaId : 'GHSA-III-BBB' , cvss : 4.6 } )
5- expect ( updateMetadata . parse ( '' , 'dependabot/nuget/coffee-rails' , 'main' , getAlert ) ) . resolves . toEqual ( [ ] )
5+ const getScore = async ( ) => Promise . resolve ( 43 )
6+ expect ( updateMetadata . parse ( '' , 'dependabot/nuget/coffee-rails' , 'main' , getAlert , getScore ) ) . resolves . toEqual ( [ ] )
67} )
78
89test ( 'it returns an empty array for commit message with no dependabot yaml fragment' , async ( ) => {
@@ -14,7 +15,8 @@ test('it returns an empty array for commit message with no dependabot yaml fragm
1415 Signed-off-by: dependabot[bot] <[email protected] >` 1516
1617 const getAlert = async ( ) => Promise . resolve ( { alertState : 'DISMISSED' , ghsaId : 'GHSA-III-BBB' , cvss : 4.6 } )
17- expect ( updateMetadata . parse ( commitMessage , 'dependabot/nuget/coffee-rails' , 'main' , getAlert ) ) . resolves . toEqual ( [ ] )
18+ const getScore = async ( ) => Promise . resolve ( 43 )
19+ expect ( updateMetadata . parse ( commitMessage , 'dependabot/nuget/coffee-rails' , 'main' , getAlert , getScore ) ) . resolves . toEqual ( [ ] )
1820} )
1921
2022test ( 'it returns the updated dependency information when there is a yaml fragment' , async ( ) => {
@@ -34,7 +36,8 @@ test('it returns the updated dependency information when there is a yaml fragmen
3436 'Signed-off-by: dependabot[bot] <[email protected] >' 3537
3638 const getAlert = async ( ) => Promise . resolve ( { alertState : 'DISMISSED' , ghsaId : 'GHSA-III-BBB' , cvss : 4.6 } )
37- const updatedDependencies = await updateMetadata . parse ( commitMessage , 'dependabot/nuget/coffee-rails' , 'main' , getAlert )
39+ const getScore = async ( ) => Promise . resolve ( 43 )
40+ const updatedDependencies = await updateMetadata . parse ( commitMessage , 'dependabot/nuget/coffee-rails' , 'main' , getAlert , getScore )
3841
3942 expect ( updatedDependencies ) . toHaveLength ( 1 )
4043
@@ -46,6 +49,7 @@ test('it returns the updated dependency information when there is a yaml fragmen
4649 expect ( updatedDependencies [ 0 ] . targetBranch ) . toEqual ( 'main' )
4750 expect ( updatedDependencies [ 0 ] . prevVersion ) . toEqual ( '4.0.1' )
4851 expect ( updatedDependencies [ 0 ] . newVersion ) . toEqual ( '4.2.2' )
52+ expect ( updatedDependencies [ 0 ] . compatScore ) . toEqual ( 43 )
4953 expect ( updatedDependencies [ 0 ] . alertState ) . toEqual ( 'DISMISSED' )
5054 expect ( updatedDependencies [ 0 ] . ghsaId ) . toEqual ( 'GHSA-III-BBB' )
5155 expect ( updatedDependencies [ 0 ] . cvss ) . toEqual ( 4.6 )
@@ -78,7 +82,15 @@ test('it supports multiple dependencies within a single fragment', async () => {
7882 return Promise . resolve ( { alertState : '' , ghsaId : '' , cvss : 0 } )
7983 }
8084
81- const updatedDependencies = await updateMetadata . parse ( commitMessage , 'dependabot/nuget/api/main/coffee-rails' , 'main' , getAlert )
85+ const getScore = async ( name : string ) => {
86+ if ( name === 'coffee-rails' ) {
87+ return Promise . resolve ( 34 )
88+ }
89+
90+ return Promise . resolve ( 0 )
91+ }
92+
93+ const updatedDependencies = await updateMetadata . parse ( commitMessage , 'dependabot/nuget/api/main/coffee-rails' , 'main' , getAlert , getScore )
8294
8395 expect ( updatedDependencies ) . toHaveLength ( 2 )
8496
@@ -90,6 +102,7 @@ test('it supports multiple dependencies within a single fragment', async () => {
90102 expect ( updatedDependencies [ 0 ] . targetBranch ) . toEqual ( 'main' )
91103 expect ( updatedDependencies [ 0 ] . prevVersion ) . toEqual ( '4.0.1' )
92104 expect ( updatedDependencies [ 0 ] . newVersion ) . toEqual ( '4.2.2' )
105+ expect ( updatedDependencies [ 0 ] . compatScore ) . toEqual ( 34 )
93106 expect ( updatedDependencies [ 0 ] . alertState ) . toEqual ( 'DISMISSED' )
94107 expect ( updatedDependencies [ 0 ] . ghsaId ) . toEqual ( 'GHSA-III-BBB' )
95108 expect ( updatedDependencies [ 0 ] . cvss ) . toEqual ( 4.6 )
@@ -101,7 +114,7 @@ test('it supports multiple dependencies within a single fragment', async () => {
101114 expect ( updatedDependencies [ 1 ] . packageEcosystem ) . toEqual ( 'nuget' )
102115 expect ( updatedDependencies [ 1 ] . targetBranch ) . toEqual ( 'main' )
103116 expect ( updatedDependencies [ 1 ] . prevVersion ) . toEqual ( '' )
104- expect ( updatedDependencies [ 1 ] . newVersion ) . toEqual ( '' )
117+ expect ( updatedDependencies [ 1 ] . compatScore ) . toEqual ( 0 )
105118 expect ( updatedDependencies [ 1 ] . alertState ) . toEqual ( '' )
106119 expect ( updatedDependencies [ 1 ] . ghsaId ) . toEqual ( '' )
107120 expect ( updatedDependencies [ 1 ] . cvss ) . toEqual ( 0 )
@@ -129,7 +142,7 @@ test('it only returns information within the first fragment if there are multipl
129142 '\n' +
130143 'Signed-off-by: dependabot[bot] <[email protected] >' 131144
132- const updatedDependencies = await updateMetadata . parse ( commitMessage , 'dependabot|nuget|coffee-rails' , 'main' , undefined )
145+ const updatedDependencies = await updateMetadata . parse ( commitMessage , 'dependabot|nuget|coffee-rails' , 'main' , undefined , undefined )
133146
134147 expect ( updatedDependencies ) . toHaveLength ( 1 )
135148
@@ -141,6 +154,7 @@ test('it only returns information within the first fragment if there are multipl
141154 expect ( updatedDependencies [ 0 ] . targetBranch ) . toEqual ( 'main' )
142155 expect ( updatedDependencies [ 0 ] . prevVersion ) . toEqual ( '' )
143156 expect ( updatedDependencies [ 0 ] . newVersion ) . toEqual ( '' )
157+ expect ( updatedDependencies [ 0 ] . compatScore ) . toEqual ( 0 )
144158 expect ( updatedDependencies [ 0 ] . alertState ) . toEqual ( '' )
145159 expect ( updatedDependencies [ 0 ] . ghsaId ) . toEqual ( '' )
146160 expect ( updatedDependencies [ 0 ] . cvss ) . toEqual ( 0 )
@@ -162,7 +176,8 @@ test('it properly handles dependencies which contain slashes', async () => {
162176 'Signed-off-by: dependabot[bot] <[email protected] >' 163177
164178 const getAlert = async ( ) => Promise . resolve ( { alertState : '' , ghsaId : '' , cvss : 0 } )
165- const updatedDependencies = await updateMetadata . parse ( commitMessage , 'dependabot/nuget/api/rails/coffee' , 'main' , getAlert )
179+ const getScore = async ( ) => Promise . resolve ( 0 )
180+ const updatedDependencies = await updateMetadata . parse ( commitMessage , 'dependabot/nuget/api/rails/coffee' , 'main' , getAlert , getScore )
166181
167182 expect ( updatedDependencies ) . toHaveLength ( 1 )
168183
@@ -174,6 +189,7 @@ test('it properly handles dependencies which contain slashes', async () => {
174189 expect ( updatedDependencies [ 0 ] . targetBranch ) . toEqual ( 'main' )
175190 expect ( updatedDependencies [ 0 ] . prevVersion ) . toEqual ( '' )
176191 expect ( updatedDependencies [ 0 ] . newVersion ) . toEqual ( '' )
192+ expect ( updatedDependencies [ 0 ] . compatScore ) . toEqual ( 0 )
177193 expect ( updatedDependencies [ 0 ] . alertState ) . toEqual ( '' )
178194 expect ( updatedDependencies [ 0 ] . ghsaId ) . toEqual ( '' )
179195 expect ( updatedDependencies [ 0 ] . cvss ) . toEqual ( 0 )
0 commit comments