Skip to content

Implementar Testes de Unidade para Alunos (Tarefa 02)#98

Merged
EmiyaKiritsugu3 merged 3 commits into
mainfrom
task/97
May 6, 2026
Merged

Implementar Testes de Unidade para Alunos (Tarefa 02)#98
EmiyaKiritsugu3 merged 3 commits into
mainfrom
task/97

Conversation

@EmiyaKiritsugu3
Copy link
Copy Markdown
Owner

@EmiyaKiritsugu3 EmiyaKiritsugu3 commented May 5, 2026

Testes de unidade para CRUD de alunos. Resolve #97

Summary by CodeRabbit

  • Tests
    • Added comprehensive test suite validating CRUD operations for alunos with authorization checks and path revalidation handling.

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 5, 2026

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

Project Deployment Actions Updated (UTC)
smartmanagementsystem Ready Ready Preview, Comment May 6, 2026 4:55am

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 5, 2026

Warning

Rate limit exceeded

@EmiyaKiritsugu3 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 54 minutes and 47 seconds before requesting another review.

To continue reviewing without waiting, purchase usage credits 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: d330f824-2acc-4535-897f-8f2dc771b893

📥 Commits

Reviewing files that changed from the base of the PR and between e8a78fb and 4df9850.

📒 Files selected for processing (1)
  • src/lib/actions/alunos.test.ts

Walkthrough

A new Vitest-based test file is added that validates CRUD actions for alunos (students). The suite mocks Prisma, authentication, revalidation, and error tracking dependencies to test successful and unauthorized create, update, and delete operations.

Changes

Alunos Actions Test Suite

Layer / File(s) Summary
Test Setup & Mocks
src/lib/actions/alunos.test.ts (lines 1–41)
Test file initialization with mocks for Prisma client (aluno.create/update/delete), getUser, revalidatePath, and captureException. Test suite constants (mockAdmin, validId) and beforeEach hook established.
CRUD Operation Tests
src/lib/actions/alunos.test.ts (lines 42–116)
Four test cases covering createAlunoAction (success and unauthorized paths), updateAlunoAction success, and deleteAlunoAction success. Each verifies correct Prisma method invocation and revalidatePath calls to /dashboard/alunos.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is minimal, containing only a brief statement and issue reference. It does not follow the provided template structure with sections for Type of Change, Related Documents, or Checklist. Add the missing sections from the template: specify 'test' as the Type of Change, link the related User Story/issue #97, and complete the pre-merge checklist items.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: implementing unit tests for alunos (students) with task reference 02, directly matching the changeset that adds a new test file.
Linked Issues check ✅ Passed The pull request successfully implements unit tests for CRUD actions of alunos using Vitest with mocked dependencies (Prisma, Supabase, Next.js, Sentry), fully satisfying the requirements of issue #97.
Out of Scope Changes check ✅ Passed The pull request contains only the new test file for alunos CRUD actions, which is entirely within scope of the linked issue #97 requirement to implement unit tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch task/97

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
src/lib/actions/alunos.test.ts (2)

1-1: ⚡ Quick win

Remove broad any suppression and type mocks explicitly.

The file-level disable plus repeated as any weakens strict TS guarantees in tests. Prefer typed mock helpers/casts scoped to each mock instead of disabling the rule globally.

Proposed typed approach
-/* eslint-disable `@typescript-eslint/no-explicit-any` */
 import { describe, it, expect, vi, beforeEach } from 'vitest';
+import type { MockedFunction } from 'vitest';
 ...
   beforeEach(() => {
     vi.clearAllMocks();
-    vi.mocked(getUser).mockResolvedValue(mockAdmin as any);
+    (getUser as MockedFunction<typeof getUser>).mockResolvedValue(mockAdmin);
   });
 ...
-      vi.mocked(prisma.aluno.create).mockResolvedValue(mockCreatedAluno as any);
+      vi.mocked(prisma.aluno.create).mockResolvedValue(mockCreatedAluno);
 ...
