-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(mrc): ensure useAuthorizationIam query option enabled is a boole…
…an (#14322) ref: 13791 Signed-off-by: Jacques Larique <[email protected]>
- Loading branch information
1 parent
b55369d
commit 8027456
Showing
2 changed files
with
68 additions
and
9 deletions.
There are no files selected for viewing
9 changes: 0 additions & 9 deletions
9
packages/manager-react-components/src/hooks/iam/useOvhIam.spec.ts
This file was deleted.
Oops, something went wrong.
68 changes: 68 additions & 0 deletions
68
packages/manager-react-components/src/hooks/iam/useOvhIam.spec.tsx
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,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); | ||
}); | ||
}); |