Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

21515 - MRAS & BN emails for continuation in and amalgamation #2966

Merged
merged 6 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion queue_services/entity-emailer/q_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

affiliation_type: Final = 'bc.registry.affiliation'
dissolution_type: Final = 'bc.registry.dissolution'
bn: Final = 'businessNumber'


async def run(loop, email_info): # pylint: disable=too-many-locals
Expand Down Expand Up @@ -121,14 +122,16 @@ def subscription_options():
identifier = arg
elif opt in ('-n', '--name'):
name = arg
if not etype or (etype not in [affiliation_type, dissolution_type] and not all([fid, etype, option])):
if not etype or (etype not in [affiliation_type, dissolution_type, bn] and not all([fid, etype, option])):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to add check for 'bn' here otherwise it would exit right away

print('q_cli.py -f <filing_id> -t <email_type> -o <option> -i <identifier>')
sys.exit()
elif etype and etype in [affiliation_type] and not all([fid, etype]):
print('q_cli.py -f <filing_id> -t <email_type>')
sys.exit()
elif etype and etype in [dissolution_type] and not all([fid, etype, identifier, name]):
print('q_cli.py -f <furnishing_id> -t <email_type> -i <identifier> -n <furnishing_name>')
elif etype and etype in [bn] and not all([etype, identifier]):
print('q_cli.py -t <email_type> -i <identifier>')

if etype in [affiliation_type]:
msg_id = str(uuid.uuid4())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ def process(email_msg: dict) -> dict:

# get filing and business json
business = Business.find_by_identifier(email_msg['identifier'])
filing_type = 'incorporationApplication'
if business.legal_type in [Business.LegalTypes.SOLE_PROP.value, Business.LegalTypes.PARTNERSHIP.value]:
filing_type = 'registration'
filing = (Filing.get_a_businesses_most_recent_filing_of_a_type(business.id, filing_type))

# get filings by types. There will be only one of the listed filing types at once
filings = Filing.get_filings_by_types(business.id, ['amalgamationApplication', 'continuationIn',
'incorporationApplication', 'registration'])
filing = filings[0]
corp_type = CorpType.find_by_id(business.legal_type)

# render template with vars
Expand All @@ -48,7 +49,7 @@ def process(email_msg: dict) -> dict:
)

