@@ -979,7 +979,9 @@ def test_unenrol_occurrence(
979979 occurrence ,
980980 project ,
981981 child_with_random_guardian ,
982+ settings ,
982983):
984+ settings .KUKKUU_ENROLMENT_UNENROL_HOURS_BEFORE = 0
983985 non_authen_executed = api_client .execute (
984986 UNENROL_OCCURRENCE_MUTATION , variables = ENROL_OCCURRENCE_VARIABLES
985987 )
@@ -1021,7 +1023,8 @@ def test_unenrol_occurrence(
10211023 snapshot .assert_match (executed )
10221024
10231025
1024- def test_ticket_not_valid_after_unenrol (user_api_client , occurrence , project ):
1026+ def test_ticket_not_valid_after_unenrol (user_api_client , occurrence , project , settings ):
1027+ settings .KUKKUU_ENROLMENT_UNENROL_HOURS_BEFORE = 0
10251028 child = ChildWithGuardianFactory (
10261029 relationship__guardian__user = user_api_client .user , project = project
10271030 )
@@ -1059,6 +1062,44 @@ def test_cannot_unenrol_from_occurrence_in_past(
10591062 assert_match_error_code (executed , PAST_ENROLMENT_ERROR )
10601063
10611064
1065+ @freeze_time ("2024-01-01 12:00:00" )
1066+ def test_cannot_unenrol_within_48_hours (guardian_api_client , child_with_user_guardian ):
1067+ # Create occurrence 47 hours in future (within 48 hour limit)
1068+ future_time = timezone .now () + timedelta (hours = 47 )
1069+ enrolment = EnrolmentFactory (
1070+ occurrence__time = future_time , child = child_with_user_guardian
1071+ )
1072+
1073+ variables = deepcopy (UNENROL_OCCURRENCE_VARIABLES )
1074+ variables ["input" ]["occurrenceId" ] = get_global_id (enrolment .occurrence )
1075+ variables ["input" ]["childId" ] = get_global_id (child_with_user_guardian )
1076+
1077+ executed = guardian_api_client .execute (
1078+ UNENROL_OCCURRENCE_MUTATION , variables = variables
1079+ )
1080+
1081+ assert_match_error_code (executed , "TOO_LATE_TO_UNENROL_ERROR" )
1082+
1083+
1084+ @freeze_time ("2024-01-01 12:00:00" )
1085+ def test_can_unenrol_outside_48_hours (guardian_api_client , child_with_user_guardian ):
1086+ # Create occurrence 49 hours in future (outside 48 hour limit)
1087+ future_time = timezone .now () + timedelta (hours = 49 )
1088+ enrolment = EnrolmentFactory (
1089+ occurrence__time = future_time , child = child_with_user_guardian
1090+ )
1091+
1092+ variables = deepcopy (UNENROL_OCCURRENCE_VARIABLES )
1093+ variables ["input" ]["occurrenceId" ] = get_global_id (enrolment .occurrence )
1094+ variables ["input" ]["childId" ] = get_global_id (child_with_user_guardian )
1095+
1096+ executed = guardian_api_client .execute (
1097+ UNENROL_OCCURRENCE_MUTATION , variables = variables
1098+ )
1099+
1100+ assert "errors" not in executed
1101+
1102+
10621103def test_maximum_enrolment (
10631104 guardian_api_client , occurrence , project , child_with_user_guardian
10641105):
0 commit comments