-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Bug Description:
The BatteryService.getBatteryStatus() method in the battery module fails to validate input charge parameters, accepting invalid values (negative numbers and values >100%) without throwing appropriate validation errors. Instead of rejecting invalid input with proper error messages, the service processes these values as legitimate inputs, leading to potential data integrity issues and poor user experience.
Module: Battery Service
Expected Results:
- Charge values < 0% should throw validation error: "Charge level must be between 0 and 100"
- Charge values > 100% should throw validation error: "Charge level must be between 0 and 100"
- API should return HTTP 400 Bad Request with clear error message
Actual Results:
- Invalid charge values (-1%, 101%, -999%) are processed without validation
- No proper error handling for boundary violations
- API returns HTTP 500 Internal Server Error instead of proper validation error
Severity:
Medium: Affects data integrity and user experience but doesn't crash the system
Priority:
High: Should be fixed before production deployment as it affects core business logic validation
Steps to Reproduce:
Environment Setup:
Start NestJS backend server (npm run start:dev)
Ensure server is running on http://localhost:3000
Test Case 1 - Negative Charge Value:
GET http://localhost:3000/battery/status?lat=52.52&lon=13.41&charge=-1
Expected: HTTP 400 with validation error
Actual: HTTP 500 Internal Server Error
Test Case 2 - Above Maximum Charge
GET http://localhost:3000/battery/status?lat=52.52&lon=13.41&charge=101
Expected: HTTP 400 with validation error
Actual: HTTP 500 Internal Server Error
Test Case 3 - Extremely Negative Value:
GET http://localhost:3000/battery/status?lat=52.52&lon=13.41&charge=-999
Expected: HTTP 400 with validation error
Actual: HTTP 500 Internal Server Error
Unit Test File and Commands
File: battery.service.spec.ts
Commands:
cd backend
npm test battery.service.spec.ts
Result: BVP tests fail showing validation gaps
Environment:
OS: Windows 10
Node.js: v18+
Framework: NestJS v11.0.1
Testing: Jest
Browser: Chrome/Edge (for API testing)
Suggested Fix:
Add input validation for above cases in BatteryController.getBatteryStatus()
Checklist (For Fixer)
- Reproduced test environment and bug
- Fixed all three input cases
- Ran and passed unit test