2022-10-31 05:50:33 +00:00
|
|
|
import * as _repositoryCache from '../cache/repository';
|
|
|
|
import type { BranchCache, RepoCacheData } from '../cache/repository/types';
|
2022-10-06 04:37:47 +00:00
|
|
|
import { setBranchNewCommit } from './set-branch-commit';
|
2023-11-22 06:30:19 +00:00
|
|
|
import type { LongCommitSha } from './types';
|
2025-03-13 17:52:09 +00:00
|
|
|
import { git, logger, partial } from '~test/util';
|
2022-10-06 04:37:47 +00:00
|
|
|
|
2025-02-26 09:35:54 +00:00
|
|
|
vi.mock('../cache/repository');
|
|
|
|
vi.mock('.');
|
2025-03-13 17:52:09 +00:00
|
|
|
const repositoryCache = vi.mocked(_repositoryCache);
|
2022-10-06 04:37:47 +00:00
|
|
|
|
2022-10-31 05:50:33 +00:00
|
|
|
describe('util/git/set-branch-commit', () => {
|
2022-10-06 04:37:47 +00:00
|
|
|
let repoCache: RepoCacheData = {};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
repoCache = {};
|
|
|
|
repositoryCache.getCache.mockReturnValue(repoCache);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setBranchCommit', () => {
|
2022-11-20 07:10:25 +00:00
|
|
|
it('sets new branch in cache if it does not exist', () => {
|
2023-11-22 06:30:19 +00:00
|
|
|
git.getBranchCommit.mockReturnValueOnce('base_SHA' as LongCommitSha);
|
2022-10-06 04:37:47 +00:00
|
|
|
setBranchNewCommit('branch_name', 'base_branch', 'SHA');
|
|
|
|
expect(logger.logger.debug).toHaveBeenCalledWith(
|
2023-11-07 15:50:29 +00:00
|
|
|
'setBranchCommit(): Branch cache not present',
|
2022-10-06 04:37:47 +00:00
|
|
|
);
|
|
|
|
expect(repoCache.branches).toEqual([
|
|
|
|
{
|
|
|
|
branchName: 'branch_name',
|
|
|
|
baseBranch: 'base_branch',
|
|
|
|
sha: 'SHA',
|
|
|
|
baseBranchSha: 'base_SHA',
|
|
|
|
isBehindBase: false,
|
2022-10-26 06:11:51 +00:00
|
|
|
isConflicted: false,
|
2022-10-06 04:37:47 +00:00
|
|
|
isModified: false,
|
2022-11-20 07:10:25 +00:00
|
|
|
pristine: true,
|
2022-10-06 04:37:47 +00:00
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
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',
|
2022-11-20 07:10:25 +00:00
|
|
|
isBehindBase: false,
|
2022-10-26 06:11:51 +00:00
|
|
|
isModified: true,
|
2022-11-20 07:10:25 +00:00
|
|
|
pristine: false,
|
2022-10-26 06:11:51 +00:00
|
|
|
isConflicted: true,
|
2022-10-06 04:37:47 +00:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
};
|
2023-11-22 06:30:19 +00:00
|
|
|
git.getBranchCommit.mockReturnValueOnce('base_SHA' as LongCommitSha);
|
2022-10-06 04:37:47 +00:00
|
|
|
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,
|
2022-10-26 06:11:51 +00:00
|
|
|
isConflicted: false,
|
2022-11-20 07:10:25 +00:00
|
|
|
pristine: true,
|
2022-10-06 04:37:47 +00:00
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|