refactor(core): Mark all backend Enterprise Edition files and dirs (#12350)

This commit is contained in:
Iván Ovejero
2024-12-24 13:02:05 +01:00
committed by GitHub
parent 471d7b9420
commit f754b22a3f
194 changed files with 161 additions and 153 deletions

View File

@@ -0,0 +1,72 @@
import { mock } from 'jest-mock-extended';
import { simpleGit } from 'simple-git';
import type { SimpleGit } from 'simple-git';
import type { User } from '@/databases/entities/user';
import { SourceControlGitService } from '../source-control-git.service.ee';
import type { SourceControlPreferences } from '../types/source-control-preferences';
const MOCK_BRANCHES = {
all: ['origin/master', 'origin/feature/branch'],
branches: {
'origin/master': {},
'origin/feature/branch': {},
},
current: 'master',
};
jest.mock('simple-git', () => {
return {
simpleGit: jest.fn().mockImplementation(() => ({
branch: jest.fn().mockResolvedValue(MOCK_BRANCHES),
})),
};
});
describe('SourceControlGitService', () => {
const sourceControlGitService = new SourceControlGitService(mock(), mock(), mock());
beforeAll(() => {
sourceControlGitService.git = simpleGit();
});
describe('getBranches', () => {
it('should support branch names containing slashes', async () => {
const branches = await sourceControlGitService.getBranches();
expect(branches.branches).toEqual(['master', 'feature/branch']);
});
});
describe('initRepository', () => {
describe('when local repo is set up after remote is ready', () => {
it('should track remote', async () => {
/**
* Arrange
*/
const gitService = new SourceControlGitService(mock(), mock(), mock());
const prefs = mock<SourceControlPreferences>({ branchName: 'main' });
const user = mock<User>();
const git = mock<SimpleGit>();
const checkoutSpy = jest.spyOn(git, 'checkout');
const branchSpy = jest.spyOn(git, 'branch');
gitService.git = git;
jest.spyOn(gitService, 'setGitSshCommand').mockResolvedValue();
jest
.spyOn(gitService, 'getBranches')
.mockResolvedValue({ currentBranch: '', branches: ['main'] });
/**
* Act
*/
await gitService.initRepository(prefs, user);
/**
* Assert
*/
expect(checkoutSpy).toHaveBeenCalledWith('main');
expect(branchSpy).toHaveBeenCalledWith(['--set-upstream-to=origin/main', 'main']);
});
});
});
});