Skip to content

Commit

Permalink
Updated code to set header on email subject based on desired logic (#39)
Browse files Browse the repository at this point in the history
* Updated code to set header on email subject based on desired logic

* Updated pytest

* Changed subject header to use the env var

* Changed check
  • Loading branch information
jcadam14 authored Aug 27, 2024
1 parent d764e9d commit 9a76bfd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/regtech_mail_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,14 @@ async def send_email(request: Request):
sender_addr = request.user.email
sender_name = request.user.name if request.user.name else ""
type = request.headers["case-type"]
subject = f"[DEV BETA] SBL User Request for {type}"

header = "[BETA]"
if "cfpb" in sender_addr.lower().split("@")[-1]:
header = "[CFPB BETA]"
if settings.environment:
header = f"[{settings.environment}]"

subject = f"{header} SBL User Request for {type}"

form_data = await request.form()

Expand Down
1 change: 1 addition & 0 deletions src/regtech_mail_api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class EmailMailerType(str, Enum):


class EmailApiSettings(BaseSettings):
environment: str = ""
email_mailer: EmailMailerType = EmailMailerType.SMTP
smtp_host: str | None = None
smtp_port: int = 0
Expand Down
4 changes: 2 additions & 2 deletions tests/test_send.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_send_no_profile(
):
email_json = {
"email": {
"subject": "[DEV BETA] SBL User Request for Institution Profile Change",
"subject": "[CFPB BETA] SBL User Request for Institution Profile Change",
"body": "Contact Email: [email protected]\nContact Name: \n\nlei: 1234567890ABCDEFGHIJ\ninstitution_name_1: Fintech 1\ntin_1: 12-3456789\nrssd_1: 1234567",
"from_addr": "[email protected]",
"to": ["[email protected]"],
Expand Down Expand Up @@ -87,7 +87,7 @@ def test_send(
):
email_json = {
"email": {
"subject": "[DEV BETA] SBL User Request for Institution Profile Change",
"subject": "[CFPB BETA] SBL User Request for Institution Profile Change",
"body": "Contact Email: [email protected]\nContact Name: Test User\n\nlei: 1234567890ABCDEFGHIJ\ninstitution_name_1: Fintech 1\ntin_1: 12-3456789\nrssd_1: 1234567",
"from_addr": "[email protected]",
"to": ["[email protected]"],
Expand Down

0 comments on commit 9a76bfd

Please sign in to comment.