Skip to content

[quality] add 23 tests for useTeams hook — CRUD, demo mode, error handling#19728

Open
clubanderson wants to merge 1 commit into
mainfrom
quality/test-useTeams
Open

[quality] add 23 tests for useTeams hook — CRUD, demo mode, error handling#19728
clubanderson wants to merge 1 commit into
mainfrom
quality/test-useTeams

Conversation

@clubanderson

Copy link
Copy Markdown
Collaborator

Test Improvement

Adds 23 unit tests for the previously untested useTeams.ts hook (208 lines, 0% coverage).

useTeams hook (10 tests)

Category Tests What's covered
Demo mode 3 Returns demo teams without API call, createTeam adds locally, deleteTeam removes locally
API mode 7 Fetch on mount, error handling, non-array response, createTeam success/failure, deleteTeam success/failure

useTeamDetail hook (13 tests)

Category Tests What's covered
Null teamId 1 Returns null without loading
Demo mode 5 Lookup by ID, unknown ID returns null, addMember, removeMember, updateTeam
API mode 7 Fetch detail, error handling, addMember/removeMember/updateTeam with refetch, failure paths

Why this matters

useTeams.ts is the primary hook for team CRUD operations. It handles:

  • Demo mode branching (local state mutations vs API calls)
  • Error state management
  • Optimistic/pessimistic update patterns
  • Member management (add/remove with role assignment)

All paths (success + failure) for both demo and API modes are now covered.


Filed by quality agent (hold-gated mode). Human review required.

Copilot AI review requested due to automatic review settings June 26, 2026 13:37
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Jun 26, 2026
@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign mikespreitzer for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@netlify

netlify Bot commented Jun 26, 2026

Copy link
Copy Markdown

Deploy Preview for kubestellarconsole ready!

Name Link
🔨 Latest commit b61e23e
🔍 Latest deploy log https://app.netlify.com/projects/kubestellarconsole/deploys/6a3fbbf1bd884d00081e8c5b
😎 Deploy Preview https://deploy-preview-19728.console-deploy-preview.kubestellar.io
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@clubanderson clubanderson added hold Blocked — do not touch quality testing and removed dco-signoff: yes Indicates the PR's author has signed the DCO. labels Jun 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

👋 Hey @clubanderson — thanks for opening this PR!

🤖 This project is developed exclusively using AI coding assistants.

Please do not attempt to code anything for this project manually.
All contributions should be authored using an AI coding tool such as:

This ensures consistency in code style, architecture patterns, test coverage,
and commit quality across the entire codebase.


This is an automated message.

@github-actions

Copy link
Copy Markdown
Contributor

🐝 Hi @clubanderson! I'm kubestellar-hive[bot], an automation bot for this repo.

Trusted users — org members and contributors with write access — can mention @kubestellar-hive in a comment to trigger repo automation.
On issues, that mention queues an automated fix attempt. On pull requests, it records extra context for existing automation.
This is not an interactive Q&A bot, so mentions should be treated as requests for automation rather than a conversation.

Automation may take a moment to start, and follow-up happens through workflow activity rather than chat replies.

@kubestellar-prow kubestellar-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

✅ Test Coverage Check

All new source files in this PR have corresponding test files.

Checked web/src/hooks/ and web/src/components/ against origin/main.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +286 to +292
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' })
})
Comment on lines +301 to +311
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')
})
Comment on lines +320 to +330
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' })
})
@kubestellar-hive kubestellar-hive Bot force-pushed the quality/test-useTeams branch from f6b7383 to fc4d1ee Compare June 26, 2026 14:40
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Jun 26, 2026
…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>
@kubestellar-hive kubestellar-hive Bot force-pushed the quality/test-useTeams branch from fc4d1ee to b61e23e Compare June 27, 2026 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates the PR's author has signed the DCO. hold Blocked — do not touch quality size/L Denotes a PR that changes 100-499 lines, ignoring generated files. testing tier/1-lightweight

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants