diff --git a/queue_services/entity-emailer/src/entity_emailer/email_processors/continuation_in_notification.py b/queue_services/entity-emailer/src/entity_emailer/email_processors/continuation_in_notification.py index db09add5e..149d3660e 100644 --- a/queue_services/entity-emailer/src/entity_emailer/email_processors/continuation_in_notification.py +++ b/queue_services/entity-emailer/src/entity_emailer/email_processors/continuation_in_notification.py @@ -24,7 +24,7 @@ from entity_queue_common.service_utils import logger from flask import current_app from jinja2 import Template -from legal_api.models import Business, Filing +from legal_api.models import Business, Filing, ReviewResult from entity_emailer.email_processors import ( get_entity_dashboard_url, @@ -66,6 +66,7 @@ def _get_pdfs( ) attach_order += 1 + # add receipt corp_name = business.get('legalName') receipt = requests.post( f'{current_app.config.get("PAY_API_URL")}/{filing.payment_token}/receipts', @@ -91,6 +92,22 @@ def _get_pdfs( } ) attach_order += 1 + + elif status == 'RESUBMITTED': + # add filing pdf + filing_pdf_type = 'continuationIn' + filing_pdf_encoded = get_filing_document(business['identifier'], filing.id, filing_pdf_type, token) + if filing_pdf_encoded: + pdfs.append( + { + 'fileName': 'Continuation Application - Resubmitted.pdf', + 'fileBytes': filing_pdf_encoded.decode('utf-8'), + 'fileUrl': '', + 'attachOrder': str(attach_order) + } + ) + attach_order += 1 + elif status == Filing.Status.COMPLETED.value: # add certificate of continuation certificate_pdf_type = 'certificateOfContinuation' @@ -105,6 +122,7 @@ def _get_pdfs( } ) attach_order += 1 + # add notice of articles noa_pdf_type = 'noticeOfArticles' noa_encoded = get_filing_document(business['identifier'], filing.id, noa_pdf_type, token) @@ -118,14 +136,17 @@ def _get_pdfs( } ) attach_order += 1 + return pdfs def process(email_info: dict, token: str) -> dict: # pylint: disable=too-many-locals, , too-many-branches """Build the email for Continuation notification.""" logger.debug('filing_notification: %s', email_info) - # get template and fill in parts + + # get template vars from email info filing_type, status = email_info['type'], email_info['option'] + # get template vars from filing filing, business, leg_tmz_filing_date, leg_tmz_effective_date = get_filing_info(email_info['filingId']) filing_name = filing.filing_type[0].upper() + ' '.join(re.findall('[a-zA-Z][^A-Z]*', filing.filing_type[1:])) @@ -133,13 +154,11 @@ def process(email_info: dict, token: str) -> dict: # pylint: disable=too-many-l if status == Filing.Status.PAID.value: business = filing_data['nameRequest'] business['identifier'] = filing.temp_reg - - template = Path(f'{current_app.config.get("TEMPLATE_PATH")}/CONT-IN-{status}.html').read_text() - filled_template = substitute_template_parts(template) - # render template with vars legal_type = business.get('legalType') numbered_description = Business.BUSINESSES.get(legal_type, {}).get('numberedDescription') - jnja_template = Template(filled_template, autoescape=True) + review_result = ReviewResult.get_last_review_result(filing.id) + # encode newlines in review comment only + latest_review_comment = review_result.comments.replace('\n', '\\n') if review_result else None # compute Foreign Jurisdiction string as in report.py and business_document.py country_code = filing_data['foreignJurisdiction']['country'] @@ -150,6 +169,12 @@ def process(email_info: dict, token: str) -> dict: # pylint: disable=too-many-l region = pycountry.subdivisions.get(code=f'{country_code}-{region_code}') foreign_jurisdiction = f'{region.name}, {country.name}' if region else country.name + # get template and fill in parts + template = Path(f'{current_app.config.get("TEMPLATE_PATH")}/CONT-IN-{status}.html').read_text() + filled_template = substitute_template_parts(template) + jnja_template = Template(filled_template, autoescape=True) + + # render template with vars html_out = jnja_template.render( business=business, filing=filing_data, @@ -161,9 +186,13 @@ def process(email_info: dict, token: str) -> dict: # pylint: disable=too-many-l email_header=filing_name.upper(), filing_type=filing_type, numbered_description=numbered_description, - foreign_jurisdiction=foreign_jurisdiction + foreign_jurisdiction=foreign_jurisdiction, + latest_review_comment=latest_review_comment ) + # decode newlines to
for html output + html_out = html_out.replace('\\n', '
') + # get attachments pdfs = _get_pdfs(status, token, @@ -179,10 +208,14 @@ def process(email_info: dict, token: str) -> dict: # pylint: disable=too-many-l # assign subject legal_name = business.get('legalName', None) - if status == Filing.Status.PAID.value: - subject = 'Confirmation of Filing from the Business Registry' + if status in [Filing.Status.APPROVED.value, Filing.Status.REJECTED.value]: + subject = 'Results of your Filing from the Business Registry' + elif status == Filing.Status.CHANGE_REQUESTED.value: + subject = 'Change Requested from the Business Registry' elif status == Filing.Status.COMPLETED.value: subject = 'Continuation Documents from the Business Registry' + elif status in [Filing.Status.PAID.value, 'RESUBMITTED']: + subject = 'Confirmation of Filing from the Business Registry' subject = f'{legal_name} - {subject}' if legal_name else subject diff --git a/queue_services/entity-emailer/src/entity_emailer/email_templates/CONT-IN-APPROVED.html b/queue_services/entity-emailer/src/entity_emailer/email_templates/CONT-IN-APPROVED.html new file mode 100644 index 000000000..22469b085 --- /dev/null +++ b/queue_services/entity-emailer/src/entity_emailer/email_templates/CONT-IN-APPROVED.html @@ -0,0 +1,67 @@ + + + + + + + + + Results of your Continuation Application + [[style.html]] + + + + + + + + + + diff --git a/queue_services/entity-emailer/src/entity_emailer/email_templates/CONT-IN-CHANGE_REQUESTED.html b/queue_services/entity-emailer/src/entity_emailer/email_templates/CONT-IN-CHANGE_REQUESTED.html new file mode 100644 index 000000000..8346fe8b0 --- /dev/null +++ b/queue_services/entity-emailer/src/entity_emailer/email_templates/CONT-IN-CHANGE_REQUESTED.html @@ -0,0 +1,56 @@ + + + + + + + + + Results of your Continuation Application + [[style.html]] + + + + + + + + + + diff --git a/queue_services/entity-emailer/src/entity_emailer/email_templates/CONT-IN-REJECTED.html b/queue_services/entity-emailer/src/entity_emailer/email_templates/CONT-IN-REJECTED.html new file mode 100644 index 000000000..945368e0f --- /dev/null +++ b/queue_services/entity-emailer/src/entity_emailer/email_templates/CONT-IN-REJECTED.html @@ -0,0 +1,71 @@ + + + + + + + + + Results of your Continuation Application + [[style.html]] + + + + + + + + + + diff --git a/queue_services/entity-emailer/src/entity_emailer/email_templates/CONT-IN-RESUBMITTED.html b/queue_services/entity-emailer/src/entity_emailer/email_templates/CONT-IN-RESUBMITTED.html new file mode 100644 index 000000000..deb02aecf --- /dev/null +++ b/queue_services/entity-emailer/src/entity_emailer/email_templates/CONT-IN-RESUBMITTED.html @@ -0,0 +1,65 @@ + + + + + + + + + Confirmation of Filing from the Business Registry + [[style.html]] + + + + + + + + + + diff --git a/queue_services/entity-emailer/tests/unit/email_processors/test_continuation_in_notification.py b/queue_services/entity-emailer/tests/unit/email_processors/test_continuation_in_notification.py index d64a37647..4e54b462d 100644 --- a/queue_services/entity-emailer/tests/unit/email_processors/test_continuation_in_notification.py +++ b/queue_services/entity-emailer/tests/unit/email_processors/test_continuation_in_notification.py @@ -22,14 +22,19 @@ @pytest.mark.parametrize('status', [ + (Filing.Status.APPROVED.value), + (Filing.Status.CHANGE_REQUESTED.value), + (Filing.Status.COMPLETED.value), (Filing.Status.PAID.value), - (Filing.Status.COMPLETED.value) + (Filing.Status.REJECTED.value), + ('RESUBMITTED'), ]) def test_continuation_in_notification(app, session, mocker, status): """Assert Continuation notification is created.""" # setup filing + business for email filing = prep_continuation_in_filing(session, 'C1234567', '1', status) token = 'token' + # test processor mocker.patch( 'entity_emailer.email_processors.continuation_in_notification.get_entity_dashboard_url', @@ -39,16 +44,36 @@ def test_continuation_in_notification(app, session, mocker, status): {'filingId': filing.id, 'type': 'continuationIn', 'option': status}, token) assert 'test@test.com' in email['recipients'] - if status == Filing.Status.PAID.value: - assert email['content']['subject'] == \ - 'HAULER MEDIA INC. - Confirmation of Filing from the Business Registry' - assert 'comp_party@email.com' in email['recipients'] - else: - assert mock_get_pdfs.call_args[0][2]['identifier'] == 'C1234567' - assert email['content']['subject'] == 'Continuation Documents from the Business Registry' - assert email['content']['body'] assert email['content']['attachments'] == [] assert mock_get_pdfs.call_args[0][0] == status assert mock_get_pdfs.call_args[0][1] == token assert mock_get_pdfs.call_args[0][3] == filing + + # spot check email content based on status + if status == Filing.Status.APPROVED.value: + assert email['content']['subject'] == 'Results of your Filing from the Business Registry' + assert 'your business has been continued in' in email['content']['body'] + + elif status == Filing.Status.CHANGE_REQUESTED.value: + assert email['content']['subject'] == 'Change Requested from the Business Registry' + assert 'resubmit your application' in email['content']['body'] + + elif status == Filing.Status.COMPLETED.value: + assert email['content']['subject'] == 'Continuation Documents from the Business Registry' + assert 'have successfully registered' in email['content']['body'] + assert mock_get_pdfs.call_args[0][2]['identifier'] == 'C1234567' + + elif status == Filing.Status.PAID.value: + assert email['content']['subject'] == \ + 'HAULER MEDIA INC. - Confirmation of Filing from the Business Registry' + assert 'Receipt' in email['content']['body'] + assert 'comp_party@email.com' in email['recipients'] + + elif status == Filing.Status.REJECTED.value: + assert email['content']['subject'] == 'Results of your Filing from the Business Registry' + assert 'rejected' in email['content']['body'] + + elif status == 'RESUBMITTED': + assert email['content']['subject'] == 'Confirmation of Filing from the Business Registry' + assert 'your updated' in email['content']['body']