feat(admin-ui): add test files for all hooks across the system (#2895)#2911
Conversation
Signed-off-by: faisalsiddique4400 <faisalsiddique10886@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (19)
📝 WalkthroughWalkthroughAdds Jest and React Testing Library coverage across admin-ui hook modules in app routes, admin plugins, auth-server plugins, SAML, scripts, user-claims, and user-management. No production code changes are included. ChangesApp-level hook tests
Admin plugin hook tests
Auth-server plugin hook tests
SAML, scripts, user-claims, and user-management hook tests
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 17
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@admin-ui/app/routes/Apps/Profile/hooks/__tests__/useProfileDetails.test.tsx`:
- Around line 125-132: The test in useProfileDetails currently only covers the
implicit false case when userInum is undefined, so it does not verify that the
hook respects the enabled argument. Add a new test around useProfileDetails and
mockUseGetUserByInum that passes a valid userInum with enabled=false, then
assert opts.query.enabled is false to cover the explicit disabled branch.
In `@admin-ui/app/routes/License/hooks/__tests__/useLicenseDetails.test.tsx`:
- Around line 20-24: The `useLicenseConfigDelete` mock in
`useLicenseDetails.test.tsx` hides the mutation callbacks, so the
`useLicenseDetails` reset-flow success/error behavior is never covered. Update
the mock to capture the passed mutation options from `useLicenseConfigDelete`
and expose them in the test, then add assertions that explicitly invoke
`capturedDeleteOptions?.mutation?.onSuccess?.()` and
`capturedDeleteOptions?.mutation?.onError?.(...)` to verify the side effects in
`useLicenseDetails` such as query invalidation, audit posting, toast dispatch,
and `onResetSuccess`.
In
`@admin-ui/plugins/admin/components/Assets/hooks/__tests__/useAssetAudit.test.ts`:
- Around line 62-81: The `useAssetAudit.logAction()` test is too weak because it
only verifies `postUserAction` was called, not that the enriched audit payload
was posted after `addAdditionalData(...)`. Update the `useAssetAudit` test to
have `mockAddAdditionalData` mutate/enrich the audit object, or assert the exact
argument passed to `mockPostUserAction`, using the `logAction` flow and the
`mockAddAdditionalData` / `mockPostUserAction` symbols to locate the check. This
should ensure the test validates the final audit object rather than an
unmodified init payload.
In
`@admin-ui/plugins/admin/components/Assets/hooks/__tests__/useAssetMutations.test.tsx`:
- Around line 151-170: The delete success test for useDeleteAssetWithAudit is
missing coverage for the asset-list cache refresh. Update the test to assert
that invalidateQueriesByKey is triggered via mockInvalidate with the
GetAllAssets query key (the ['/api/v1/jans-assets'] key returned by
getGetAllAssetsQueryKey), alongside the existing delete, audit, dispatch, and
onSuccess checks.
In
`@admin-ui/plugins/admin/components/Mapping/hooks/__tests__/useMappingApi.test.tsx`:
- Around line 25-31: The mocked queries in useMappingApi.test.tsx are sharing
the same refetch mock through the baseQuery object, which can make the refetch
assertions in useMappingApi false positives. Create a separate jest.fn() refetch
spy for each query mock instead of spreading the same baseQuery.refetch into all
three mocked responses, so each expectation verifies the correct query instance.
In
`@admin-ui/plugins/admin/components/Webhook/hooks/__tests__/useWebhookAudit.test.ts`:
- Around line 62-86: The useWebhookAudit.logAction test only verifies that
addAdditionalData is invoked, but it does not confirm that postUserAction
receives the enriched audit object. Update the test in useWebhookAudit.test.ts
to assert the exact payload passed to mockPostUserAction, using the same audit
object shape produced after addAdditionalData in useWebhookAudit.logAction, so
the test covers the hook’s actual contract rather than just call count.
In
`@admin-ui/plugins/admin/components/Webhook/hooks/__tests__/useWebhookMutations.test.tsx`:
- Around line 89-109: The success-path tests for useCreateWebhookWithAudit and
the delete hook are missing an explicit assertion for the feature-query refresh,
so they can pass even if invalidateWebhooksByFeatureQueries(queryClient) is
removed. Update the relevant tests in useWebhookMutations.test.tsx to mock and
assert invalidateWebhooksByFeatureQueries (or its downstream feature
invalidation effects) alongside the existing mockPostMutateAsync, mockLogAction,
and mockInvalidateByKey checks, using the hook names useCreateWebhookWithAudit
and the delete mutation hook to locate the cases.
In
`@admin-ui/plugins/auth-server/components/Scopes/hooks/__tests__/useScopeQueries.test.ts`:
- Around line 99-121: The pagination test for useScopeAttributes is too weak
because it only checks call count, so it would still pass even if getAttributes
keeps using the same cursor. Update the test to assert the paginated arguments
passed to mockGetAttributes, especially the startIndex progression between
calls, in addition to the final merged attributes. Use the useScopeAttributes
hook and the mockGetAttributes calls to verify the loop contract in
useScopeQueries rather than relying on mockResolvedValueOnce alone.
In
`@admin-ui/plugins/auth-server/components/Sessions/hooks/__tests__/useSessionMutations.test.tsx`:
- Around line 151-201: Add a dedicated test for the audit-failure branch in
useRevokeSessionWithAudit, since the current describe block only covers revoke
success and mutation failure. Extend the existing useRevokeSessionWithAudit
suite in useSessionMutations.test.tsx by mocking the revoke mutation to succeed
while making the audit logger reject, then assert the revoke still runs, the
warning/error toast flow is triggered correctly, and the expected fallback
callback behavior occurs. Use the existing symbols useRevokeSessionWithAudit,
mockLogAuditUserAction, mockRevokeMutateAsync, and mockUpdateToast to locate and
validate the branch.
In
`@admin-ui/plugins/auth-server/components/Ssa/hooks/__tests__/useSsaApi.test.tsx`:
- Around line 73-79: Restore the process-global fetch mock after the useSsaApi
test suite finishes, since the current beforeAll assignment to global.fetch
leaves later tests polluted and order-dependent. Update the test setup in
useSsaApi.test.tsx by saving the original fetch before overwriting it and
restoring it in an afterAll cleanup, alongside the existing jest.clearAllMocks
in beforeEach, so the suite leaves global state unchanged.
In
`@admin-ui/plugins/auth-server/components/Ssa/hooks/__tests__/useSsaValidationState.test.ts`:
- Around line 9-13: `makeFormik()` in the `useSsaValidationState.test.ts` test
helper is constructing an incomplete Formik object, so `useSsaValidationState()`
will crash when it reads `formik.values.is_expirable`. Update `makeFormik` to
include a valid `values` object matching `SsaFormValues` along with the existing
`touched` and `errors`, and adjust the test helper’s `FormikProps` typing/cast
so it reflects the full shape instead of hiding the missing field.
- Around line 16-82: The `useSsaValidationState` test suite is missing coverage
for the special `expirationDateError` branch, which is handled differently from
the other fields. Add a test in `useSsaValidationState` that exercises the
`is_expirable` gate and verifies the `expirationDate` error/message behavior
when `values.is_expirable` changes, so the custom branch is covered alongside
the existing field-mapping cases.
In
`@admin-ui/plugins/auth-server/hooks/__tests__/useAuthServerJsonProperties.test.tsx`:
- Around line 107-124: The mutation test for
usePatchAuthServerJsonPropertiesMutation only checks the toast and user onError
path, so it can miss a regression where the hook stops dispatching the error
action. Tighten the test by asserting the dispatched error action is emitted
when mockPatch rejects, alongside the existing mockUpdateToast and userOnError
expectations, using the same mutation flow in this test case.
In `@admin-ui/plugins/saml/components/hooks/__tests__/useSamlApi.test.tsx`:
- Around line 151-173: The useUpdateSamlConfiguration test covers the PUT,
webhook, and audit paths but misses the cache-refresh side effect. Update the
test in useSamlApi’s useUpdateSamlConfiguration block to assert that
getGetSamlPropertiesQueryKey() is invalidated after a successful mutateAsync
call, using the query client or invalidateQueries spy tied to the same
wrapper/store setup.
- Around line 152-173: The SAML hook tests are only asserting that dispatch was
called, which doesn’t verify the toast behavior in useUpdateSamlConfiguration or
the related error path. Update the assertions in the affected tests to check the
exact dispatched action type and payload from the toast action creator, so the
tests confirm the success and error toast variants rather than any Redux
dispatch.
- Around line 130-148: Add no-session coverage for the session-gated SAML query
hooks in useSamlApi.test.tsx. Extend the existing hook tests for
useIdentityProviders and useTrustRelationships so they also assert that when the
store has no session, the hooks stay disabled and mockGet is not called,
matching the hasSession-based gating already used by useSamlConfiguration. Use
the existing helpers like buildStore, createWrapper, renderHook, and the hook
names themselves to locate the affected tests.
In `@admin-ui/plugins/user-claims/hooks/__tests__/useAttributeApi.test.tsx`:
- Around line 167-184: Strengthen the failure-path coverage in
useCreateAttribute by asserting the actual contract, not just that mutate exists
or dispatch was called. In the mutate wrapper test, verify that the rejected
create call from useCreateAttribute().mutate is handled without throwing and
that the failure is logged or otherwise observed as expected, using the mutate
wrapper and mockPostMutateAsync as the key symbols. In the onError test, assert
the exact toast dispatch payload (or message/variant) produced by
postOptions.mutation.onError rather than only checking mockDispatch call count,
so changes to the error toast content will fail this suite.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: ff83b391-7f1e-491b-a5e7-45b652fc54f1
📒 Files selected for processing (37)
admin-ui/app/routes/Apps/Profile/hooks/__tests__/useProfileDetails.test.tsxadmin-ui/app/routes/Dashboards/hooks/__tests__/useDashboardLockStats.test.tsxadmin-ui/app/routes/License/hooks/__tests__/useLicenseDetails.test.tsxadmin-ui/app/utils/hooks/__tests__/useDebounce.test.tsadmin-ui/app/utils/hooks/__tests__/useFirstAuthorizedPath.test.tsxadmin-ui/app/utils/hooks/__tests__/useWebhookDialogAction.test.tsxadmin-ui/plugins/admin/components/Assets/hooks/__tests__/useAssetAudit.test.tsadmin-ui/plugins/admin/components/Assets/hooks/__tests__/useAssetMutations.test.tsxadmin-ui/plugins/admin/components/Assets/hooks/__tests__/useAssetQueries.test.tsxadmin-ui/plugins/admin/components/Health/hooks/__tests__/useFido2HealthStatus.test.tsxadmin-ui/plugins/admin/components/Health/hooks/__tests__/useHealthStatus.test.tsxadmin-ui/plugins/admin/components/MAU/hooks/__tests__/useMauStats.test.tsxadmin-ui/plugins/admin/components/Mapping/hooks/__tests__/useMappingApi.test.tsxadmin-ui/plugins/admin/components/Webhook/hooks/__tests__/useGetWebhook.test.tsxadmin-ui/plugins/admin/components/Webhook/hooks/__tests__/useWebhookAudit.test.tsadmin-ui/plugins/admin/components/Webhook/hooks/__tests__/useWebhookMutations.test.tsxadmin-ui/plugins/auth-server/components/AuthServerProperties/hooks/__tests__/useAuthServerScripts.test.tsadmin-ui/plugins/auth-server/components/Authentication/Acrs/hooks/__tests__/useAcrAudit.test.tsadmin-ui/plugins/auth-server/components/Authentication/AgamaFlows/hooks/__tests__/useAgamaActions.test.tsadmin-ui/plugins/auth-server/components/Logging/hooks/__tests__/useLoggingApi.test.tsxadmin-ui/plugins/auth-server/components/OidcClients/__tests__/hooks/useUpdateClient.test.tsadmin-ui/plugins/auth-server/components/Scopes/hooks/__tests__/useScopeActions.test.tsadmin-ui/plugins/auth-server/components/Scopes/hooks/__tests__/useScopeMutations.test.tsxadmin-ui/plugins/auth-server/components/Scopes/hooks/__tests__/useScopeQueries.test.tsadmin-ui/plugins/auth-server/components/Sessions/hooks/__tests__/useSessionMutations.test.tsxadmin-ui/plugins/auth-server/components/Ssa/hooks/__tests__/useSsaApi.test.tsxadmin-ui/plugins/auth-server/components/Ssa/hooks/__tests__/useSsaMutations.test.tsxadmin-ui/plugins/auth-server/components/Ssa/hooks/__tests__/useSsaValidationState.test.tsadmin-ui/plugins/auth-server/hooks/__tests__/useAuthServerJsonProperties.test.tsxadmin-ui/plugins/saml/components/hooks/__tests__/useSamlApi.test.tsxadmin-ui/plugins/scripts/components/hooks/__tests__/useCustomScriptApi.test.tsxadmin-ui/plugins/scripts/components/hooks/__tests__/useMutationEffects.test.tsadmin-ui/plugins/user-claims/hooks/__tests__/useAttributeApi.test.tsxadmin-ui/plugins/user-claims/hooks/__tests__/useMutationEffects.test.tsadmin-ui/plugins/user-claims/hooks/__tests__/useSchemaAuditLogger.test.tsadmin-ui/plugins/user-claims/hooks/__tests__/useSchemaWebhook.test.tsadmin-ui/plugins/user-management/hooks/__tests__/useUserMutations.test.tsx
Signed-off-by: faisalsiddique4400 <faisalsiddique10886@gmail.com>
|



feat(admin-ui): add test files for all hooks across the system (#2895)
Summary
This PR expands the Admin UI test suite by adding test files for hooks across the application that previously had no dedicated test coverage.
The goal is to improve confidence in shared business logic, reduce regression risk, and strengthen the overall Jest test suite by ensuring reusable hooks are independently validated.
Fix Summary
Verification
passes successfully.
🔗 Ticket
Closes: #2895
Summary by CodeRabbit