diff options
Diffstat (limited to 'server/sonar-web/src/main/js/api/mocks/UsersServiceMock.ts')
-rw-r--r-- | server/sonar-web/src/main/js/api/mocks/UsersServiceMock.ts | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/server/sonar-web/src/main/js/api/mocks/UsersServiceMock.ts b/server/sonar-web/src/main/js/api/mocks/UsersServiceMock.ts index f575559c69a..0c8c719732c 100644 --- a/server/sonar-web/src/main/js/api/mocks/UsersServiceMock.ts +++ b/server/sonar-web/src/main/js/api/mocks/UsersServiceMock.ts @@ -19,7 +19,7 @@ */ import { cloneDeep } from 'lodash'; -import { mockClusterSysInfo, mockIdentityProvider } from '../../helpers/testMocks'; +import { mockClusterSysInfo, mockIdentityProvider, mockUser } from '../../helpers/testMocks'; import { IdentityProvider, Paging, SysInfoCluster } from '../../types/types'; import { User } from '../../types/users'; import { getSystemInfo } from '../system'; @@ -27,26 +27,44 @@ import { getIdentityProviders, searchUsers } from '../users'; export default class UsersServiceMock { isManaged = true; + users = [ + mockUser({ + managed: true, + login: 'bob.marley', + name: 'Bob Marley', + }), + mockUser({ + managed: false, + login: 'alice.merveille', + name: 'Alice Merveille', + }), + ]; constructor() { jest.mocked(getSystemInfo).mockImplementation(this.handleGetSystemInfo); jest.mocked(getIdentityProviders).mockImplementation(this.handleGetIdentityProviders); - jest.mocked(searchUsers).mockImplementation(this.handleSearchUsers); + jest.mocked(searchUsers).mockImplementation((p) => this.handleSearchUsers(p)); } setIsManaged(managed: boolean) { this.isManaged = managed; } - handleSearchUsers = (): Promise<{ paging: Paging; users: User[] }> => { - return this.reply({ - paging: { - pageIndex: 1, - pageSize: 100, - total: 0, - }, - users: [], - }); + handleSearchUsers = (data: any): Promise<{ paging: Paging; users: User[] }> => { + const paging = { + pageIndex: 1, + pageSize: 100, + total: 0, + }; + + if (this.isManaged) { + if (data.managed === undefined) { + return this.reply({ paging, users: this.users }); + } + const users = this.users.filter((user) => user.managed === data.managed); + return this.reply({ paging, users }); + } + return this.reply({ paging, users: this.users }); }; handleGetIdentityProviders = (): Promise<{ identityProviders: IdentityProvider[] }> => { |