Skip to content

Commit

Permalink
CFS is down when PAD is created #5440 (#1310)
Browse files Browse the repository at this point in the history
  • Loading branch information
shabeeb-aot authored Jan 20, 2021
1 parent e66c7ee commit 6e5ea2f
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 0 deletions.
12 changes: 12 additions & 0 deletions queue_services/account-mailer/q_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,18 @@ def subscription_options():
'recipientEmail': 'foo@bar.com'
}
}
elif mode == 'pad_setup_failed':
payload = {
'specversion': '1.x-wip',
'type': f'{MessageType.PAD_SETUP_FAILED.value}',
'source': 'https://api.auth.bcregistry.gov.bc.ca/v1/invoices/{invoice.id}',
'id': auth_account_id,
'datacontenttype': 'application/json',
'data': {
'accountId': auth_account_id,
# 'recipientEmail': 'foo@bar.com'
}
}

await sc.publish(subject=subscription_options().get('subject'),
payload=json.dumps(payload).encode('utf-8'))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<base href="/">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="referrer" content="origin-when-cross-origin"/>
<meta name="author" content="BC Registries and Online Services">
<title>Your Account is Temporarily Suspended</title>
[[style.html]]
</head>
<body style="max-width: initial;">
<div style="font-family: Verdana, Arial, sans-serif; font-size: 16px; padding: 16px;width: 650px;margin: auto;">
<div style="margin-left: -6px; text-align: center;;">
[[logo.html]]
</div>
<p style="padding-top: 10px; padding-bottom: 10px">
When you setup pre-authorized debit, the bank information you entered was invalid.</p>
<p style="padding-top: 10px; padding-bottom: 10px">To unlock your account, please review and update your bank information.
</p>
<a style="display: block; width: 200px; padding: 15px 0; color: #ffffff; border: none; border-radius: 6px; background-color: #003366; text-align: center; text-decoration: none; font-size: 16px; font-weight: bold;margin-top: 10px;"
href="{{ url }}">Log in
</a>
</div>
</body>
</html>
3 changes: 3 additions & 0 deletions queue_services/account-mailer/src/account_mailer/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class MessageType(Enum):
ONLINE_BANKING_OVER_PAYMENT = 'bc.registry.payment.OverPaid'
ONLINE_BANKING_UNDER_PAYMENT = 'bc.registry.payment.UnderPaid'
ONLINE_BANKING_PAYMENT = 'bc.registry.payment.Payment'
PAD_SETUP_FAILED = 'bc.registry.payment.PadSetupFailed'


class SubjectType(Enum):
Expand All @@ -42,6 +43,7 @@ class SubjectType(Enum):
ADMIN_REMOVED_SUBJECT = '[BC Registries and Online Services] You have been removed as an administrator'
TEAM_MODIFIED_SUBJECT = '[BC Registries and Online Services] Change in Team members'
ONLINE_BANKING_PAYMENT_SUBJECT = '[BC Registries and Online Services] Online Banking payment has been received'
PAD_SETUP_FAILED = '[BC Registries and Online Services] Your Account is Temporarily Suspended'


class TemplateType(Enum):
Expand All @@ -56,3 +58,4 @@ class TemplateType(Enum):
ONLINE_BANKING_PAYMENT_TEMPLATE_NAME = 'online_banking_payment'
ONLINE_BANKING_OVER_PAYMENT_TEMPLATE_NAME = 'online_banking_over_payment'
ONLINE_BANKING_UNDER_PAYMENT_TEMPLATE_NAME = 'online_banking_under_payment'
PAD_SETUP_FAILED_TEMPLATE_NAME = 'pad_setup_failed'
11 changes: 11 additions & 0 deletions queue_services/account-mailer/src/account_mailer/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,17 @@ async def process_event(event_message: dict, flask_app):
'credit_amount': email_msg.get('creditAmount'),
}
email_dict = common_mailer.process(org_id, admin_emails, template_name, subject, **args)
elif message_type == MessageType.PAD_SETUP_FAILED.value:
email_msg = event_message.get('data')
template_name = TemplateType.PAD_SETUP_FAILED_TEMPLATE_NAME.value
org_id = email_msg.get('accountId')
admin_coordinator_emails = get_member_emails(org_id, (ADMIN,))
subject = SubjectType.PAD_SETUP_FAILED.value
args = {
'accountId': email_msg.get('accountId'),
}
email_dict = common_mailer.process(org_id, admin_coordinator_emails, template_name, subject,
**args)
if email_dict:
logger.debug('Extracted email msg Recipient: %s ', email_dict.get('recipients', ''))
process_email(email_dict, FLASK_APP, token)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,46 @@ async def test_online_banking_emails(app, session, stan_server, event_loop, clie
'subject') == SubjectType.ONLINE_BANKING_PAYMENT_SUBJECT.value
assert mock_send.call_args.args[0].get('attachments') is None
assert mock_send.call_args.args[0].get('content').get('body') is not None


@pytest.mark.asyncio
async def test_pad_failed_emails(app, session, stan_server, event_loop, client_id, events_stan, future):
"""Assert that events can be retrieved and decoded from the Queue."""
# Call back for the subscription
from account_mailer.worker import cb_subscription_handler

# vars
user = factory_user_model_with_contact()
org = factory_org_model()
factory_membership_model(user.id, org.id)
id = org.id

events_subject = 'test_subject'
events_queue = 'test_queue'
events_durable_name = 'test_durable'
with patch.object(notification_service, 'send_email', return_value=None) as mock_send:
# register the handler to test it
await subscribe_to_queue(events_stan,
events_subject,
events_queue,
events_durable_name,
cb_subscription_handler)

# add an event to queue
mail_details = {
'accountId': id
}
await helper_add_event_to_queue(events_stan, events_subject, org_id=id,
msg_type=MessageType.PAD_SETUP_FAILED.value,
mail_details=mail_details)

mock_send.assert_called
assert mock_send.call_args.args[0].get('recipients') == 'foo@bar.com'
assert mock_send.call_args.args[0].get('content').get(
'subject') == SubjectType.PAD_SETUP_FAILED.value
assert mock_send.call_args.args[0].get('attachments') is None
assert mock_send.call_args.args[0].get('content').get('body') is not None

await helper_add_event_to_queue(events_stan, events_subject, org_id=id,
msg_type=MessageType.PAD_SETUP_FAILED.value,
mail_details=mail_details)

0 comments on commit 6e5ea2f

Please sign in to comment.