test(ui): migrate test mocks from hooks to @/client/sdk.gen - #6933
Merged
Conversation
luizhf42
marked this pull request as draft
August 20, 2026 20:51
luizhf42
force-pushed
the
test/ui/fix-generated-client-mocks
branch
2 times, most recently
from
August 24, 2026 11:56
f93b3df to
8ae3351
Compare
Add entity factories (`mockDevice`, `mockContainer`, `mockNamespace`, etc.), `seedAuthStore` for populating the auth Zustand store from factory data, `mockTags`/`mockNamespaces` helpers, and the `paginatedResponse` SDK helper to `src/tests/`.
luizhf42
force-pushed
the
test/ui/fix-generated-client-mocks
branch
from
August 24, 2026 17:04
8ae3351 to
c2adde7
Compare
luizhf42
marked this pull request as ready for review
August 24, 2026 17:07
Member
|
/review |
1 similar comment
Member
|
/review |
|
Claude finished @otavio's task in 9m 35s —— View job Code Review CompleteReviewed the test-migration diff (100+ files) across code quality, security, testing, language patterns, and architecture — no new issues found. The code looks good as-is. A few notes for context (not blocking, no action required):
If you push additional changes and want a new review, tag |
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.
What
Migrated all 93 test files from mocking the
@/clientbarrel or@/hooks/use*to mocking@/client/sdk.gendirectly, and consolidated the per-file mock boilerplate into a sharedmockSdkGenhelper.Closes shellhub-io/team#216.
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. Moving thevi.mockfactory into a global helper (mockSdkGen) eliminates ~1200 lines of duplicated boilerplate across 93 files.Changes
Shared test infrastructure (
src/tests/)mockSdkGenglobal (defined insetup.ts, typed inglobals.d.ts): receives an object of{sdkFn: vi.fn()}entries, callsvi.doMockinternally, returns the mocks. Usage:const sdk = vi.hoisted(() => mockSdkGen({...}))— one call replaces the per-filevi.hoisted+vi.mockboilerplateseedAuthStore(overrides?): seeds the Zustand auth store frommockUserAuth()factory data; replaces alluseAuthStorecustom mocks anduseHasPermissionmockspaginatedResponse(items[], total?): wraps list data withX-Total-Countheader; replaces 6 localpaginatedSdkResponsehelperscreateTestWrapper(opts?):QueryClientProvider+ optionalMemoryRouterwithretry: false; replaces ~25createWrapper()/makeWrapper()copiesfactories.ts:mockDevice,mockContainer,mockNamespace,mockTag,mockFirewallRule,mockPublicKey,mockWebEndpoint,mockAccessPolicy,mockSubscription,mockCustomer,mockLicense,mockInvitation,mockServiceAccount,mockSshIdentity,mockInstallKey,mockUserAuth,mockAnnouncementFull,mockStatsMock seam migration (93 files)
@/clientbarrel mocks to@/client/sdk.genviamockSdkGenuseDevices,useNamespaces,useHasPermission,useBilling,useStats,useLatestAnnouncement, etc. with SDK-level mocks +seedAuthStore()AcceptDevicefrom inline sync factory tomockSdkGenpatternCleanup
as nevercasts — mock data satisfies types via factoriespaginatedSdkResponsedefinitionsuseInvitations.test.tsrelative import (../../client→@/tests/sdk)What stays mocked at the hook level
Pure utility hooks with no API call are still mocked directly:
useDeviceActions,useContainerActions,useSidebarLayout,useOtpInput,useCopy,useResetOnOpen,useDebouncedValue,useBrowserKey. Non-TQ store mocks also stay:useTerminalStore,useVaultStore,signUpStore.