-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use pattern '*' when group pattern is not specified in config (#1535)
* Use '*' if group pattern is not specified; filter out null dependency groups * Guard against empty arrays too * Unit tests
- Loading branch information
Rhys Koedijk
authored
Jan 15, 2025
1 parent
726e337
commit f531b91
Showing
2 changed files
with
115 additions
and
14 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
extension/tasks/dependabotV2/utils/dependabot-cli/DependabotJobBuilder.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { IDependabotGroup } from '../dependabot/interfaces/IDependabotConfig'; | ||
import { mapGroupsFromDependabotConfigToJobConfig } from './DependabotJobBuilder'; | ||
|
||
describe('mapGroupsFromDependabotConfigToJobConfig', () => { | ||
it('should return undefined if dependencyGroups is undefined', () => { | ||
const result = mapGroupsFromDependabotConfigToJobConfig(undefined); | ||
expect(result).toBeUndefined(); | ||
}); | ||
|
||
it('should return an empty array if dependencyGroups is an empty object', () => { | ||
const result = mapGroupsFromDependabotConfigToJobConfig({}); | ||
expect(result).toEqual([]); | ||
}); | ||
|
||
it('should filter out undefined groups', () => { | ||
const dependencyGroups: Record<string, any> = { | ||
group1: undefined, | ||
group2: { | ||
patterns: ['pattern2'], | ||
}, | ||
}; | ||
|
||
const result = mapGroupsFromDependabotConfigToJobConfig(dependencyGroups); | ||
expect(result).toEqual([ | ||
{ | ||
name: 'group2', | ||
rules: { | ||
patterns: ['pattern2'], | ||
}, | ||
}, | ||
]); | ||
}); | ||
|
||
it('should filter out null groups', () => { | ||
const dependencyGroups: Record<string, any> = { | ||
group1: null, | ||
group2: { | ||
patterns: ['pattern2'], | ||
}, | ||
}; | ||
|
||
const result = mapGroupsFromDependabotConfigToJobConfig(dependencyGroups); | ||
expect(result).toEqual([ | ||
{ | ||
name: 'group2', | ||
rules: { | ||
patterns: ['pattern2'], | ||
}, | ||
}, | ||
]); | ||
}); | ||
|
||
it('should map dependency group properties correctly', () => { | ||
const dependencyGroups: Record<string, IDependabotGroup> = { | ||
group: { | ||
'applies-to': 'all', | ||
'patterns': ['pattern1', 'pattern2'], | ||
'exclude-patterns': ['exclude1'], | ||
'dependency-type': 'direct', | ||
'update-types': ['security'], | ||
}, | ||
}; | ||
|
||
const result = mapGroupsFromDependabotConfigToJobConfig(dependencyGroups); | ||
|
||
expect(result).toEqual([ | ||
{ | ||
'name': 'group', | ||
'applies-to': 'all', | ||
'rules': { | ||
'patterns': ['pattern1', 'pattern2'], | ||
'exclude-patterns': ['exclude1'], | ||
'dependency-type': 'direct', | ||
'update-types': ['security'], | ||
}, | ||
}, | ||
]); | ||
}); | ||
|
||
it('should use pattern "*" if no patterns are provided', () => { | ||
const dependencyGroups: Record<string, IDependabotGroup> = { | ||
group: {}, | ||
}; | ||
|
||
const result = mapGroupsFromDependabotConfigToJobConfig(dependencyGroups); | ||
|
||
expect(result).toEqual([ | ||
{ | ||
name: 'group', | ||
rules: { | ||
patterns: ['*'], | ||
}, | ||
}, | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters