test: add test files for schemas
Issue Summary
Align Schemas and Models for Points, Tasks, OTP, and Associations to Ensure Consistency and Validation Integrity
The current implementation across multiple schema and model files shows inconsistencies in field definitions, validation logic, and relationships. These mismatches can lead to incorrect data handling, validation failures, and potential runtime issues.
Problem Statement
Several schema and model files have inconsistencies:
- Mismatch between schema fields and model attributes
- Inconsistent naming conventions across modules
- Missing or incorrect relationships in association models
- Validation gaps in OTP, password reset, and task-related schemas
- Potential data integrity issues in points tracking and user follow logic
Affected Files:
app/schemas/points.pyapp/schemas/task.pyapp/schemas/password_reset.pyapp/schemas/otp.pyapp/models/points.pyapp/models/associations.pyapp/models/otp.pyapp/models/user_follow.py
Impact:
- Data inconsistency between API layer and database layer
- Validation errors or incorrect acceptance of invalid data
- Broken relationships (e.g., user follow, points tracking)
- Increased risk of bugs in authentication and task workflows
Reproduction:
- Trigger API endpoints using these schemas
- Observe mismatches in expected vs actual data
- Run tests → failures in validation and schema alignment
Proposed Solution
-
Align schema fields with corresponding model attributes
-
Standardize naming conventions across schemas and models
-
Add/validate relationships in association models (e.g., user_follow)
-
Improve validation logic for:
- OTP (expiry, format)
- Password reset (token, security checks)
- Task schema (required fields, constraints)
-
Ensure points system correctly reflects model logic
-
Add missing constraints and default values where necessary
Test-Driven Development
Acceptance Criteria (Given-When-Then)
Scenario 1: Points Schema and Model Alignment
Given a points-related request payload
When it is validated and stored
Then schema and model fields should match
And data should be persisted correctly
Scenario 2: OTP Validation
Given a valid or invalid OTP input
When validation is performed
Then valid OTPs should pass
And invalid or expired OTPs should fail
Scenario 3: User Follow Relationship
Given a user follows another user
When the relationship is stored
Then association should be correctly created
And duplicate or invalid follows should be prevented
Scenario 4: Task and Password Reset Validation
Given task and password reset inputs
When schema validation is executed
Then only valid data should pass
And invalid inputs should return errors
Test Cases
| Test ID | Test Description | Precondition | Test Steps | Expected Result | Priority |
|---|---|---|---|---|---|
| TC-001 | Validate points schema-model mapping | Schema defined | 1. Send data 2. Validate/store |
Data matches model | High |
| TC-002 | Validate OTP logic | OTP generated | 1. Validate OTP | Correct pass/fail | High |
| TC-003 | Validate user follow relationship | Users exist | 1. Follow user | Relationship stored | High |
| TC-004 | Validate task schema | Task input ready | 1. Validate input | Pass valid cases | Medium |
| TC-005 | Validate password reset | Token generated | 1. Validate reset | Secure validation | High |
Unit Test Requirements
Components/Functions to Test:
| Module/Component | Function/Hook | Test Cases to Cover |
|---|---|---|
points |
schema/model mapping | TC-001 |
otp |
validation logic | TC-002 |
user_follow |
relationship logic | TC-003 |
task |
validation | TC-004 |
password_reset |
token validation | TC-005 |
Test Assertions Required:
-
Schema and model fields are consistent -
Validation rejects invalid inputs -
Relationships are correctly created -
Edge cases handled properly -
No data integrity issues
Implementation Details
Files to Change
| File Path | Action | Purpose |
|---|---|---|
app/schemas/points.py |
Modify | Align fields and validation |
app/schemas/task.py |
Modify | Fix schema constraints |
app/schemas/password_reset.py |
Modify | Improve validation logic |
app/schemas/otp.py |
Modify | Add OTP validation rules |
app/models/points.py |
Modify | Ensure consistency with schema |
app/models/associations.py |
Modify | Fix relationships |
app/models/otp.py |
Modify | Align with OTP schema |
app/models/user_follow.py |
Modify | Ensure correct association logic |
Technical Considerations
- Maintain backward compatibility where possible
- Ensure database migrations (if needed)
- Follow consistent naming conventions
- Validate relationships using ORM constraints
UI/UX Requirements
N/A (Backend schema/model improvements)
Testing Strategy
Manual Testing
Test Environment:
- Backend API (local + staging)
Manual Test Steps:
- Trigger endpoints using updated schemas
- Validate responses and DB entries
- Test edge cases (invalid inputs, duplicates)
Automated Testing
Unit Tests:
-
Schema validation tests -
Model logic tests -
Relationship tests
Integration Tests:
-
API flow tests -
Authentication-related flows
Test Data Requirements
const mockTestData = {
user: { id: 1 },
otp: "123456",
task: { title: "Sample Task", description: "Valid description here" },
points: { value: 10 }
}
Definition of Done
-
Schema and model consistency achieved -
All validation rules correctly implemented -
All tests passing -
No data inconsistencies -
Code reviewed and approved -
No warnings or errors
Additional Context
Related Issues
- Related to: Test failures due to schema mismatch
- Blocks: Validation-related issues
References
- ORM documentation
- Validation library docs
Notes
- Critical for data integrity across authentication and user interaction features
- Ensure alignment before adding new features