[quality] add 23 tests for useTeams hook — CRUD, demo mode, error handling#19728
[quality] add 23 tests for useTeams hook — CRUD, demo mode, error handling#19728clubanderson wants to merge 1 commit into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
✅ Deploy Preview for kubestellarconsole ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
👋 Hey @clubanderson — thanks for opening this PR!
This is an automated message. |
|
🐝 Hi @clubanderson! I'm Trusted users — org members and contributors with write access — can mention Automation may take a moment to start, and follow-up happens through workflow activity rather than chat replies. |
✅ Test Coverage CheckAll new source files in this PR have corresponding test files. Checked |
There was a problem hiding this comment.
Pull request overview
Adds a comprehensive Vitest unit test suite for useTeams / useTeamDetail hooks, which are responsible for team CRUD and member management in both demo mode (local state mutations) and API mode (server calls + refetch).
Changes:
- Introduces 23 new tests covering demo-mode behavior and API-mode success/error paths for team list and team detail hooks.
- Adds API mocking (
api.get/post/put/delete) and demo-mode mocking (getDemoMode) to exercise both branches deterministically.
| await act(async () => { | ||
| success = await result.current.addMember('u2', 'member') | ||
| }) | ||
|
|
||
| expect(success).toBe(true) | ||
| expect(mockApi.post).toHaveBeenCalledWith('/api/teams/t1/members', { userId: 'u2', role: 'member' }) | ||
| }) |
| mockApi.delete.mockResolvedValueOnce({}) | ||
| mockApi.get.mockResolvedValueOnce({ data: { ...detail, memberCount: 1, members: [{ userId: 'u1' }] } }) | ||
|
|
||
| let success: boolean | undefined | ||
| await act(async () => { | ||
| success = await result.current.removeMember('u2') | ||
| }) | ||
|
|
||
| expect(success).toBe(true) | ||
| expect(mockApi.delete).toHaveBeenCalledWith('/api/teams/t1/members/u2') | ||
| }) |
| mockApi.put.mockResolvedValueOnce({}) | ||
| mockApi.get.mockResolvedValueOnce({ data: { ...detail, name: 'New' } }) | ||
|
|
||
| let success: boolean | undefined | ||
| await act(async () => { | ||
| success = await result.current.updateTeam({ name: 'New' }) | ||
| }) | ||
|
|
||
| expect(success).toBe(true) | ||
| expect(mockApi.put).toHaveBeenCalledWith('/api/teams/t1', { name: 'New' }) | ||
| }) |
f6b7383 to
fc4d1ee
Compare
…ndling) - useTeams: demo mode returns/create/delete, API fetch/error/non-array, createTeam success/failure, deleteTeam success/failure - useTeamDetail: null teamId, demo mode lookup/addMember/removeMember/update, API fetch/error, addMember/removeMember/updateTeam with refetch, failure paths Signed-off-by: Quality Agent <quality-agent@kubestellar.io>
fc4d1ee to
b61e23e
Compare
Test Improvement
Adds 23 unit tests for the previously untested
useTeams.tshook (208 lines, 0% coverage).useTeams hook (10 tests)
useTeamDetail hook (13 tests)
Why this matters
useTeams.tsis the primary hook for team CRUD operations. It handles:All paths (success + failure) for both demo and API modes are now covered.
Filed by quality agent (hold-gated mode). Human review required.