Skip to content

Commit

Permalink
test(mrc): ensure useAuthorizationIam query option enabled is a boole…
Browse files Browse the repository at this point in the history
…an (#14322)

ref: 13791

Signed-off-by: Jacques Larique <[email protected]>
  • Loading branch information
JacquesLarique authored Nov 28, 2024
1 parent b55369d commit 8027456
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 9 deletions.

This file was deleted.

68 changes: 68 additions & 0 deletions packages/manager-react-components/src/hooks/iam/useOvhIam.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { renderHook } from '@testing-library/react';
import { vi } from 'vitest';
import { QueryClientProvider, QueryClient } from '@tanstack/react-query';
import {
ShellContext,
ShellContextType,
} from '@ovh-ux/manager-react-shell-client';
import { getAuthorizationCheckUrl, useAuthorizationIam } from './useOvhIam';

const shellContext = {
environment: {
getUser: () => ({ ovhSubsidiary: 'mocked_ovhSubsidiary' }),
},
shell: {
navigation: {
getURL: vi.fn(),
},
},
};

const queryClient = new QueryClient();
const wrapper = ({ children }) => (
<QueryClientProvider client={queryClient}>
<ShellContext.Provider value={shellContext as unknown as ShellContextType}>
{children}
</ShellContext.Provider>
</QueryClientProvider>
);

vi.mock('@ovh-ux/manager-core-api', () => ({
apiClient: {
v2: {
get: vi.fn(),
},
},
}));

describe('getAuthorizationCheckUrl', () => {
it('encodes the urn if it contains /', () => {
expect(getAuthorizationCheckUrl('test/urn')).toBe(
'/iam/resource/test%2Furn/authorization/check',
);
});
});

describe('useAuthorizationIam', () => {
it('should not fetch data if urn is nil', () => {
const { result } = renderHook(
() => useAuthorizationIam(['test'], undefined),
{
wrapper,
},
);
expect(result.current?.isFetching).toBe(false);
});
it('should not fetch data if actions is nil', () => {
const { result } = renderHook(() => useAuthorizationIam(undefined, 'urn'), {
wrapper,
});
expect(result.current?.isFetching).toBe(false);
});
it('should fetch data if both actions and urn are not nil', () => {
const { result } = renderHook(() => useAuthorizationIam(['test'], 'urn'), {
wrapper,
});
expect(result.current?.isFetching).toBe(true);
});
});

0 comments on commit 8027456

Please sign in to comment.