Add test for library and application pattern

Commit message is different between application and library.
Current parser targets only for application pattern.
This commit will cover libraries.

7444344c03/common/lib/dependabot/pull_request_creator/message_builder.rb (L71-L110)
7444344c03/common/lib/dependabot/pull_request_creator/message_builder.rb (L126-L130)
7444344c03/common/lib/dependabot/pull_request_creator/message_builder.rb (L181-L216)
This commit is contained in:
Kenichi Kamiya
2022-06-30 01:33:50 +09:00
parent a7c13a83a6
commit cf997547b4

View File

@@ -61,7 +61,7 @@ test('it does nothing if there is no metadata in the commit', async () => {
/* eslint-enable no-unused-expressions */
})
test('it sets the updated dependency as an output for subsequent actions', async () => {
test('it sets the updated dependency as an output for subsequent actions when given a commit message for application', async () => {
const mockCommitMessage =
'Bumps [coffee-rails](https://github.com/rails/coffee-rails) from 4.0.1 to 4.2.2.\n' +
'- [Release notes](https://github.com/rails/coffee-rails/releases)\n' +
@@ -131,6 +131,75 @@ test('it sets the updated dependency as an output for subsequent actions', async
expect(core.setOutput).toBeCalledWith('cvss', 0)
})
test('it sets the updated dependency as an output for subsequent actions when given a commit message for library', async () => {
const mockCommitMessage = `Update rubocop requirement from ~> 1.30.1 to ~> 1.31.0
Updates the requirements on [rubocop](https://github.com/rubocop/rubocop) to permit the latest version.
- [Release notes](https://github.com/rubocop/rubocop/releases)
- [Changelog](https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md)
- [Commits](rubocop/rubocop@v1.30.1...v1.31.0)
---
updated-dependencies:
- dependency-name: rubocop
dependency-type: direct:development
...
Signed-off-by: dependabot[bot] <support@github.com>`
const mockAlert = { alertState: 'FIXED', ghsaId: 'GSHA', cvss: 3.4 }
jest.spyOn(core, 'getInput').mockImplementation(jest.fn((name) => { return name === 'github-token' ? 'mock-token' : '' }))
jest.spyOn(util, 'getBranchNames').mockReturnValue({ headName: 'dependabot|bundler|feature1', baseName: 'main' })
jest.spyOn(dependabotCommits, 'getMessage').mockImplementation(jest.fn(
() => Promise.resolve(mockCommitMessage)
))
jest.spyOn(dependabotCommits, 'getAlert').mockImplementation(jest.fn(
() => Promise.resolve(mockAlert)
))
jest.spyOn(dependabotCommits, 'getCompatibility').mockImplementation(jest.fn(
() => Promise.resolve(34)
))
jest.spyOn(core, 'setOutput').mockImplementation(jest.fn())
await run()
expect(core.startGroup).toHaveBeenCalledWith(
expect.stringContaining('Outputting metadata for 1 updated dependency')
)
expect(core.setOutput).toHaveBeenCalledWith(
'updated-dependencies-json',
[
{
dependencyName: 'rubocop',
dependencyType: 'direct:development',
updateType: 'version-update:semver-minor',
directory: '/',
packageEcosystem: 'bundler',
targetBranch: 'main',
prevVersion: '1.30.1',
newVersion: '1.31.0',
compatScore: 0,
alertState: '',
ghsaId: '',
cvss: 0
}
]
)
expect(core.setOutput).toBeCalledWith('dependency-names', 'rubocop')
expect(core.setOutput).toBeCalledWith('dependency-type', 'direct:development')
expect(core.setOutput).toBeCalledWith('update-type', 'version-update:semver-minor')
expect(core.setOutput).toBeCalledWith('directory', '/')
expect(core.setOutput).toBeCalledWith('package-ecosystem', 'bundler')
expect(core.setOutput).toBeCalledWith('target-branch', 'main')
expect(core.setOutput).toBeCalledWith('previous-version', '1.30.1')
expect(core.setOutput).toBeCalledWith('new-version', '1.31.0')
expect(core.setOutput).toBeCalledWith('compatibility-score', 0)
expect(core.setOutput).toBeCalledWith('alert-state', '')
expect(core.setOutput).toBeCalledWith('ghsa-id', '')
expect(core.setOutput).toBeCalledWith('cvss', 0)
})
test('if there are multiple dependencies, it summarizes them', async () => {
const mockCommitMessage =
'Bump coffee-rails from 4.0.1 to 4.2.2 in api/main\n' +