diff --git a/src/core/handlers.py b/src/core/handlers.py index 3811e722..46df1ab8 100644 --- a/src/core/handlers.py +++ b/src/core/handlers.py @@ -51,10 +51,9 @@ def get_username_from_jwt(payload: dict) -> str: def registration_callback(user: User, **kwargs: dict) -> None: """ Listens for the `user_signed_up` signal and adds a background tasks to - send the welcome email and slack invite + send the welcome email """ logger.info(f"Received user_signed_up signal for {user}") - send_slack_invite_job(user.email) send_welcome_email(user.email) @@ -62,7 +61,8 @@ def registration_callback(user: User, **kwargs: dict) -> None: def email_confirmed_callback(email_address: EmailConfirmation, **kwargs: dict) -> None: """ Listens for the `email_confirmed` signal and adds a background task to - add the user to the mailing list + add the user to the mailing list and send the slack invite """ logger.info(f"Received email_confirmed signal for {email_address.email}") + send_slack_invite_job(email_address.email) add_user_to_mailing_list(email_address.email) diff --git a/src/tests/integration/test_rest_registration.py b/src/tests/integration/test_rest_registration.py index 4cb6656e..5940ef97 100644 --- a/src/tests/integration/test_rest_registration.py +++ b/src/tests/integration/test_rest_registration.py @@ -57,7 +57,7 @@ def test_user_profile_created(client: APIClient, register_form: Dict[str, str]): @pytest.mark.django_db -def test_slack_invite_task_created( +def test_slack_invite_task_not_created( client: APIClient, register_form: Dict[str, str], mailoutbox: List[EmailMultiAlternatives], @@ -68,8 +68,7 @@ def test_slack_invite_task_created( tasks = BackgroundTask.objects.filter(task_name="core.tasks.send_slack_invite_job") - assert len(tasks) == 1 - assert tasks[0].task_name.split(".")[-1] == "send_slack_invite_job" + assert len(tasks) == 0 @pytest.mark.django_db @@ -140,3 +139,25 @@ def test_mailing_list_task_created( assert any( task.task_name.split(".")[-1] == "add_user_to_mailing_list" for task in tasks ) + + +@pytest.mark.django_db +def test_slack_invite_task_created( + client: APIClient, + register_form: Dict[str, str], + mailoutbox: List[EmailMultiAlternatives], +): + client.post(reverse("rest_register"), register_form) + + body = mailoutbox[0].body + groups = key_pattern.search(body).groupdict() + + res = client.post(reverse("rest_verify_email"), {"key": groups["key"]}) + + assert res.status_code == 200 + tasks = BackgroundTask.objects.filter(task_name="core.tasks.send_slack_invite_job") + + assert len(tasks) == 1 + assert any( + task.task_name.split(".")[-1] == "send_slack_invite_job" for task in tasks + )