Skip to content

Conversation

kilnhast
Copy link
Collaborator

@kilnhast kilnhast commented Sep 28, 2025

Summary by CodeRabbit

  • Tests
    • Added comprehensive automated tests for polls: creating polls, listing polls, voting, and viewing results.
    • Covered edge cases such as missing users, missing polls, duplicate votes, and response shape validation.
    • Strengthens reliability and ensures consistent status codes and payloads for poll-related endpoints.
    • No user-facing changes; improves confidence in existing functionality.

Copy link
Contributor

coderabbitai bot commented Sep 28, 2025

Walkthrough

Introduces a Vitest suite for the polls API. It sets up a Fastify app, mocks PrismaClient methods and authentication, and tests endpoints: POST /polls, GET /polls, POST /polls/:id/vote, and GET /polls/:id/results, covering success and error cases with response shape and status assertions.

Changes

Cohort / File(s) Summary
Polls route tests
test/polls.test.ts
Adds comprehensive Vitest tests for polls routes; mocks PrismaClient (apiUser, poll, vote methods and groupBy) and auth; initializes Fastify and registers routes; verifies create/list/vote/results flows including 200/400/404 paths and payload shapes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor T as Test Suite (Vitest)
  participant A as Fastify App
  participant Auth as verifyWalletSignature (mock)
  participant DB as PrismaClient (mock)

  rect rgb(230,240,255)
  note over T,A: POST /polls (create)
  T->>A: POST /polls {title, options, ...}
  A->>Auth: verify signature
  Auth-->>A: ok
  A->>DB: apiUser.findUnique(wallet)
  alt user found
    A->>DB: poll.create(data)
    DB-->>A: poll
    A-->>T: 200 {poll}
  else user missing
    A-->>T: 404
  end
  end

  rect rgb(235,255,235)
  note over T,A: GET /polls (list)
  T->>A: GET /polls
  A->>DB: poll.findMany()
  DB-->>A: polls[]
  A-->>T: 200 {polls}
  end

  rect rgb(255,245,230)
  note over T,A: POST /polls/:id/vote
  T->>A: POST /polls/:id/vote {optionId}
  A->>DB: poll.findUnique(id)
  alt poll exists
    A->>DB: vote.findUnique(userId+pollId)
    alt not yet voted
      A->>DB: vote.create(...)
      DB-->>A: vote
      A-->>T: 200 {vote}
    else already voted
      A-->>T: 400
    end
  else missing poll
    A-->>T: 404
  end
  end

  rect rgb(255,235,245)
  note over T,A: GET /polls/:id/results
  T->>A: GET /polls/:id/results
  A->>DB: poll.findUnique(id)
  alt poll exists
    A->>DB: vote.groupBy(pollId, optionId, _count)
    DB-->>A: aggregated results
    A-->>T: 200 {results, totalVotes}
  else missing poll
    A-->>T: 404
  end
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I twitched my whiskers, tapped my keys,
Mocked a world with tests that tease.
Fastify burrows, Prisma’s tracks,
Votes and polls on tidy stacks.
Green dots bloom—my carrots’ hue—
Results hop in: 200s too!
Thump! The suite is proven true.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title precisely describes the core change by indicating that comprehensive tests are being added for the polls route and highlights the key operations of creation, retrieval, and voting, making it clear and specific for anyone reviewing the history.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch test/poll-unit-test

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
Contributor

@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.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 651c224 and 232b75d.

📒 Files selected for processing (1)
  • test/polls.test.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
test/polls.test.ts (1)
src/routes/polls.ts (1)
  • pollsRoute (14-278)

@metanodreamer metanodreamer merged commit 1a22b83 into main Sep 28, 2025
1 check 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.

2 participants