@@ -339,6 +339,44 @@ def test_monthly_logs_route(self):
339339 self .assertIn ("entries" , entry )
340340 self .assertIn ("total_hours" , entry )
341341
342+ def test_monthly_logs_with_absence (self ):
343+ # Create an absence entry
344+ with self .app .app_context ():
345+ entry_date = date (2025 , 4 , 15 )
346+ absence_entry = ScheduleEntry (
347+ employee_id = 1 , date = entry_date , entries = [], absence_code = "VAC"
348+ )
349+ db .session .add (absence_entry )
350+ db .session .commit ()
351+
352+ # Test getting monthly logs for the month with the absence
353+ response = self .client .get ("/logs/monthly/2025/4" )
354+ self .assertEqual (response .status_code , 200 )
355+ data = json .loads (response .data )
356+
357+ # Find the absence entry in the response
358+ absence_found = False
359+ for entry in data :
360+ if entry ["date" ] == "2025-04-15" :
361+ self .assertEqual (entry ["type" ], "VAC" )
362+ self .assertEqual (entry ["total_hours" ], 0 )
363+ absence_found = True
364+ break
365+ self .assertTrue (absence_found , "Absence entry not found in response" )
366+
367+ def test_monthly_logs_exception (self ):
368+ with self .app .app_context ():
369+ with patch ("app.routes.time_log.ScheduleEntry.query" ) as mock_query :
370+ # Configure the mock to raise an exception when used
371+ mock_query .filter .side_effect = Exception ("Database connection failed" )
372+
373+ # Test that the exception is handled and a 500 error is returned
374+ response = self .client .get ("/logs/monthly/2025/5" )
375+ self .assertEqual (response .status_code , 500 )
376+ data = json .loads (response .data )
377+ self .assertIn ("error" , data )
378+ self .assertEqual (data ["error" ], "Database connection failed" )
379+
342380
343381if __name__ == "__main__" :
344382 unittest .main ()
0 commit comments