Skip to content

Commit

Permalink
VIH-7335 Sending Notification Email for judge and ejud judge (#722)
Browse files Browse the repository at this point in the history
* VIH-7335 Sending Notification Email for judge and ejud judge

* VIH-7335 courtroom account username for judge only
  • Loading branch information
PrasannaDommalapati authored May 28, 2021
1 parent 4f44adf commit 5667d2d
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,113 @@ namespace AdminWebsite.UnitTests.Mappers.NotificationMappers
public class MapToDemoOrTestNotificationTests
{
[Test]
public void Should_map_joh_demo_or_test_notification()
public void Should_map_ejud_judge_demo_or_test_notification()
{
//Arrange
var hearing = new HearingDetailsResponse
{
Id = Guid.NewGuid(),
Participants = new List<ParticipantResponse>(),
ScheduledDateTime = new DateTime(2020, 2, 10, 12, 15, 0, DateTimeKind.Utc)
};
const NotificationType expectedNotificationType = NotificationType.EJudJudgeDemoOrTest;
const string testType = "Generic";
const string caseNumber = "MBFY/17364";

var participant = new ParticipantResponse
{
Id = Guid.NewGuid(),
Username = "[email protected]",
CaseRoleName = "caserolename",
ContactEmail = "[email protected]",
FirstName = "John",
HearingRoleName = "hearingrolename",
LastName = "Doe",
TelephoneNumber = "0123456789",
UserRoleName = "Judge",
DisplayName = "Johnny",
};

hearing.Participants.Add(participant);

var expectedParameters = new Dictionary<string, string>
{
{"case number", caseNumber},
{"test type", "Generic"},
{"date", "10 February 2020"},
{"time", "12:15 PM"},
{"judge", participant.DisplayName}
};

//Act
var result = AddNotificationRequestMapper.MapToDemoOrTestNotification(hearing, participant, caseNumber, testType);

//Assert
result.Should().NotBeNull();
result.HearingId.Should().Be(hearing.Id);
result.ParticipantId.Should().Be(participant.Id);
result.ContactEmail.Should().Be(participant.ContactEmail);
result.NotificationType.Should().Be(expectedNotificationType);
result.MessageType.Should().Be(MessageType.Email);
result.PhoneNumber.Should().Be(participant.TelephoneNumber);
result.Parameters.Should().BeEquivalentTo(expectedParameters);
}

[Test]
public void Should_map_judge_demo_or_test_notification()
{
//Arrange
var hearing = new HearingDetailsResponse
{
Id = Guid.NewGuid(),
Participants = new List<ParticipantResponse>(),
ScheduledDateTime = new DateTime(2020, 2, 10, 12, 15, 0, DateTimeKind.Utc)
};
const NotificationType expectedNotificationType = NotificationType.JudgeDemoOrTest;
const string testType = "Generic";
const string caseNumber = "MBFY/17364";

var participant = new ParticipantResponse
{
Id = Guid.NewGuid(),
Username = "[email protected]",
CaseRoleName = "caserolename",
ContactEmail = "[email protected]",
FirstName = "John",
HearingRoleName = "hearingrolename",
LastName = "Doe",
TelephoneNumber = "0123456789",
UserRoleName = "Judge",
DisplayName = "Johnny",
};

hearing.Participants.Add(participant);

var expectedParameters = new Dictionary<string, string>
{
{"case number", caseNumber},
{"test type", "Generic"},
{"date", "10 February 2020"},
{"time", "12:15 PM"},
{"judge", participant.DisplayName},
{"courtroom account username", participant.Username}
};

//Act
var result = AddNotificationRequestMapper.MapToDemoOrTestNotification(hearing, participant, caseNumber, testType);

//Assert
result.Should().NotBeNull();
result.HearingId.Should().Be(hearing.Id);
result.ParticipantId.Should().Be(participant.Id);
result.ContactEmail.Should().Be(participant.ContactEmail);
result.NotificationType.Should().Be(expectedNotificationType);
result.MessageType.Should().Be(MessageType.Email);
result.PhoneNumber.Should().Be(participant.TelephoneNumber);
result.Parameters.Should().BeEquivalentTo(expectedParameters);
}
[Test]
public void Should_map_ejud_joh_demo_or_test_notification()
{
//Arrange
var hearing = new HearingDetailsResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,18 @@ public async Task should_send_confirmation_email_when_hearing_is_generic_case_ty
await _service.SendHearingConfirmationEmail(_hearing);

_mocker.Mock<INotificationApiClient>()
.Verify(x => x.CreateNewNotificationAsync(It.IsAny<AddNotificationRequest>()), Times.Exactly(3));
.Verify(x => x.CreateNewNotificationAsync(It.IsAny<AddNotificationRequest>()), Times.Exactly(4));
}

[Test]
public async Task should_not_send_confirmation_email_when_hearing_is_generic_case_type_and_automated_test()
{
_hearing.CaseTypeName = "Generic";
_hearing.HearingTypeName = "Automated Test";
await _service.SendHearingConfirmationEmail(_hearing);

_mocker.Mock<INotificationApiClient>()
.Verify(x => x.CreateNewNotificationAsync(It.IsAny<AddNotificationRequest>()), Times.Never);
}

[Test]
Expand Down
41 changes: 30 additions & 11 deletions AdminWebsite/AdminWebsite/Mappers/AddNotificationRequestMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public static AddNotificationRequest MapToHearingAmendmentNotification(HearingDe
};

NotificationType notificationType;
if (participant.UserRoleName.Contains("Judge", StringComparison.InvariantCultureIgnoreCase) &&
!hearing.IsJudgeEmailEJud())
if (participant.UserRoleName.Contains("Judge", StringComparison.InvariantCultureIgnoreCase) &&
!hearing.IsJudgeEmailEJud())
{
notificationType = NotificationType.HearingAmendmentJudge;
parameters.Add("judge", participant.DisplayName);
Expand Down Expand Up @@ -115,8 +115,8 @@ public static AddNotificationRequest MapToHearingConfirmationNotification(Hearin
var parameters = InitConfirmReminderParams(hearing);

NotificationType notificationType;
if (participant.UserRoleName.Contains("Judge", StringComparison.InvariantCultureIgnoreCase) &&
!hearing.IsJudgeEmailEJud())
if (participant.UserRoleName.Contains("Judge", StringComparison.InvariantCultureIgnoreCase) &&
!hearing.IsJudgeEmailEJud())
{
notificationType = NotificationType.HearingConfirmationJudge;
parameters.Add("judge", participant.DisplayName);
Expand Down Expand Up @@ -211,23 +211,42 @@ public static AddNotificationRequest MapToMultiDayHearingConfirmationNotificatio
public static AddNotificationRequest MapToDemoOrTestNotification(HearingDetailsResponse hearing,
ParticipantResponse participant, string caseNumber, string testType)
{
var parameters = new Dictionary<string, string>();
var parameters = new Dictionary<string, string>()
{
{"case number",caseNumber},
{"test type",testType},
{"date",hearing.ScheduledDateTime.ToEmailDateGbLocale() },
{"time",hearing.ScheduledDateTime.ToEmailTimeGbLocale()},
{"username",participant.Username.ToLower()}
};

NotificationType notificationType = default;
if (hearing.IsParticipantAEJudJudicialOfficeHolder(participant.Id))
{
notificationType = NotificationType.EJudJohDemoOrTest;
parameters.Add("judicial office holder", $"{participant.FirstName} {participant.LastName}");
}
else if(!hearing.IsParticipantAJudicialOfficeHolderOrJudge(participant.Id))
else if (!hearing.IsParticipantAJudicialOfficeHolderOrJudge(participant.Id))
{
notificationType = NotificationType.ParticipantDemoOrTest;
parameters.Add("name", $"{participant.FirstName} {participant.LastName}");
}
parameters.Add("case number", caseNumber);
parameters.Add("test type", testType);
parameters.Add("date", hearing.ScheduledDateTime.ToEmailDateGbLocale());
parameters.Add("time", hearing.ScheduledDateTime.ToEmailTimeGbLocale());
parameters.Add("username", participant.Username.ToLower());
else if (participant.UserRoleName.Contains("Judge", StringComparison.InvariantCultureIgnoreCase))
{
if (hearing.IsJudgeEmailEJud())
{
notificationType = NotificationType.EJudJudgeDemoOrTest;
}
else
{
notificationType = NotificationType.JudgeDemoOrTest;
parameters.Add("courtroom account username", participant.Username);
}

parameters.Add("judge", participant.DisplayName);
parameters.Remove("username");
}

return new AddNotificationRequest
{
HearingId = hearing.Id,
Expand Down
1 change: 0 additions & 1 deletion AdminWebsite/AdminWebsite/Services/HearingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ public async Task ProcessGenericEmail(HearingDetailsResponse hearing, List<Parti
var participantsToEmail = participants ?? hearing.Participants;

var requests = participantsToEmail
.Where(x => !x.UserRoleName.Contains("Judge", StringComparison.CurrentCultureIgnoreCase))
.Select(participant =>
AddNotificationRequestMapper.MapToDemoOrTestNotification(hearing, participant, @case.Number, hearing.CaseTypeName))
.ToList();
Expand Down

0 comments on commit 5667d2d

Please sign in to comment.