From 4d1e5a2dbb8618f646b4e10bf450fc4ca1eae8c4 Mon Sep 17 00:00:00 2001 From: MUsoftware Date: Mon, 18 May 2026 09:01:14 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=9D=B4=EB=A9=94=EC=9D=BC=20=EB=B0=9C?= =?UTF-8?q?=EC=86=A1=20=EC=8B=9C=20body=EB=A5=BC=20HTML=20=EB=A0=8C?= =?UTF-8?q?=EB=8D=94=EB=A7=81=EB=90=9C=20=EA=B2=B0=EA=B3=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=A0=84=EC=86=A1=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/notification/models/email.py | 8 +++++++- app/notification/test/history_send_test.py | 24 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/app/notification/models/email.py b/app/notification/models/email.py index fe0fc6d..27bc524 100644 --- a/app/notification/models/email.py +++ b/app/notification/models/email.py @@ -1,4 +1,4 @@ -from typing import ClassVar +from typing import Any, ClassVar from core.external_apis.smtp_email import EmailClient, email_client from django.db import models @@ -17,6 +17,12 @@ class EmailNotificationTemplate(NotificationTemplateBase): class EmailNotificationHistorySentTo(NotificationHistorySentToBase): history = models.ForeignKey("EmailNotificationHistory", on_delete=models.PROTECT, related_name="sent_to_list") + @property + def payload(self) -> dict[str, Any]: + rendered = self.render() + rendered["body"] = self.render_as_html() + return rendered + class EmailNotificationHistoryQuerySet( NotificationHistoryQuerySet["EmailNotificationHistory", EmailNotificationTemplate], diff --git a/app/notification/test/history_send_test.py b/app/notification/test/history_send_test.py index d266c17..00abbd6 100644 --- a/app/notification/test/history_send_test.py +++ b/app/notification/test/history_send_test.py @@ -126,6 +126,30 @@ def test_history_send_parameters_uses_rendered_payload(system_user): assert params["template_code"] == "render" +@pytest.mark.django_db +def test_email_payload_body_is_html_rendered(system_user): + # 이메일 발송 시 payload["body"]는 HTML 템플릿으로 렌더링된 결과여야 함. + tpl = EmailNotificationTemplate.objects.create( + code="html-body", + title="t", + sent_from="a@b.c", + data='{"title":"안녕 {{ name }}","body":"본문 {{ name }}"}', + created_by=system_user, + updated_by=system_user, + ) + history = _create_history(tpl, context={"name": "길동"}) + sent_to = history.sent_to_list.get() + payload = sent_to.payload + + # title은 plain text + assert payload["title"] == "안녕 길동" + assert not payload["title"].strip().startswith("<") + + # body는 HTML 렌더링 결과 + assert payload["body"].strip().startswith("<") + assert "길동" in payload["body"] + + @pytest.mark.django_db def test_history_template_code_property_returns_template_code(email_template): history = _create_history(email_template)