diff options
author | Revanshu Paliwal <revanshu.paliwal@sonarsource.com> | 2022-11-11 16:12:19 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-11-17 20:03:07 +0000 |
commit | 317ada58ae514beeb7865d67dae54f271f6d26ae (patch) | |
tree | 30f20c3f681ea773403f9d74d1ff0d7af748afd1 /server/sonar-web/src/main/js/api/mocks/AlmIntegrationsServiceMock.ts | |
parent | 8d0f159bb4994704c4395c99762d794441eece8f (diff) | |
download | sonarqube-317ada58ae514beeb7865d67dae54f271f6d26ae.tar.gz sonarqube-317ada58ae514beeb7865d67dae54f271f6d26ae.zip |
SONAR-17586 Allow project onboarding when multiple Gitlab integrations are configured
Diffstat (limited to 'server/sonar-web/src/main/js/api/mocks/AlmIntegrationsServiceMock.ts')
-rw-r--r-- | server/sonar-web/src/main/js/api/mocks/AlmIntegrationsServiceMock.ts | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/server/sonar-web/src/main/js/api/mocks/AlmIntegrationsServiceMock.ts b/server/sonar-web/src/main/js/api/mocks/AlmIntegrationsServiceMock.ts new file mode 100644 index 00000000000..d63bbf29a17 --- /dev/null +++ b/server/sonar-web/src/main/js/api/mocks/AlmIntegrationsServiceMock.ts @@ -0,0 +1,86 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 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 { mockGitlabProject } from '../../helpers/mocks/alm-integrations'; +import { GitlabProject } from '../../types/alm-integration'; +import { + checkPersonalAccessTokenIsValid, + getGitlabProjects, + setAlmPersonalAccessToken, +} from '../alm-integrations'; + +export default class AlmIntegrationsServiceMock { + almInstancePATMap: { [key: string]: boolean } = {}; + gitlabProjects: GitlabProject[]; + defaultAlmInstancePATMap: { [key: string]: boolean } = { + 'conf-final-1': false, + 'conf-final-2': true, + }; + + defaultGitlabProjects: GitlabProject[] = [ + mockGitlabProject({ + name: 'Gitlab project 1', + id: '1', + sqProjectKey: 'key', + sqProjectName: 'Gitlab project 1', + }), + mockGitlabProject({ name: 'Gitlab project 2', id: '2' }), + mockGitlabProject({ name: 'Gitlab project 3', id: '3' }), + ]; + + constructor() { + this.almInstancePATMap = cloneDeep(this.defaultAlmInstancePATMap); + this.gitlabProjects = cloneDeep(this.defaultGitlabProjects); + (checkPersonalAccessTokenIsValid as jest.Mock).mockImplementation( + this.checkPersonalAccessTokenIsValid + ); + (setAlmPersonalAccessToken as jest.Mock).mockImplementation(this.setAlmPersonalAccessToken); + (getGitlabProjects as jest.Mock).mockImplementation(this.getGitlabProjects); + } + + checkPersonalAccessTokenIsValid = (conf: string) => { + return Promise.resolve({ status: this.almInstancePATMap[conf] }); + }; + + setAlmPersonalAccessToken = (conf: string) => { + this.almInstancePATMap[conf] = true; + return Promise.resolve(); + }; + + getGitlabProjects = () => { + return Promise.resolve({ + projects: this.gitlabProjects, + projectsPaging: { + pageIndex: 1, + pageSize: 30, + total: 3, + }, + }); + }; + + setGitlabProjects(gitlabProjects: GitlabProject[]) { + this.gitlabProjects = gitlabProjects; + } + + reset = () => { + this.almInstancePATMap = cloneDeep(this.defaultAlmInstancePATMap); + this.gitlabProjects = cloneDeep(this.defaultGitlabProjects); + }; +} |