2023-07-23 03:57:07 -06:00
|
|
|
import * as httpMock from '../../../../test/http-mock';
|
|
|
|
import { remoteBranchExists } from './branch';
|
|
|
|
|
|
|
|
describe('modules/platform/github/branch', () => {
|
|
|
|
it('should return true if the branch exists', async () => {
|
|
|
|
httpMock
|
|
|
|
.scope('https://api.github.com')
|
2024-10-21 01:38:11 -06:00
|
|
|
.get('/repos/my/repo/git/matching-refs/heads/renovate/foobar')
|
|
|
|
.reply(200, [{ ref: 'refs/heads/renovate/foobar' }]);
|
2023-07-23 03:57:07 -06:00
|
|
|
|
|
|
|
const result = await remoteBranchExists('my/repo', 'renovate/foobar');
|
|
|
|
|
|
|
|
expect(result).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return false if the branch does not exist', async () => {
|
|
|
|
httpMock
|
|
|
|
.scope('https://api.github.com')
|
2024-10-21 01:38:11 -06:00
|
|
|
.get('/repos/my/repo/git/matching-refs/heads/renovate/foobar')
|
|
|
|
.reply(200, []);
|
2023-07-23 03:57:07 -06:00
|
|
|
|
|
|
|
const result = await remoteBranchExists('my/repo', 'renovate/foobar');
|
|
|
|
|
|
|
|
expect(result).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should throw an error for nested branches', async () => {
|
|
|
|
httpMock
|
|
|
|
.scope('https://api.github.com')
|
2024-10-21 01:38:11 -06:00
|
|
|
.get('/repos/my/repo/git/matching-refs/heads/renovate/foobar')
|
|
|
|
.reply(200, [
|
|
|
|
{ ref: 'refs/heads/renovate/foobar/branch-1' },
|
|
|
|
{ ref: 'refs/heads/renovate/foobar/branch-2' },
|
|
|
|
{ ref: 'refs/heads/renovate/foobar/branch-3' },
|
|
|
|
]);
|
2023-07-23 03:57:07 -06:00
|
|
|
|
|
|
|
await expect(
|
2023-11-07 08:50:29 -07:00
|
|
|
remoteBranchExists('my/repo', 'renovate/foobar'),
|
2023-07-23 03:57:07 -06:00
|
|
|
).rejects.toThrow(
|
2023-11-07 08:50:29 -07:00
|
|
|
`Trying to create a branch 'renovate/foobar' while it's the part of nested branch`,
|
2023-07-23 03:57:07 -06:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should throw an error if the request fails for any other reason', async () => {
|
|
|
|
httpMock
|
|
|
|
.scope('https://api.github.com')
|
2024-10-21 01:38:11 -06:00
|
|
|
.get('/repos/my/repo/git/matching-refs/heads/renovate/foobar')
|
|
|
|
.reply(500);
|
2023-07-23 03:57:07 -06:00
|
|
|
|
|
|
|
await expect(
|
2023-11-07 08:50:29 -07:00
|
|
|
remoteBranchExists('my/repo', 'renovate/foobar'),
|
2023-07-23 03:57:07 -06:00
|
|
|
).rejects.toThrow('external-host-error');
|
|
|
|
});
|
|
|
|
});
|