@@ -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,50 @@ 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 (
1067+ guardian_api_client , child_with_user_guardian , settings
1068+ ):
1069+ settings .KUKKUU_ENROLMENT_UNENROL_HOURS_BEFORE = 48
1070+ # Create occurrence 47 hours in future (within 48 hour limit)
1071+ future_time = timezone .now () + timedelta (hours = 47 )
1072+ enrolment = EnrolmentFactory (
1073+ occurrence__time = future_time , child = child_with_user_guardian
1074+ )
1075+
1076+ variables = deepcopy (UNENROL_OCCURRENCE_VARIABLES )
1077+ variables ["input" ]["occurrenceId" ] = get_global_id (enrolment .occurrence )
1078+ variables ["input" ]["childId" ] = get_global_id (child_with_user_guardian )
1079+
1080+ executed = guardian_api_client .execute (
1081+ UNENROL_OCCURRENCE_MUTATION , variables = variables
1082+ )
1083+
1084+ assert_match_error_code (executed , "TOO_LATE_TO_UNENROL_ERROR" )
1085+
1086+
1087+ @freeze_time ("2024-01-01 12:00:00" )
1088+ def test_can_unenrol_outside_48_hours (
1089+ guardian_api_client , child_with_user_guardian , settings
1090+ ):
1091+ settings .KUKKUU_ENROLMENT_UNENROL_HOURS_BEFORE = 48
1092+ # Create occurrence 49 hours in future (outside 48 hour limit)
1093+ future_time = timezone .now () + timedelta (hours = 49 )
1094+ enrolment = EnrolmentFactory (
1095+ occurrence__time = future_time , child = child_with_user_guardian
1096+ )
1097+
1098+ variables = deepcopy (UNENROL_OCCURRENCE_VARIABLES )
1099+ variables ["input" ]["occurrenceId" ] = get_global_id (enrolment .occurrence )
1100+ variables ["input" ]["childId" ] = get_global_id (child_with_user_guardian )
1101+
1102+ executed = guardian_api_client .execute (
1103+ UNENROL_OCCURRENCE_MUTATION , variables = variables
1104+ )
1105+
1106+ assert "errors" not in executed
1107+
1108+
10621109def test_maximum_enrolment (
10631110 guardian_api_client , occurrence , project , child_with_user_guardian
10641111):
0 commit comments