Spaces:
Runtime error
Runtime error
Candidate Test-Taking Flow - Implementation Complete
Overview
The complete candidate test-taking flow has been implemented, allowing candidates to take tests assigned to them through a public link.
What Was Implemented
Backend (Already Complete)
β
API Endpoints (backend/api/endpoints/candidate_tests.py):
GET /api/v1/candidate-tests/access/{test_result_id}- Check test accessPOST /api/v1/candidate-tests/start- Start test and get questionsPOST /api/v1/candidate-tests/submit- Submit answers and get resultsGET /api/v1/candidate-tests/result/{test_result_id}- View results
β
Router Registration (backend/api_app.py):
- Candidate tests router is registered and accessible
Frontend (Just Implemented)
β
Test Taking Page (frontend/src/pages/TakeTest.jsx):
- Test access verification with email
- Test information and instructions display
- Interactive test-taking interface with:
- Timer countdown with color coding
- Question navigation (previous/next)
- Progress indicator
- Answer summary
- Multiple question types support (multiple choice, text, coding)
- Auto-submit when time runs out
- Results display (immediate or pending based on test settings)
β
API Service Methods (frontend/src/services/api.js):
checkCandidateTestAccess(testResultId, email)- Verify accessstartCandidateTest(testResultId, email)- Start testsubmitCandidateTest(submission)- Submit answersgetCandidateTestResults(testResultId, email)- Get results
β
Routing (frontend/src/App.jsx):
- Public route added:
/take-test/:testResultId - Route is accessible without authentication
How It Works
1. Recruiter Assigns Test
- Go to Tests page
- Click "Assign" on any test
- Select candidate and set expiration (optional)
- System creates test assignment and sends email
2. Candidate Receives Link
Email contains link format:
http://localhost:5173/take-test/{test_result_id}?email={candidate_email}
3. Candidate Takes Test
- Click link β See test info and instructions
- Click "Start Test" β Timer starts, questions appear
- Answer questions β Navigate between questions
- Submit test β Get immediate results (if configured)
4. Recruiter Views Results
- Go to Tests page
- Click "View Results" on the test
- See all candidate scores and details
Testing the Flow
Quick Test Steps:
Start Backend:
cd backend python api_app.pyStart Frontend:
cd frontend npm run devCreate and Assign Test:
- Login to recruiter dashboard
- Go to Tests page
- Create a new test with questions
- Assign it to a candidate
Get Test Link:
- Check database for test_result_id:
cd backend python view_db.py - Look for the TestResult record
- Check database for test_result_id:
Take Test:
- Open:
http://localhost:5173/take-test/{test_result_id}?email={candidate_email} - Complete the test
- Open:
View Results:
- Check Tests page for results
- Or candidate sees immediate results (if configured)
Features Implemented
Security
- β Email verification on every request
- β No authentication required (uses test_result_id + email)
- β One-time use (cannot retake unless configured)
- β Expiration date checking
- β Correct answers hidden until submission
User Experience
- β Clean, intuitive interface
- β Timer with color coding (green β yellow β red)
- β Progress tracking
- β Question navigation
- β Answer summary
- β Auto-submit on timeout
- β Immediate or delayed results
Question Types Supported
- β Multiple choice (radio buttons)
- β Text (textarea)
- β Coding (monospace textarea)
Scoring
- β Automatic scoring
- β Points per question
- β Pass/fail determination
- β Individual question scores
- β Time tracking
Next Steps (Optional Enhancements)
Email Integration
- Send test assignment email with link
- Send test completion notification
- Send results email (if delayed)
Implementation:
# In backend/api/endpoints/tests.py assign_test_to_candidate()
from modules.email_service import send_email
# After creating test_result
test_link = f"http://localhost:5173/take-test/{test_result.id}?email={candidate.email}"
send_email(
to_email=candidate.email,
subject=f"Test Assignment: {test.title}",
body=f"You have been assigned a test. Click here to start: {test_link}"
)
Additional Features
- Save progress (allow browser refresh)
- Question bookmarking/flagging
- Review answers before submission
- Detailed question-by-question results
- Test analytics for recruiters
- Proctoring features (webcam, screen recording)
File Structure
backend/
βββ api/endpoints/
β βββ candidate_tests.py # NEW: Public test endpoints
β βββ tests.py # Existing: Recruiter test management
βββ models/test.py # Test and TestResult models
βββ TEST_FLOW_GUIDE.md # Complete documentation
frontend/
βββ src/
β βββ pages/
β β βββ TakeTest.jsx # NEW: Candidate test interface
β β βββ Tests.jsx # Existing: Recruiter test management
β βββ services/
β β βββ api.js # UPDATED: Added candidate test methods
β βββ App.jsx # UPDATED: Added public route
API Endpoints Summary
Recruiter Endpoints (Authenticated)
POST /api/v1/tests/- Create testGET /api/v1/tests/- List testsPUT /api/v1/tests/{id}- Update testDELETE /api/v1/tests/{id}- Delete testPOST /api/v1/tests/{id}/assign- Assign to candidateGET /api/v1/tests/{id}/results- View all results
Candidate Endpoints (Public with email verification)
GET /api/v1/candidate-tests/access/{test_result_id}- Check accessPOST /api/v1/candidate-tests/start- Start testPOST /api/v1/candidate-tests/submit- Submit answersGET /api/v1/candidate-tests/result/{test_result_id}- View results
Database Schema
Test Table
- Stores test configuration
- Questions with correct answers
- Settings (duration, passing score, etc.)
TestResult Table
- One record per test assignment
- Status: assigned β in_progress β completed
- Stores answers and scores
- Tracks timing and attempts
Troubleshooting
Test Link Not Working
- Verify test_result_id exists in database
- Check email matches candidate email exactly
- Ensure test status is "assigned" or "in_progress"
- Check expiration date
Timer Issues
- Browser must support JavaScript
- Don't refresh page during test
- Auto-submit triggers at 0:00
Submission Fails
- Check internet connection
- Verify backend is running
- Check browser console for errors
- Ensure all required fields are filled
Success! π
The complete candidate test-taking flow is now implemented and ready to use. Candidates can receive test links, take tests with a timer, and see their results immediately or later based on test configuration.