Skip to content

Commit

Permalink
Updates for date formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jcadam14 committed Dec 4, 2024
1 parent adeae5d commit 4877192
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 3 deletions.
17 changes: 16 additions & 1 deletion src/regtech_mail_api/internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@

router = Router()

custom_months = {
"January": "Jan.",
"February": "Feb.",
"August": "Aug.",
"September": "Sept.",
"October": "Oct.",
"November": "Nov.",
"December": "Dec.",
}


class ConfirmationRequest(BaseModel):
model_config = ConfigDict(from_attributes=True)
Expand Down Expand Up @@ -44,7 +54,12 @@ async def send_email(request: Request, confirmation_request: ConfirmationRequest
timestamp_est = confirmation_request.timestamp.astimezone(
ZoneInfo("America/New_York")
)
formatted_date = timestamp_est.strftime("%B %d, %Y at %-I:%M %p %Z")
full_month = timestamp_est.strftime("%B")
formatted_month = custom_months.get(full_month, full_month)
am_pm = "a.m." if timestamp_est.strftime("%p") == "AM" else "p.m."
formatted_date = (
f"{formatted_month} {timestamp_est.strftime("%d, %Y at %-I:%M")} {am_pm} EST"
)
body_template = (
prod_body_template if settings.environment == "PROD" else beta_body_template
)
Expand Down
60 changes: 58 additions & 2 deletions tests/test_send.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from regtech_api_commons.models.auth import AuthenticatedUser
from starlette.authentication import AuthCredentials

from datetime import datetime


@pytest.fixture
def app_fixture(mocker: MockerFixture) -> FastAPI:
Expand Down Expand Up @@ -113,6 +115,60 @@ def test_case_send(
assert res.status_code == 200
assert res.json() == email_json

def test_email_dates(
self, mocker: MockerFixture, app_fixture: FastAPI, full_user_mock: Mock
):
client = TestClient(app_fixture)
res = client.post(
"/internal/confirmation/send",
data=json.dumps(
{
"confirmation_id": "test",
"signer_email": "[email protected]",
"signer_name": "Test User",
"contact_email": "[email protected]",
"timestamp": datetime(2024, 3, 15, 8, 10).timestamp() * 1000,
}
),
)

expected_email = {
"subject": "[BETA] Small Business Lending Data Filing Confirmation",
"body": "\nCongratulations! This email confirms that the filing submitted by Test User on March 15, 2024 at 10:10 a.m. EST was successful. The confirmation number is test.\n\nThe beta platform is for testing purposes only and user-supplied data may be removed at any time. Take a moment to email our support staff at [email protected] with your feedback or return to the beta platform and upload a new file to continue testing.\n",
"from_addr": "[email protected]",
"to": ["[email protected]"],
"cc": None,
"bcc": None,
}

assert res.status_code == 200
assert res.json()["email"] == expected_email

res = client.post(
"/internal/confirmation/send",
data=json.dumps(
{
"confirmation_id": "test",
"signer_email": "[email protected]",
"signer_name": "Test User",
"contact_email": "[email protected]",
"timestamp": datetime(2024, 9, 15, 13, 10).timestamp() * 1000,
}
),
)

expected_email = {
"subject": "[BETA] Small Business Lending Data Filing Confirmation",
"body": "\nCongratulations! This email confirms that the filing submitted by Test User on Sept. 15, 2024 at 3:10 p.m. EST was successful. The confirmation number is test.\n\nThe beta platform is for testing purposes only and user-supplied data may be removed at any time. Take a moment to email our support staff at [email protected] with your feedback or return to the beta platform and upload a new file to continue testing.\n",
"from_addr": "[email protected]",
"to": ["[email protected]"],
"cc": None,
"bcc": None,
}

assert res.status_code == 200
assert res.json()["email"] == expected_email

def test_confirmation_send(
self, mocker: MockerFixture, app_fixture: FastAPI, full_user_mock: Mock
):
Expand All @@ -132,7 +188,7 @@ def test_confirmation_send(

expected_email = {
"subject": "[BETA] Small Business Lending Data Filing Confirmation",
"body": "\nCongratulations! This email confirms that the filing submitted by Test User on November 20, 2024 at 1:51 PM EST was successful. The confirmation number is test.\n\nThe beta platform is for testing purposes only and user-supplied data may be removed at any time. Take a moment to email our support staff at [email protected] with your feedback or return to the beta platform and upload a new file to continue testing.\n",
"body": "\nCongratulations! This email confirms that the filing submitted by Test User on Nov. 20, 2024 at 1:51 p.m. EST was successful. The confirmation number is test.\n\nThe beta platform is for testing purposes only and user-supplied data may be removed at any time. Take a moment to email our support staff at [email protected] with your feedback or return to the beta platform and upload a new file to continue testing.\n",
"from_addr": "[email protected]",
"to": ["[email protected]"],
"cc": None,
Expand All @@ -149,7 +205,7 @@ def test_confirmation_send(
mock_settings.from_addr = "[email protected]"
expected_email = {
"subject": "Small Business Lending Data Filing Confirmation",
"body": "\nCongratulations! This email confirms that the filing submitted by Test User on November 20, 2024 at 1:51 PM EST was successful. The confirmation number is test.\n\nTo make any changes to the filing, please return to the Small Business Lending Data Filing Platform and follow the provided instructions. If you have any questions or need additional support, email our support staff at [email protected].\n",
"body": "\nCongratulations! This email confirms that the filing submitted by Test User on Nov. 20, 2024 at 1:51 p.m. EST was successful. The confirmation number is test.\n\nTo make any changes to the filing, please return to the Small Business Lending Data Filing Platform and follow the provided instructions. If you have any questions or need additional support, email our support staff at [email protected].\n",
"from_addr": "[email protected]",
"to": ["[email protected]", "[email protected]"],
"cc": None,
Expand Down

0 comments on commit 4877192

Please sign in to comment.