diff --git a/queue_services/account-mailer/src/account_mailer/email_processors/account_unlock.py b/queue_services/account-mailer/src/account_mailer/email_processors/account_unlock.py index de878e3e9d..ea92cd00b8 100644 --- a/queue_services/account-mailer/src/account_mailer/email_processors/account_unlock.py +++ b/queue_services/account-mailer/src/account_mailer/email_processors/account_unlock.py @@ -14,7 +14,6 @@ """A Template for the Account Unlocked Email.""" import base64 -import datetime from auth_api.services.rest_service import RestService from auth_api.utils.enums import AuthHeaderType, ContentType @@ -25,15 +24,15 @@ from account_mailer.email_processors import generate_template -def process(email_msg: dict, token: str) -> dict: +def process(data: dict, token: str) -> dict: """Build the email for Account Unlocked notification.""" - logger.debug('email_msg notification: %s', email_msg) - pdf_attachment = _get_account_unlock_pdf(email_msg, token) - html_body = _get_account_unlock_email(email_msg) + logger.debug('email_msg notification: %s', data) + pdf_attachment = _get_account_unlock_pdf(data, token) + html_body = _get_account_unlock_email(data) return { - 'recipients': email_msg.get('admin_coordinator_emails'), + 'recipients': data.get('admin_coordinator_emails'), 'content': { - 'subject': email_msg.get('subject'), + 'subject': data.get('subject'), 'body': f'{html_body}', 'attachments': [ { @@ -51,29 +50,16 @@ def _get_account_unlock_email(email_msg): filled_template = generate_template(current_app.config.get('TEMPLATE_PATH'), email_msg.get('template_name')) jnja_template = Template(filled_template, autoescape=True) html_out = jnja_template.render( - account_name=email_msg.get('account_name'), + account_name=email_msg.get('accountName'), logo_url=email_msg.get('logo_url') ) return html_out -def _get_account_unlock_pdf(email_msg, token): - current_time = datetime.datetime.now() - template_vars = { - **email_msg, - 'corpName': email_msg.get('account_name'), - 'receiptNumber': email_msg.get('receipt_number'), - 'filingDate': current_time.strftime('%Y-%m-%d'), - 'effectiveDateTime': current_time.strftime('%Y-%m-%d %H:%M:%S'), - 'filingIdentifier': email_msg.get('filing_identifier'), - 'paymentMethodDescription': email_msg.get('payment_method_description'), - 'invoiceNumber': email_msg.get('invoice_number'), - 'invoice': email_msg.get('invoice') - } - +def _get_account_unlock_pdf(data, token): pdf_payload = { 'reportName': 'NSF_Fee_Receipt', - 'templateVars': template_vars, + 'templateVars': data['template_vars'], 'populatePageNumber': True, 'templateName': 'payment_receipt', } diff --git a/queue_services/account-mailer/src/account_mailer/worker.py b/queue_services/account-mailer/src/account_mailer/worker.py index 6ed6a8660d..8049fa2241 100644 --- a/queue_services/account-mailer/src/account_mailer/worker.py +++ b/queue_services/account-mailer/src/account_mailer/worker.py @@ -106,16 +106,15 @@ async def process_event(event_message: dict, flask_app): logo_url = email_msg.get('logo_url') email_dict = { - 'account_name': email_msg.get('toOrgName'), + 'template_vars': email_msg, 'logo_url': logo_url, 'template_name': template_name, 'subject': subject, 'org_id': org_id, 'admin_coordinator_emails': admin_coordinator_emails, - 'filing_identifier': email_msg.get('filing_identifier'), } - email_dict = account_unlock.process(email_msg=email_dict, token=token) + email_dict = account_unlock.process(data=email_dict, token=token) elif message_type == MessageType.ACCOUNT_CONFIRMATION_PERIOD_OVER.value: template_name = TemplateType.ACCOUNT_CONF_OVER_TEMPLATE_NAME.value diff --git a/queue_services/account-mailer/tests/integration/test_worker_queue.py b/queue_services/account-mailer/tests/integration/test_worker_queue.py index fe554d6aca..54ba676670 100644 --- a/queue_services/account-mailer/tests/integration/test_worker_queue.py +++ b/queue_services/account-mailer/tests/integration/test_worker_queue.py @@ -162,9 +162,7 @@ async def test_unlock_account_mailer_queue(app, session, stan_server, event_loop response = types.SimpleNamespace() response.status_code = 200 response.content = bytes('foo', 'utf-8') - # patch RestService.post with patch.object(notification_service, 'send_email', return_value=None) as mock_send: - # register the handler to test it with patch.object(RestService, 'post', return_value=response): await subscribe_to_queue(events_stan, events_subject, @@ -172,10 +170,80 @@ async def test_unlock_account_mailer_queue(app, session, stan_server, event_loop events_durable_name, cb_subscription_handler) - # add an event to queue + # Note: This payload should work with report-api. mail_details = { 'accountId': id, - 'accountName': org.name + 'accountName': org.name, + 'invoiceNumber': 'REG0123456', + 'receiptNumber': '99123', + 'paymentMethodDescription': 'Credit Card', + 'invoice': { + '_links': { + 'self': 'http://auth-web.dev.com/api/v1/payment-requests/2', + 'collection': 'http://auth-web.dev.com/api/v1/payment-requests?invoice_id=2' + }, + 'bcolAccount': 'TEST', + 'corpTypeCode': 'CP', + 'createdName': + 'test name', + 'id': 2, + 'createdBy': 'test', + 'paymentAccount': { + 'accountId': '1234', + 'billable': True + }, + 'paymentDate': '2024-02-27T09:52:03+00:00', + 'total': 130.0, + 'paymentMethod': 'CC', + 'overdueDate': '2024-03-01T09:52:02+00:00', + 'paid': 30.0, + 'details': [{'label': 'label', 'value': 'value'}], + 'serviceFees': 0.0, + 'updatedOn': '2024-02-27T09:52:03+00:00', + 'lineItems': [{ + 'waivedFees': None, + 'waivedBy': None, + 'gst': 0.0, + 'pst': 0.0, + 'filingFees': 10.0, + 'id': 2, + 'serviceFees': 0.0, + 'priorityFees': 0.0, + 'futureEffectiveFees': 0.0, + 'quantity': 1, + 'statusCode': 'ACTIVE', + 'total': 10.0, + 'description': 'NSF Fee' + }, { + 'waivedFees': None, + 'waivedBy': None, + 'gst': 0.0, + 'pst': 0.0, + 'filingFees': 10.0, + 'id': 1, + 'serviceFees': 0.0, + 'priorityFees': 0.0, + 'futureEffectiveFees': 0.0, + 'quantity': 1, + 'statusCode': 'ACTIVE', + 'total': 10.0, + 'description': 'Name Request' + }], + 'createdOn': '2024-02-27T09:51:55+00:00', + 'references': [{ + 'invoiceNumber': 'REG00001', + 'id': 2, + 'statusCode': 'COMPLETED' + }], + 'receipts': [{ + 'receiptAmount': 100.0, + 'id': 2, + 'receiptDate': '2024-02-27T09:52:03.018524', + 'receiptNumber': '1234567890' + }], + 'statusCode': 'COMPLETED', + 'folioNumber': '1234567890' + } } await helper_add_event_to_queue(events_stan, events_subject, org_id=id, msg_type=MessageType.NSF_UNLOCK_ACCOUNT.value, mail_details=mail_details)