aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/api/mocks
diff options
context:
space:
mode:
authorAmbroise C <ambroise.christea@sonarsource.com>2024-03-19 11:47:48 +0100
committersonartech <sonartech@sonarsource.com>2024-04-10 20:02:55 +0000
commite4d510ae08bffe482350633e423b455c006ca119 (patch)
tree6588ea997773482098f196b390b7dd3512d6b17a /server/sonar-web/src/main/js/api/mocks
parentd5c21bcc36de8f5a0fcd9ce44b02eac9e30f9cab (diff)
downloadsonarqube-e4d510ae08bffe482350633e423b455c006ca119.tar.gz
sonarqube-e4d510ae08bffe482350633e423b455c006ca119.zip
SONAR-21822 Add monorepo setup for GitHub
Diffstat (limited to 'server/sonar-web/src/main/js/api/mocks')
-rw-r--r--server/sonar-web/src/main/js/api/mocks/ComponentsServiceMock.ts7
-rw-r--r--server/sonar-web/src/main/js/api/mocks/DopTranslationServiceMock.ts123
-rw-r--r--server/sonar-web/src/main/js/api/mocks/data/dop-translation.ts34
3 files changed, 164 insertions, 0 deletions
diff --git a/server/sonar-web/src/main/js/api/mocks/ComponentsServiceMock.ts b/server/sonar-web/src/main/js/api/mocks/ComponentsServiceMock.ts
index 8f0404dda49..9c3e7948066 100644
--- a/server/sonar-web/src/main/js/api/mocks/ComponentsServiceMock.ts
+++ b/server/sonar-web/src/main/js/api/mocks/ComponentsServiceMock.ts
@@ -37,6 +37,7 @@ import {
ComponentRaw,
GetTreeParams,
changeKey,
+ doesComponentExists,
getBreadcrumbs,
getChildren,
getComponentData,
@@ -106,6 +107,7 @@ export default class ComponentsServiceMock {
jest.mocked(setProjectTags).mockImplementation(this.handleSetProjectTags);
jest.mocked(setApplicationTags).mockImplementation(this.handleSetApplicationTags);
jest.mocked(searchProjects).mockImplementation(this.handleSearchProjects);
+ jest.mocked(doesComponentExists).mockImplementation(this.handleDoesComponentExists);
}
handleSearchProjects: typeof searchProjects = (data) => {
@@ -420,6 +422,11 @@ export default class ComponentsServiceMock {
return this.reply();
};
+ handleDoesComponentExists: typeof doesComponentExists = ({ component }) => {
+ const exists = this.components.some(({ component: { key } }) => key === component);
+ return this.reply(exists);
+ };
+
reply<T>(): Promise<void>;
reply<T>(response: T): Promise<T>;
reply<T>(response?: T): Promise<T | void> {
diff --git a/server/sonar-web/src/main/js/api/mocks/DopTranslationServiceMock.ts b/server/sonar-web/src/main/js/api/mocks/DopTranslationServiceMock.ts
new file mode 100644
index 00000000000..1393c846867
--- /dev/null
+++ b/server/sonar-web/src/main/js/api/mocks/DopTranslationServiceMock.ts
@@ -0,0 +1,123 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+import { cloneDeep } from 'lodash';
+import { mockPaging } from '../../helpers/testMocks';
+import { AlmKeys } from '../../types/alm-settings';
+import { BoundProject, DopSetting } from '../../types/dop-translation';
+import { createBoundProject, getDopSettings } from '../dop-translation';
+import { mockDopSetting } from './data/dop-translation';
+
+jest.mock('../dop-translation');
+
+const defaultDopSettings = [
+ mockDopSetting({ key: 'conf-final-1', type: AlmKeys.GitLab }),
+ mockDopSetting({ key: 'conf-final-2', type: AlmKeys.GitLab }),
+ mockDopSetting({ key: 'conf-github-1', type: AlmKeys.GitHub, url: 'http://url' }),
+ mockDopSetting({ key: 'conf-github-2', type: AlmKeys.GitHub, url: 'http://url' }),
+ mockDopSetting({ key: 'conf-github-3', type: AlmKeys.GitHub, url: 'javascript://url' }),
+ mockDopSetting({ key: 'conf-azure-1', type: AlmKeys.Azure, url: 'url' }),
+ mockDopSetting({ key: 'conf-azure-2', type: AlmKeys.Azure, url: 'url' }),
+ mockDopSetting({
+ key: 'conf-bitbucketcloud-1',
+ type: AlmKeys.BitbucketCloud,
+ url: 'url',
+ }),
+ mockDopSetting({
+ key: 'conf-bitbucketcloud-2',
+ type: AlmKeys.BitbucketCloud,
+ url: 'url',
+ }),
+ mockDopSetting({
+ key: 'conf-bitbucketserver-1',
+ type: AlmKeys.BitbucketServer,
+ url: 'url',
+ }),
+ mockDopSetting({
+ key: 'conf-bitbucketserver-2',
+ type: AlmKeys.BitbucketServer,
+ url: 'url',
+ }),
+ mockDopSetting(),
+ mockDopSetting({ id: 'dop-setting-test-id-2', key: 'Test/DopSetting2' }),
+];
+
+export default class DopTranslationServiceMock {
+ boundProjects: BoundProject[] = [];
+ dopSettings: DopSetting[] = [
+ mockDopSetting({ key: 'conf-final-1', type: AlmKeys.GitLab }),
+ mockDopSetting({ key: 'conf-final-2', type: AlmKeys.GitLab }),
+ mockDopSetting({ key: 'conf-github-1', type: AlmKeys.GitHub, url: 'http://url' }),
+ mockDopSetting({ key: 'conf-github-2', type: AlmKeys.GitHub, url: 'http://url' }),
+ mockDopSetting({ key: 'conf-github-3', type: AlmKeys.GitHub, url: 'javascript://url' }),
+ mockDopSetting({ key: 'conf-azure-1', type: AlmKeys.Azure, url: 'url' }),
+ mockDopSetting({ key: 'conf-azure-2', type: AlmKeys.Azure, url: 'url' }),
+ mockDopSetting({
+ key: 'conf-bitbucketcloud-1',
+ type: AlmKeys.BitbucketCloud,
+ url: 'url',
+ }),
+ mockDopSetting({
+ key: 'conf-bitbucketcloud-2',
+ type: AlmKeys.BitbucketCloud,
+ url: 'url',
+ }),
+ mockDopSetting({
+ key: 'conf-bitbucketserver-1',
+ type: AlmKeys.BitbucketServer,
+ url: 'url',
+ }),
+ mockDopSetting({
+ key: 'conf-bitbucketserver-2',
+ type: AlmKeys.BitbucketServer,
+ url: 'url',
+ }),
+ mockDopSetting(),
+ mockDopSetting({ id: 'dop-setting-test-id-2', key: 'Test/DopSetting2' }),
+ ];
+
+ constructor() {
+ jest.mocked(createBoundProject).mockImplementation(this.createBoundProject);
+ jest.mocked(getDopSettings).mockImplementation(this.getDopSettings);
+ }
+
+ createBoundProject: typeof createBoundProject = (data) => {
+ this.boundProjects.push(data);
+ return Promise.resolve({});
+ };
+
+ getDopSettings = () => {
+ const total = this.getDopSettings.length;
+ return Promise.resolve({
+ dopSettings: this.dopSettings,
+ paging: mockPaging({ pageSize: total, total }),
+ });
+ };
+
+ removeDopTypeFromSettings = (type: AlmKeys) => {
+ this.dopSettings = cloneDeep(defaultDopSettings).filter(
+ (dopSetting) => dopSetting.type !== type,
+ );
+ };
+
+ reset() {
+ this.boundProjects = [];
+ this.dopSettings = cloneDeep(defaultDopSettings);
+ }
+}
diff --git a/server/sonar-web/src/main/js/api/mocks/data/dop-translation.ts b/server/sonar-web/src/main/js/api/mocks/data/dop-translation.ts
new file mode 100644
index 00000000000..bc8a5d9a991
--- /dev/null
+++ b/server/sonar-web/src/main/js/api/mocks/data/dop-translation.ts
@@ -0,0 +1,34 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/* eslint-disable local-rules/use-metrickey-enum */
+
+import { AlmKeys } from '../../../types/alm-settings';
+import { DopSetting } from '../../../types/dop-translation';
+
+export function mockDopSetting(overrides?: Partial<DopSetting>): DopSetting {
+ return {
+ id: overrides?.id ?? overrides?.key ?? 'dop-setting-test-id',
+ key: 'Test/DopSetting',
+ type: AlmKeys.GitHub,
+ url: 'https://github.com',
+ ...overrides,
+ };
+}