From 2a15c441255c935cda446fe65f7b62724e123b8f Mon Sep 17 00:00:00 2001 From: Viktor Vorona Date: Wed, 27 Sep 2023 16:20:53 +0200 Subject: [PATCH] SONAR-20532 Support isBaseRole in FE mocks --- .../js/api/mocks/AuthenticationServiceMock.ts | 111 ++++++------------ 1 file changed, 36 insertions(+), 75 deletions(-) diff --git a/server/sonar-web/src/main/js/api/mocks/AuthenticationServiceMock.ts b/server/sonar-web/src/main/js/api/mocks/AuthenticationServiceMock.ts index b2ddda2275d..c4664fc7ddc 100644 --- a/server/sonar-web/src/main/js/api/mocks/AuthenticationServiceMock.ts +++ b/server/sonar-web/src/main/js/api/mocks/AuthenticationServiceMock.ts @@ -63,67 +63,42 @@ const defaultConfigurationStatus: GitHubConfigurationStatus = { ], }; -const defaultMapping: GitHubMapping[] = [ - { - id: 'read', - githubRole: 'read', - permissions: { - user: true, - codeViewer: true, - issueAdmin: false, - securityHotspotAdmin: false, - admin: false, - scan: false, - }, - }, - { - id: 'write', - githubRole: 'write', - permissions: { - user: true, - codeViewer: true, - issueAdmin: true, - securityHotspotAdmin: true, - admin: false, - scan: true, - }, - }, - { - id: 'triage', - githubRole: 'triage', - permissions: { - user: true, - codeViewer: true, - issueAdmin: false, - securityHotspotAdmin: false, - admin: false, - scan: false, - }, - }, - { - id: 'maintain', - githubRole: 'maintain', - permissions: { - user: true, - codeViewer: true, - issueAdmin: true, - securityHotspotAdmin: true, - admin: false, - scan: true, - }, - }, - { - id: 'admin', - githubRole: 'admin', - permissions: { - user: true, - codeViewer: true, - issueAdmin: true, - securityHotspotAdmin: true, - admin: true, - scan: true, - }, +const githubMappingMock = ( + id: string, + permissions: (keyof GitHubMapping['permissions'])[], + isBaseRole = false, +) => ({ + id, + githubRole: id, + isBaseRole, + permissions: { + user: permissions.includes('user'), + codeViewer: permissions.includes('codeViewer'), + issueAdmin: permissions.includes('issueAdmin'), + securityHotspotAdmin: permissions.includes('securityHotspotAdmin'), + admin: permissions.includes('admin'), + scan: permissions.includes('scan'), }, +}); + +const defaultMapping: GitHubMapping[] = [ + githubMappingMock('read', ['user', 'codeViewer'], true), + githubMappingMock( + 'write', + ['user', 'codeViewer', 'issueAdmin', 'securityHotspotAdmin', 'scan'], + true, + ), + githubMappingMock('triage', ['user', 'codeViewer'], true), + githubMappingMock( + 'maintain', + ['user', 'codeViewer', 'issueAdmin', 'securityHotspotAdmin', 'scan'], + true, + ), + githubMappingMock( + 'admin', + ['user', 'codeViewer', 'issueAdmin', 'securityHotspotAdmin', 'admin', 'scan'], + true, + ), ]; export default class AuthenticationServiceMock { @@ -266,21 +241,7 @@ export default class AuthenticationServiceMock { }; addGitHubCustomRole = (id: string, permissions: (keyof GitHubMapping['permissions'])[]) => { - this.githubMapping = [ - ...this.githubMapping, - { - id, - githubRole: id, - permissions: { - user: permissions.includes('user'), - codeViewer: permissions.includes('codeViewer'), - issueAdmin: permissions.includes('issueAdmin'), - securityHotspotAdmin: permissions.includes('securityHotspotAdmin'), - admin: permissions.includes('admin'), - scan: permissions.includes('scan'), - }, - }, - ]; + this.githubMapping = [...this.githubMapping, githubMappingMock(id, permissions)]; }; reset = () => { -- 2.39.5