test(ui): migrate test mocks from hooks to @/client/sdk.gen - #6933
Draft
luizhf42 wants to merge 3 commits into
Draft
test(ui): migrate test mocks from hooks to @/client/sdk.gen#6933luizhf42 wants to merge 3 commits into
@/client/sdk.gen#6933luizhf42 wants to merge 3 commits into
Conversation
Code Review CompleteThe automated review ran but did not post an updated summary — this usually means no new issues were found since the previous review. If you've pushed changes and want a fresh pass, comment |
Replace `vi.mock("@/client")` and `vi.mock("@/hooks/use*")` with
`vi.mock("@/client/sdk.gen")` so real generated factories and
`paginatedQueryFn` run through the mocked SDK layer. Drop redundant
`vi.mock("@/api/pagination")` and `vi.mock("@/api/errors")` calls.
Replace `vi.mock("@/hooks/use*")` with `vi.mock("@/client/sdk.gen")` so
real hooks run through React Query against the mocked SDK layer. Add
shared tag factories in `mockTags.ts` and extend `factories.ts`.
Replace hook mocks (`vi.mock("@/hooks/useXxx")`) with SDK-level mocks
(`vi.mock("@/client/sdk.gen")`) across 16 page test files so the real
hooks execute and only the network boundary is faked.
Key changes beyond the mock-seam swap:
- Shared `paginatedResponse` helper in `@/tests/sdk.ts` replaces the
repeated `mockSdkResponse(data, { "X-Total-Count": "N" })` pattern
- `mockTags` from `@/tests/mockTags` reused in RuleDrawer and KeyDrawer
- Factories: `mockDevice`/`mockSession` compose (shared uid, tenant_id),
no `as` casts, all required fields filled
- `useHasPermission` mocks → `useAuthStore.setState({ role })` (3 files)
- `useSessionRecording` mock → `getSessionRecord` SDK mock
- Imports moved above `vi.mock()` blocks (vitest hoists automatically)
- `getBy` → `findBy` for assertions on async-rendered data
luizhf42
force-pushed
the
test/ui/fix-generated-client-mocks
branch
from
August 21, 2026 21:09
a5fa94b to
f93b3df
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Warning
WIP — covers 20 of ~63 test files. The remaining ~43 mock hooks (not the barrel) and need deeper refactoring where each hook mock is traced to its underlying SDK call. This branch will incrementally receive the remaining changes.
What
Migrated 20 test files from mocking
@/clientbarrel or@/hooks/use*to mocking@/client/sdk.gendirectly, which is the correct seam for the generated SDK layer.Why
The
@/clientbarrel mock replaces the entire module, but generated*Optionshelpers import from../sdk.geninternally — so barrel mocks don't intercept them. Mocking@/client/sdk.genwithimportOriginalensures all code paths hit the mock.Part of shellhub-io/team#216.
Changes
sdkError.tsintomakeSdkError, renameduserAuth.tstofactories.ts, addedmockNamespace/mockTagfactories and sharedmockTagshelper@tanstack/react-query.gen,types.gen) to the barrel (@/client)sdk.genmocks; replaceduseHasPermissionmocks withuseAuthStore.setState({ role })sdk.genmocks; removed banner comments andas nevercastsRemaining (~43 files)
*Options/*Mutation/*QueryKeyfactories +paginatedQueryFnuseChatwoot) that mocks other hooks