Skip to content

Commit

Permalink
Merge pull request #2113 from SkillsFundingAgency/CON-1488-Employer-u…
Browse files Browse the repository at this point in the history
…nsubscribe-alert-summary-notification-email

CON-1488 employer unsubscribe alert summary notification email
  • Loading branch information
ben1stone-leftdfe authored Sep 4, 2020
2 parents 8b39a2b + 0999d0d commit 6e943f3
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,22 +133,5 @@ public async Task ShouldUnsubscribeFromOneAccount()
var setting = list.SingleOrDefault(m => m.AccountId == _command.AccountId);
setting.ReceiveNotifications.Should().BeFalse();
}

[Test]
public async Task ShouldSendEmail()
{
Email mask = null;
_command.NotificationSettingUrl = "this/is/url";
_notiApi.Setup(n => n.SendEmail(It.IsAny<Email>()))
.Callback<Email>(m => mask = m)
.Returns(Task.FromResult(1));

await _sut.Handle(_command);
mask.RecipientsAddress.Should().Be("[email protected]");
mask.Subject.Should().Be("UnsubscribeSuccessful");
mask.Tokens["name"].Should().Be("First name");
mask.Tokens["account_name"].Should().Be("Account Name");
mask.Tokens["link_notification_page"].Should().Be(_command.NotificationSettingUrl);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ await _mediator.SendAsync(
new UnsubscribeNotificationCommand
{
UserRef = userRef,
AccountId = accountId,
NotificationSettingUrl = settingUrl
AccountId = accountId
});

_logger.Info("Unsubscribed from alerts for user {userRef} in account {accountId}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,19 @@
{
<h1 class="heading-xlarge">You've already unsubscribed</h1>

<p>You've already unsubscribed from notifications for @Model.Data.AccountName</p>
<p>You've already unsubscribed from notifications for @{@Model.Data.AccountName}.</p>

<p>You'll continue to receive important service email, such as password resets.</p>
}
else
{
<p>You'll continue to receive important service emails, such as password resets.</p>
}
else
{
<h1 class="heading-xlarge">Unsubscribe successful</h1>
<p>You've unsubscribed from any further email notification for @Model.Data.AccountName</p>

<p>You'll receive one final email to confirm that we've unsubscribed you.</p>
<p>You've unsubscribed from any further email notifications for @{@Model.Data.AccountName}.</p>

<p>You'll continue to receive important service email, such as password resets.</p>
<p>You'll continue to receive important service emails, such as password resets.</p>
}

@Html.ActionLink("View notification settings","NotificationSettings", null, new { @class = "button" })

</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@ public class UnsubscribeNotificationCommand : IAsyncRequest
public string UserRef { get; set; }

public long AccountId { get; set; }

public string NotificationSettingUrl { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,38 +48,6 @@ protected override async Task HandleCore(UnsubscribeNotificationCommand command)

setting.ReceiveNotifications = false;
await _accountRepository.UpdateUserAccountSettings(command.UserRef, settings);

try
{
var user = _userRepository.GetUserByRef(command.UserRef);
await Task.WhenAll(user);
_logger.Info($"Sending email to unsubscriber: {user.Result.Id}");
var email = CreateEmail(user.Result, setting.Name, command.NotificationSettingUrl);
await _notificationsApi.SendEmail(email);
}
catch (Exception ex)
{
_logger.Error(ex, "Error sending email to notifications api");
throw;
}
}

private Email CreateEmail(User user, string accountName, string notificationSettingUrl)
{
return new Email
{
RecipientsAddress = user.Email,
TemplateId = "EmployerUnsubscribeAlertSummaryNotification",
ReplyToAddress = "[email protected]",
Subject = "UnsubscribeSuccessful",
SystemId = "x",
Tokens = new Dictionary<string, string>
{
{ "name", user.FirstName },
{ "account_name", accountName },
{ "link_notification_page", notificationSettingUrl ?? string.Empty }
}
};
}
}
}

0 comments on commit 6e943f3

Please sign in to comment.