fix(tests): mocks completos do supabase client + authService + hooks/admin — #59#89
Conversation
…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
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Rate limit exceeded
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 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
There was a problem hiding this comment.
💡 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() }), |
There was a problem hiding this comment.
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 👍 / 👎.
Summary
Fix do issue #59:
Test Coveragefalhava em todos os PRs com 9+ erros vindos de mocks incompletos emtests/components/render-helpers.tsx.Mocks faltantes adicionados
@/integrations/supabase/client(from()builder).like(),.ilike(),.gt(),.gte(),.lt(),.lte(),.is(),.not(),.or(),.match(),.contains(),.containedBy(),.overlaps(),.range(),.upsert()supabase.authsignOut,signInWithPassword,signInWithOAuth,signUp,refreshSession,resetPasswordForEmail,updateUser,mfa.{getAuthenticatorAssuranceLevel, listFactors, enroll, challenge, verify, unenroll},getClaimssupabase.storage.fromupload,download,remove,list,getPublicUrl,createSignedUrl@/hooks/admin(novo mock)useDevGate,useIPValidation,useAllowedIPs,useIPValidationConfig@/services/authService(novo mock)signOut+ todos os outros (signIn,fetchAAL,queryRoles,fetchProfile,updateLastLogin)Erros que esse PR resolve (do CI #59)
No 'useDevGate' export is defined on the '@/hooks/admin' mockauthService.signOut is not a functionsupabase.from(...).select(...).like is not a functionsupabase.rpc is not a function(em testes que importam direto do client)Resta para o time
window is not definedemRolePermissionsPage.tsx:74— tests que rodam em ambientenodedeveriam ter/* @vitest-environment jsdom */. Não é cross-cutting: fix per-file.Test plan
Test Coveragejob e confirmar redução de falhas para apenas os casoswindow is not defined(per-file fix posterior)tests/components/pages/Auth.test.tsxagora passa (era um dos casos do issue)Notas
Não cobre:
tests/setup.tsou outros setup files. Apenastests/components/render-helpers.tsxque é usado viarenderWithProviders. Tests emsrc/contexts/AuthContext.test.tsxcontinuam 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.from()chain (filters, order, range,upsert) withsingle/maybeSingle/then;authflow (sign-in/out, refresh, reset, update,mfa.*,getClaims);rpc; andstorage.from(...).@/hooks/admin(dev gate + IP validation) and@/services/authService(signOut, signIn, roles, profile, last-login).useDevGate,authService.signOut,.like()chain, andrpc./* @vitest-environment jsdom */to fix "window is not defined" per file.Written for commit cae14c8. Summary will update on new commits. Review in cubic