33import pytest
44from django .utils .timezone import now
55from subscriptions .factories import FreeSpotNotificationSubscriptionFactory
6- from subscriptions .tests .utils import assert_subscriptions
6+ from subscriptions .tests .utils import assert_child_has_subscriptions
77
8- from events .factories import EnrolmentFactory , EventFactory , OccurrenceFactory
8+ from events .factories import (
9+ EnrolmentFactory ,
10+ EventFactory ,
11+ EventGroupFactory ,
12+ OccurrenceFactory ,
13+ )
914
1015
1116@pytest .mark .django_db
@@ -22,6 +27,43 @@ def test_enrolling_deletes_same_event_free_spot_subscriptions(
2227 ) # same event subscription
2328 other_event_subscription = FreeSpotNotificationSubscriptionFactory (child = child )
2429
30+ # create an enrolment for the child, subscriptions should be updated accordingly
2531 EnrolmentFactory (occurrence = occurrence_2 , child = child )
2632
27- assert_subscriptions (child , other_event_subscription )
33+ assert_child_has_subscriptions (child , other_event_subscription )
34+
35+
36+ @pytest .mark .django_db
37+ def test_enrolling_deletes_same_event_group_free_spot_subscriptions (child ):
38+ event_group = EventGroupFactory (published_at = now ())
39+ event = EventFactory (published_at = now (), event_group = event_group )
40+ same_group_event = EventFactory (published_at = now (), event_group = event_group )
41+ other_group_event = EventFactory (
42+ published_at = now (), event_group = EventGroupFactory ()
43+ )
44+
45+ occurrence = OccurrenceFactory .create (time = now () + timedelta (days = 1 ), event = event )
46+ same_event_occurrence = OccurrenceFactory .create (
47+ time = now () + timedelta (days = 2 ), event = event
48+ )
49+ same_group_occurrence = OccurrenceFactory (
50+ time = now () + timedelta (days = 3 ), event = same_group_event
51+ )
52+ other_group_occurrence = OccurrenceFactory (
53+ time = now () + timedelta (days = 4 ), event = other_group_event
54+ )
55+
56+ same_event_subscription = FreeSpotNotificationSubscriptionFactory ( # noqa: F841
57+ child = child , occurrence = same_event_occurrence
58+ )
59+ same_group_subscription = FreeSpotNotificationSubscriptionFactory ( # noqa: F841
60+ child = child , occurrence = same_group_occurrence
61+ )
62+ other_group_subscription = FreeSpotNotificationSubscriptionFactory (
63+ child = child , occurrence = other_group_occurrence
64+ )
65+
66+ # create an enrolment for the child, subscriptions should be updated accordingly
67+ EnrolmentFactory (child = child , occurrence = occurrence )
68+
69+ assert_child_has_subscriptions (child , other_group_subscription )
0 commit comments