# get recipients
recipients = get_recipients(email_msg['option'], filing.filing_json, filing_type=filing_type)
recipients = get_recipients(email_msg['option'], filing.filing_json, filing_type=filing.filing_type)
return {
'recipients': recipients,
'requestBy': '[email protected]',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ def process(email_msg: dict) -> dict:
jnja_template = Template(filled_template, autoescape=True)
html_out = jnja_template.render(
business=business,
filing=(filing.json)['filing']['incorporationApplication'],
filing=(filing.json)['filing'][filing_type],
header=(filing.json)['filing']['header'],
filing_date_time=leg_tmz_filing_date,
effective_date_time=leg_tmz_effective_date,
filing_type=filing_type
)

# get recipients
recipients = get_recipients(email_msg['option'], filing.filing_json)
recipients = get_recipients(email_msg['option'], filing.filing_json, filing_type=filing_type)

return {
'recipients': recipients,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<td class="name">Company Name:</td>
{% endif %}

{% if filing_status == 'PAID' and filing_type == 'incorporationApplication' %}
{% if filing_status == 'PAID' and filing_type in ['amalgamationApplication', 'continuationIn', 'incorporationApplication'] %}
{% if filing.nameRequest.legalName %}
<!-- try to get legal name from Name Request object -->
<td class="value bold">{{ filing.nameRequest.legalName }}</td>
Expand Down
4 changes: 3 additions & 1 deletion queue_services/entity-emailer/src/entity_emailer/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ def process_email(email_msg: dict, flask_app: Flask): # pylint: disable=too-man
if etype == 'businessNumber':
email = bn_notification.process(email_msg['email'])
send_email(email, token)
elif etype == 'incorporationApplication' and option == 'mras':
elif etype in ['amalgamationApplication',
'continuationIn',
'incorporationApplication'] and option == 'mras':
email = mras_notification.process(email_msg['email'])
send_email(email, token)
elif etype == 'annualReport' and option == 'reminder':
Expand Down
4 changes: 2 additions & 2 deletions queue_services/entity-emailer/tests/unit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ def prep_amalgamation_filing(session, identifier, payment_id, option, legal_name
business_id=business.id, bootstrap_id=temp_identifier)
filing.payment_completion_date = filing.filing_date
filing.save()
if option == Filing.Status.COMPLETED.value:
if option in [Filing.Status.COMPLETED.value, 'bn']:
uow = versioning_manager.unit_of_work(session)
transaction = uow.create_transaction(session)
filing.transaction_id = transaction.id
Expand Down Expand Up @@ -679,7 +679,7 @@ def prep_continuation_in_filing(session, identifier, payment_id, option):
business_id=business.id, bootstrap_id=temp_identifier)
filing.payment_completion_date = filing.filing_date
filing.save()
if option == Filing.Status.COMPLETED.value:
if option in [Filing.Status.COMPLETED.value, 'bn']:
uow = versioning_manager.unit_of_work(session)
transaction = uow.create_transaction(session)
filing.transaction_id = transaction.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@
from legal_api.models import Business

from entity_emailer.email_processors import bn_notification
from tests.unit import prep_incorp_filing, prep_registration_filing
from tests.unit import (
prep_amalgamation_filing,
prep_continuation_in_filing,
prep_incorp_filing,
prep_registration_filing,
)


def test_bn_notificaton(app, session):
def test_incorporation_bn_notificaton(app, session):
"""Assert that the bn email processor builds the email correctly."""
# setup filing + business for email
identifier = 'BC1234567'
Expand All @@ -40,6 +45,46 @@ def test_bn_notificaton(app, session):
assert email['content']['attachments'] == []


def test_amalgamation_bn_notificaton(app, session):
"""Assert bn notification email for Amalgamation filing."""
# setup filing + business for email
identifier = 'BC1234567'
filing = prep_amalgamation_filing(session, identifier, '1', 'bn', 'TED business')
business = Business.find_by_identifier(identifier)
# sanity check
assert filing.id
assert business.id
# run processor
email = bn_notification.process(
{'filingId': None, 'type': 'businessNumber', 'option': 'bn', 'identifier': 'BC1234567'})
# check email values
assert '[email protected]' in email['recipients']
assert '[email protected]' in email['recipients']
assert email['content']['subject'] == f'{business.legal_name} - Business Number Information'
assert email['content']['body']
assert email['content']['attachments'] == []


def test_continuation_bn_notificaton(mocker, app, session):
"""Assert bn notification email for Continuation filing."""
# setup filing + business for email
identifier = 'BC1234567'
filing = prep_continuation_in_filing(session, identifier, '1', 'bn')
business = Business.find_by_identifier(identifier)
# sanity check
assert filing.id
assert business.id
# run processor
email = bn_notification.process(
{'filingId': None, 'type': 'businessNumber', 'option': 'bn', 'identifier': 'BC1234567'})
# check email values
assert '[email protected]' in email['recipients']
assert '[email protected]' in email['recipients']
assert email['content']['subject'] == f'{business.legal_name} - Business Number Information'
assert email['content']['body']
assert email['content']['attachments'] == []


def test_bn_move_notificaton(app, session):
"""Assert that the bn move email processor builds the email correctly."""
# setup filing + business for email
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
# limitations under the License.
"""The Unit Tests for the mras email processor."""
from entity_emailer.email_processors import mras_notification
from tests.unit import prep_incorp_filing
from tests.unit import prep_amalgamation_filing, prep_continuation_in_filing, prep_incorp_filing


def test_mras_notification(app, session):
"""Assert that the legal name is changed."""
def test_incorporation_app_mras_notification(app, session):
"""Assert mras notification email for Incorporation application filing."""
# setup filing + business for email
filing = prep_incorp_filing(session, 'BC1234567', '1', 'mras')
# run processor
Expand All @@ -28,3 +28,32 @@ def test_mras_notification(app, session):
assert email['content']['subject'] == 'BC Business Registry Partner Information'
assert email['content']['body']
assert email['content']['attachments'] == []


def test_amalgamation_mras_notification(app, session):
"""Assert mras notification email for Amalgamation filing."""
# setup filing + business for email
filing = prep_amalgamation_filing(session, 'BC1234567', '1', 'mras', 'TED business')
# run processor
email = mras_notification.process(
{'filingId': filing.id, 'type': 'amalgamationApplication', 'option': 'mras'})
# check email values
assert email['recipients'] == '[email protected]'
assert email['content']['subject'] == 'BC Business Registry Partner Information'
assert email['content']['body']
assert email['content']['attachments'] == []


def test_continuation_mras_notification(app, session):
"""Assert mras notification email for Continuation In filing."""
# setup filing + business for email
filing = prep_continuation_in_filing(session, 'BC1234567', '1', 'mras')

# run processor
email = mras_notification.process(
{'filingId': filing.id, 'type': 'continuationIn', 'option': 'mras'})
# check email values
assert email['recipients'] == '[email protected]'
assert email['content']['subject'] == 'BC Business Registry Partner Information'
assert email['content']['body']
assert email['content']['attachments'] == []
Loading