0
0
mirror of https://github.com/renovatebot/renovate.git synced 2024-12-22 13:38:32 +00:00
renovatebot_renovate/lib/util/git/set-branch-commit.spec.ts
Tom Vervoort c82b9afb36
refactor: strongly type commit SHAs (#25207)
Co-authored-by: Rhys Arkins <rhys@arkins.net>
2023-11-22 06:30:19 +00:00

73 lines
2.2 KiB
TypeScript

import { git, logger, mocked, partial } from '../../../test/util';
import * as _repositoryCache from '../cache/repository';
import type { BranchCache, RepoCacheData } from '../cache/repository/types';
import { setBranchNewCommit } from './set-branch-commit';
import type { LongCommitSha } from './types';
jest.mock('../cache/repository');
jest.mock('.');
const repositoryCache = mocked(_repositoryCache);
describe('util/git/set-branch-commit', () => {
let repoCache: RepoCacheData = {};
beforeEach(() => {
repoCache = {};
repositoryCache.getCache.mockReturnValue(repoCache);
});
describe('setBranchCommit', () => {
it('sets new branch in cache if it does not exist', () => {
git.getBranchCommit.mockReturnValueOnce('base_SHA' as LongCommitSha);
setBranchNewCommit('branch_name', 'base_branch', 'SHA');
expect(logger.logger.debug).toHaveBeenCalledWith(
'setBranchCommit(): Branch cache not present',
);
expect(repoCache.branches).toEqual([
{
branchName: 'branch_name',
baseBranch: 'base_branch',
sha: 'SHA',
baseBranchSha: 'base_SHA',
isBehindBase: false,
isConflicted: false,
isModified: false,
pristine: true,
},
]);
});
it('sets new values in branch when old state exists', () => {
repoCache = {
branches: [
partial<BranchCache>({
branchName: 'branch_name',
baseBranch: 'base_branch',
sha: 'SHA',
baseBranchSha: 'base_SHA',
isBehindBase: false,
isModified: true,
pristine: false,
isConflicted: true,
}),
],
};
git.getBranchCommit.mockReturnValueOnce('base_SHA' as LongCommitSha);
repositoryCache.getCache.mockReturnValue(repoCache);
setBranchNewCommit('branch_name', 'base_branch', 'SHA');
expect(repoCache.branches).toEqual([
{
branchName: 'branch_name',
baseBranch: 'base_branch',
sha: 'SHA',
baseBranchSha: 'base_SHA',
isBehindBase: false,
isModified: false,
isConflicted: false,
pristine: true,
},
]);
});
});
});