-      vi.mocked(getUser).mockResolvedValue({ user: null, error: null } as any);
-      const result = await createAlunoAction({} as any);
+      (getUser as MockedFunction<typeof getUser>).mockResolvedValue({ user: null, error: null });
+      const result = await createAlunoAction({
+        nomeCompleto: '',
+        cpf: '',
+        email: '',
+        telefone: '',
+        statusMatricula: 'ATIVA',
+      });
 ...
-      vi.mocked(prisma.aluno.update).mockResolvedValue(mockUpdatedAluno as any);
+      vi.mocked(prisma.aluno.update).mockResolvedValue(mockUpdatedAluno);
As per coding guidelines, "Use TypeScript 5 in strict mode" and "All code changes must pass `npm run lint` (ESLint quality gate) before merging".

Also applies to: 39-39, 62-62, 73-74, 93-93

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/actions/alunos.test.ts` at line 1, Remove the file-level eslint
disable at the top of src/lib/actions/alunos.test.ts and replace each broad "as
any" mock with properly typed test mocks scoped to that usage (e.g., use
jest.Mocked<YourServiceType>, typed helper functions like createMock<T>(), or
"as unknown as ExpectedType" per case) where the test currently casts
dependencies; update the specific mock instances (the occurrences flagged in the
comment) to use those typed helpers/casts so ESLint no-explicit-any is not
needed globally and each mock preserves correct types for the functions under
test.

80-117: ⚡ Quick win

Add unauthorized tests for updateAlunoAction and deleteAlunoAction.

Both actions enforce the same auth guard as create; adding those two negative-path tests will complete CRUD auth coverage and prevent regressions.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/actions/alunos.test.ts` around lines 80 - 117, Add negative-path
tests that assert updateAlunoAction and deleteAlunoAction return an unauthorized
failure and do not call the DB or revalidation when the auth guard denies
access: in the alunos.test.ts suite, create tests for updateAlunoAction(validId,
updateData) and deleteAlunoAction(validId) where you mock the auth/session to be
unauthenticated (same mechanism used in create tests), assert result.success is
false (or the expected unauthorized shape), assert prisma.aluno.update /
prisma.aluno.delete were not called, and assert revalidatePath was not called
for delete; use the existing symbols updateAlunoAction, deleteAlunoAction,
prisma.aluno.update, prisma.aluno.delete, and revalidatePath to locate the code
to mock and assert against.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/lib/actions/alunos.test.ts`:
- Line 1: Remove the file-level eslint disable at the top of
src/lib/actions/alunos.test.ts and replace each broad "as any" mock with
properly typed test mocks scoped to that usage (e.g., use
jest.Mocked<YourServiceType>, typed helper functions like createMock<T>(), or
"as unknown as ExpectedType" per case) where the test currently casts
dependencies; update the specific mock instances (the occurrences flagged in the
comment) to use those typed helpers/casts so ESLint no-explicit-any is not
needed globally and each mock preserves correct types for the functions under
test.
- Around line 80-117: Add negative-path tests that assert updateAlunoAction and
deleteAlunoAction return an unauthorized failure and do not call the DB or
revalidation when the auth guard denies access: in the alunos.test.ts suite,
create tests for updateAlunoAction(validId, updateData) and
deleteAlunoAction(validId) where you mock the auth/session to be unauthenticated
(same mechanism used in create tests), assert result.success is false (or the
expected unauthorized shape), assert prisma.aluno.update / prisma.aluno.delete
were not called, and assert revalidatePath was not called for delete; use the
existing symbols updateAlunoAction, deleteAlunoAction, prisma.aluno.update,
prisma.aluno.delete, and revalidatePath to locate the code to mock and assert
against.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b6a5369a-0836-4273-8843-78b57d9d2a87

📥 Commits

Reviewing files that changed from the base of the PR and between cbb951e and e8a78fb.

📒 Files selected for processing (1)
  • src/lib/actions/alunos.test.ts

@EmiyaKiritsugu3 EmiyaKiritsugu3 merged commit 25d7f0f into main May 6, 2026
10 checks passed
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.

Implementar Testes de Unidade para Alunos (Tarefa 02)

1 participant