Skip to content

(SP: 3) [Testing] Add integration tests for quiz components and API #199

Closed

Description

@LesiaUKR

Week 6

Goal

Cover component interactions and API endpoints with integration tests (60% of testing strategy).

Scope

1. quiz-verify-answer.test.ts

  • POST /api/quiz/verify-answer
  • Returns isCorrect: true for correct answer
  • Returns isCorrect: false for wrong answer
  • Returns 400 for tampered encryptedAnswers
  • Returns correctAnswerId in response

2. quiz-countdown-timer.test.ts

  • CountdownTimer component with Testing Library
  • Calls onTimeUp when timer reaches zero
  • Displays correct remaining time
  • Handles language switch (startedAt prop)
  • Warning state when < 60 seconds

3. quiz-anticheat.test.ts

  • useAntiCheat hook
  • Detects copy event
  • Detects paste event
  • Detects tab switch (visibilitychange)
  • Does not track when isActive = false
  • resetViolations() clears state

Test utilities:

  • vi.useFakeTimers() for timer tests
  • renderHook() for hook tests
  • Mock fetch for API tests

Test location: lib/tests/quiz/

Expected impact

  • Verified component behavior
  • API contract validation
  • Regression prevention for critical flows

Out of scope

  • Full E2E flow tests
  • Database integration tests

Metadata

Metadata

Assignees

Labels

testingAutomated tests: unit, integration, E2E

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions