refactor(core): Use Dependency Injection for all Controller classes (no-changelog) (#8146)

## Review / Merge checklist
- [x] PR title and summary are descriptive
This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2023-12-27 11:50:43 +01:00
committed by GitHub
parent 518a99e528
commit f69ddcd796
51 changed files with 209 additions and 522 deletions

View File

@@ -1,22 +1,18 @@
import { Container } from 'typedi';
import type { SuperAgentTest } from 'supertest';
import { SOURCE_CONTROL_API_ROOT } from '@/environments/sourceControl/constants';
import * as utils from '../shared/utils/';
import type { User } from '@db/entities/User';
import * as UserManagementHelpers from '@/UserManagement/UserManagementHelper';
import Container from 'typedi';
import config from '@/config';
import { SourceControlPreferencesService } from '@/environments/sourceControl/sourceControlPreferences.service.ee';
import { SourceControlService } from '@/environments/sourceControl/sourceControl.service.ee';
import type { SourceControlledFile } from '@/environments/sourceControl/types/sourceControlledFile';
import { getGlobalMemberRole, getGlobalOwnerRole } from '../shared/db/roles';
import * as utils from '../shared/utils/';
import { getGlobalOwnerRole } from '../shared/db/roles';
import { createUser } from '../shared/db/users';
let authOwnerAgent: SuperAgentTest;
let authMemberAgent: SuperAgentTest;
let owner: User;
let member: User;
const sharingSpy = jest.spyOn(UserManagementHelpers, 'isSharingEnabled').mockReturnValue(true);
const testServer = utils.setupTestServer({
endpointGroups: ['sourceControl', 'license', 'auth'],
@@ -25,11 +21,8 @@ const testServer = utils.setupTestServer({
beforeAll(async () => {
const globalOwnerRole = await getGlobalOwnerRole();
const globalMemberRole = await getGlobalMemberRole();
owner = await createUser({ globalRole: globalOwnerRole });
member = await createUser({ globalRole: globalMemberRole });
authOwnerAgent = testServer.authAgentFor(owner);
authMemberAgent = testServer.authAgentFor(member);
Container.get(SourceControlPreferencesService).isSourceControlConnected = () => true;
});
@@ -37,7 +30,7 @@ beforeAll(async () => {
describe('GET /sourceControl/preferences', () => {
test('should return Source Control preferences', async () => {
await authOwnerAgent
.get(`/${SOURCE_CONTROL_API_ROOT}/preferences`)
.get('/source-control/preferences')
.expect(200)
.expect((res) => {
return 'repositoryUrl' in res.body && 'branchName' in res.body;
@@ -60,7 +53,7 @@ describe('GET /sourceControl/preferences', () => {
] as SourceControlledFile[];
};
await authOwnerAgent
.get(`/${SOURCE_CONTROL_API_ROOT}/get-status`)
.get('/source-control/get-status')
.query({ direction: 'push', preferLocalVersion: 'true', verbose: 'false' })
.expect(200)
.expect((res) => {
@@ -73,7 +66,7 @@ describe('GET /sourceControl/preferences', () => {
test('refreshing key pairsshould return new rsa key', async () => {
config.set('sourceControl.defaultKeyPairType', 'rsa');
await authOwnerAgent
.post(`/${SOURCE_CONTROL_API_ROOT}/generate-key-pair`)
.post('/source-control/generate-key-pair')
.send()
.expect(200)
.expect((res) => {