diff --git a/CHANGELOG.md b/CHANGELOG.md index d94285d..d367990 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.2.3] - 2025-08-22 + +### Added +- Increased test coverage for the `time_log.py` module from 88% to 100%. + + ## [1.2.2] - 2025-08-22 ### Added @@ -141,6 +147,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Flexible database configuration (SQLite/PostgreSQL). + +[1.2.3]: https://github.com/PPeitsch/TimeTrack/compare/v1.2.2...v1.2.3 [1.2.2]: https://github.com/PPeitsch/TimeTrack/compare/v1.2.1...v1.2.2 [1.2.1]: https://github.com/PPeitsch/TimeTrack/compare/v1.2.0...v1.2.1 [1.2.0]: https://github.com/PPeitsch/TimeTrack/compare/v1.1.1...v1.2.0 diff --git a/tests/test_routes.py b/tests/test_routes.py index fdc3895..46e5c02 100644 --- a/tests/test_routes.py +++ b/tests/test_routes.py @@ -339,6 +339,44 @@ def test_monthly_logs_route(self): self.assertIn("entries", entry) self.assertIn("total_hours", entry) + def test_monthly_logs_with_absence(self): + # Create an absence entry + with self.app.app_context(): + entry_date = date(2025, 4, 15) + absence_entry = ScheduleEntry( + employee_id=1, date=entry_date, entries=[], absence_code="VAC" + ) + db.session.add(absence_entry) + db.session.commit() + + # Test getting monthly logs for the month with the absence + response = self.client.get("/logs/monthly/2025/4") + self.assertEqual(response.status_code, 200) + data = json.loads(response.data) + + # Find the absence entry in the response + absence_found = False + for entry in data: + if entry["date"] == "2025-04-15": + self.assertEqual(entry["type"], "VAC") + self.assertEqual(entry["total_hours"], 0) + absence_found = True + break + self.assertTrue(absence_found, "Absence entry not found in response") + + def test_monthly_logs_exception(self): + with self.app.app_context(): + with patch("app.routes.time_log.ScheduleEntry.query") as mock_query: + # Configure the mock to raise an exception when used + mock_query.filter.side_effect = Exception("Database connection failed") + + # Test that the exception is handled and a 500 error is returned + response = self.client.get("/logs/monthly/2025/5") + self.assertEqual(response.status_code, 500) + data = json.loads(response.data) + self.assertIn("error", data) + self.assertEqual(data["error"], "Database connection failed") + if __name__ == "__main__": unittest.main()