Skip to content

fix(tests): mocks completos do supabase client + authService + hooks/admin — #59#89

Merged
adm01-debug merged 1 commit into
mainfrom
fix/issue-59-test-mocks
May 22, 2026
Merged

fix(tests): mocks completos do supabase client + authService + hooks/admin — #59#89
adm01-debug merged 1 commit into
mainfrom
fix/issue-59-test-mocks

Conversation

@adm01-debug
Copy link
Copy Markdown
Owner

@adm01-debug adm01-debug commented May 22, 2026

Summary

Fix do issue #59: Test Coverage falhava em todos os PRs com 9+ erros vindos de mocks incompletos em tests/components/render-helpers.tsx.

Mocks faltantes adicionados

Módulo O que faltava Resultado
@/integrations/supabase/client (from() builder) .like(), .ilike(), .gt(), .gte(), .lt(), .lte(), .is(), .not(), .or(), .match(), .contains(), .containedBy(), .overlaps(), .range(), .upsert() Builder chainable completo do supabase-js 2.x
supabase.auth signOut, signInWithPassword, signInWithOAuth, signUp, refreshSession, resetPasswordForEmail, updateUser, mfa.{getAuthenticatorAssuranceLevel, listFactors, enroll, challenge, verify, unenroll}, getClaims Cobre todo o fluxo auth
supabase.storage.from Builder com upload, download, remove, list, getPublicUrl, createSignedUrl Mock de storage estava ausente
@/hooks/admin (novo mock) useDevGate, useIPValidation, useAllowedIPs, useIPValidationConfig Auth.tsx, AdminLayout e siblings paravam de quebrar
@/services/authService (novo mock) signOut + todos os outros (signIn, fetchAAL, queryRoles, fetchProfile, updateLastLogin) AuthContext.signOut funciona em qualquer teste com renderWithProviders

Erros que esse PR resolve (do CI #59)

  • No 'useDevGate' export is defined on the '@/hooks/admin' mock
  • authService.signOut is not a function
  • supabase.from(...).select(...).like is not a function
  • supabase.rpc is not a function (em testes que importam direto do client)

Resta para o time

  • window is not defined em RolePermissionsPage.tsx:74 — tests que rodam em ambiente node deveriam ter /* @vitest-environment jsdom */. Não é cross-cutting: fix per-file.

Test plan

  • Após merge, rodar Test Coverage job e confirmar redução de falhas para apenas os casos window is not defined (per-file fix posterior)
  • Validar que testes existentes (DevOnlyBridgeOverlay, AuthContext etc.) continuam passando — esse mock é mais permissivo que o anterior, não restritivo
  • Verificar se tests/components/pages/Auth.test.tsx agora passa (era um dos casos do issue)

Notas

Não cobre: tests/setup.ts ou outros setup files. Apenas tests/components/render-helpers.tsx que é usado via renderWithProviders. Tests em src/contexts/AuthContext.test.tsx continuam com seus próprios mocks locais — não interferem.

https://claude.ai/code/session_011Lgxm1NZGmAztRSvZHX9U3


Generated by Claude Code


Summary by cubic

Fixes issue #59 by adding complete test mocks for @/integrations/supabase/client, @/services/authService, and @/hooks/admin. This prevents coverage jobs from failing on missing Supabase and auth methods.

  • Bug Fixes
    • Supabase client mock: full from() chain (filters, order, range, upsert) with single/maybeSingle/then; auth flow (sign-in/out, refresh, reset, update, mfa.*, getClaims); rpc; and storage.from(...).
    • New mocks: @/hooks/admin (dev gate + IP validation) and @/services/authService (signOut, signIn, roles, profile, last-login).
    • Resolves CI errors: missing useDevGate, authService.signOut, .like() chain, and rpc.
    • Note: some tests may still need /* @vitest-environment jsdom */ to fix "window is not defined" per file.

Written for commit cae14c8. Summary will update on new commits. Review in cubic

…admin — #59

Issue #59: o coverage job derruba PRs por mocks incompletos em tests/
components/render-helpers.tsx que NÃO cobrem:
  • supabase.from().select().like / .ilike / .gte / .lte / .gt / .lt / etc.
  • supabase.auth.signOut / signInWithPassword / refreshSession / mfa.*
  • supabase.rpc (já tinha, mas faltava terminação .then)
  • supabase.storage.from(...)
  • @/hooks/admin: useDevGate, useIPValidation, useAllowedIPs
  • @/services/authService.signOut + outros métodos

Após o fix, qualquer test que use renderWithProviders consegue importar
Auth.tsx (que chama useDevGate), AdminConexoesStatusPage (que chama
.like()), FailureWindowCard/AutoTestIntervalCard (que chamam .rpc()),
e qualquer página que dispara authService.signOut.

Backwards compat: o builder retornado por from() agora é compartilhado
entre métodos (chainável) e tem todos os terminais necessários.

https://claude.ai/code/session_011Lgxm1NZGmAztRSvZHX9U3
Copilot AI review requested due to automatic review settings May 22, 2026 09:39
@vercel
Copy link
Copy Markdown

vercel Bot commented May 22, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
we-dream-big Building Building Preview, Comment May 22, 2026 9:40am

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 22, 2026

Warning

Rate limit exceeded

@adm01-debug has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 12 minutes and 45 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5cc4aa08-a245-47f3-9530-e5da2dfb87ab

📥 Commits

Reviewing files that changed from the base of the PR and between 5684faf and cae14c8.

📒 Files selected for processing (1)
  • tests/components/render-helpers.tsx
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/issue-59-test-mocks

Comment @coderabbitai help to get the list of available commands and usage tips.

@adm01-debug adm01-debug merged commit 5734b92 into main May 22, 2026
18 of 22 checks passed
@supabase
Copy link
Copy Markdown

supabase Bot commented May 22, 2026

This pull request has been ignored for the connected project doufsxqlfjyuvxuezpln because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cae14c8aee

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

logLoginAttempt: vi.fn(),
fetchCurrentIP: vi.fn().mockResolvedValue("0.0.0.0"),
}),
useAllowedIPs: vi.fn().mockReturnValue({ ips: [], isLoading: false, refetch: vi.fn() }),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Return allowedIPs from useAllowedIPs mock

The new @/hooks/admin mock returns { ips: [] }, but the real useAllowedIPs contract exposes allowedIPs. Any test that imports render-helpers and renders code that uses useAllowedIPs via @/hooks/admin (for example useSecurityData/IPRestrictionManager) will get allowedIPs === undefined and can crash on allowedIPs.length, reintroducing mock-related test failures instead of preventing them.

Useful? React with 👍 / 👎.

@adm01-debug adm01-debug review requested due to automatic review settings May 22, 2026 10:00
@adm01-debug adm01-debug deleted the fix/issue-59-test-mocks branch May 24, 2026 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants