Skip to content

Commit

Permalink
test: add test to support changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mudassir-hafeez committed Jun 11, 2024
1 parent dae80f7 commit 29b61aa
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions ecommerce/mail_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
)
from ecommerce.mail_api import (
EMAIL_DATE_FORMAT,
EMAIL_TIME_FORMAT,
ENROLL_ERROR_EMAIL_SUBJECT,
send_b2b_receipt_email,
send_bulk_enroll_emails,
send_course_run_enrollment_email,
send_ecommerce_order_receipt,
send_enrollment_failure_message,
send_welcome_course_run_enrollment_email,
)
from ecommerce.models import Order
from mail.api import EmailMetadata, UserMessageProps
Expand All @@ -41,6 +43,7 @@
EMAIL_BULK_ENROLL,
EMAIL_COURSE_RUN_ENROLLMENT,
EMAIL_PRODUCT_ORDER_RECEIPT,
EMAIL_WELCOME_COURSE_RUN_ENROLLMENT,
)
from mitxpro.utils import format_price
from users.factories import UserFactory
Expand Down Expand Up @@ -147,6 +150,42 @@ def test_send_course_run_enrollment_email_error(mocker):
)


def test_send_welcome_course_run_enrollment_email(mocker):
"""send_welcome_course_run_enrollment_email should send a welcome email for the given enrollment"""
patched_mail_api = mocker.patch("ecommerce.mail_api.api")
enrollment = CourseRunEnrollmentFactory.create()

run_start_date = enrollment.run.start_date
run_start_time = run_start_date.astimezone(datetime.timezone.utc).strftime(
EMAIL_TIME_FORMAT
)
run_end_date = enrollment.run.end_date
date_range = (
f"{run_start_date.strftime(EMAIL_DATE_FORMAT)} - "
f"{run_end_date.strftime(EMAIL_DATE_FORMAT)}"
)

send_welcome_course_run_enrollment_email(enrollment)

patched_mail_api.context_for_user.assert_called_once_with(
user=enrollment.user,
extra_context={
"enrollment": enrollment,
"run_start_date": run_start_date.strftime(EMAIL_DATE_FORMAT),
"run_start_time": run_start_time,
"run_date_range": date_range,
},
)
patched_mail_api.message_for_recipient.assert_called_once_with(
enrollment.user.email,
patched_mail_api.context_for_user.return_value,
EMAIL_WELCOME_COURSE_RUN_ENROLLMENT,
)
patched_mail_api.send_message.assert_called_once_with(
patched_mail_api.message_for_recipient.return_value
)


@pytest.mark.parametrize("has_discount", [True, False])
def test_send_b2b_receipt_email(mocker, settings, has_discount):
"""send_b2b_receipt_email should send a receipt email"""
Expand Down

0 comments on commit 29b61aa

Please sign in to comment.