Skip to content

Commit

Permalink
VIH-10218 Fix for UpdateParticipantDetails Command parameters overwri…
Browse files Browse the repository at this point in the history
…te hearing and case type (#607)

* Fix for prod issue, where null parameters overwrite hearing and case role values

* Tidy up
  • Loading branch information
will-craig authored Sep 29, 2023
1 parent a8c6578 commit fd3f94b
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 35 deletions.
23 changes: 16 additions & 7 deletions VideoApi/VideoApi.DAL/Commands/UpdateParticipantDetailsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public class UpdateParticipantDetailsCommand : ICommand
public string HearingRole { get; set; }
public string CaseTypeGroup { get; set; }

public UpdateParticipantDetailsCommand(Guid conferenceId, Guid participantId, string fullname, string firstname,
public UpdateParticipantDetailsCommand(Guid conferenceId,
Guid participantId, string fullname, string firstname,
string lastname, string displayName, string representee, string contactEmail, string contactTelephone,
IList<LinkedParticipantDto> linkedParticipants, UserRole userRole, string hearingRole, string caseTypeGroup)
{
Expand Down Expand Up @@ -83,11 +84,17 @@ public async Task Handle(UpdateParticipantDetailsCommand command)
participantCasted.Representee = command.Representee;
participantCasted.ContactEmail = command.ContactEmail ?? participantCasted.ContactEmail;
participantCasted.ContactTelephone = command.ContactTelephone ?? participantCasted.ContactTelephone;
participantCasted.UserRole = command.UserRole;
participantCasted.HearingRole = command.HearingRole;
participantCasted.CaseTypeGroup = command.CaseTypeGroup;
}

if (command.UserRole != UserRole.None)
participantCasted.UserRole = command.UserRole;

if (command.HearingRole != null)
participantCasted.HearingRole = command.HearingRole;

if (command.CaseTypeGroup != null)
participantCasted.CaseTypeGroup = command.CaseTypeGroup;
}

// remove all linked participants where the current participant is the secondary, i.e., LinkedId
//
// get the Ids of the participants the primary participant is linked to
Expand All @@ -98,8 +105,10 @@ public async Task Handle(UpdateParticipantDetailsCommand command)
foreach (var linkedParticipant in linkedParticipants)
{
// get all linked participants between the secondary participant and primary participant
var linkedParticipantsFromSecondary = linkedParticipant.LinkedParticipants.Where(x =>
x.ParticipantId == linkedParticipant.Id && x.LinkedId == participant.Id).ToList();
var linkedParticipantsFromSecondary =
linkedParticipant.LinkedParticipants
.Where(x => x.ParticipantId == linkedParticipant.Id && x.LinkedId == participant.Id)
.ToList();

// remove each one
foreach (var linkedParticipantFromSecondary in linkedParticipantsFromSecondary)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public async Task Should_update_participant_details()
var participant = seededConference.GetParticipants().First();

var command = new UpdateParticipantDetailsCommand(_newConferenceId, participant.Id, "fullname", "firstName",
"lastName", "displayname", String.Empty, "[email protected]", "0123456789", new List<LinkedParticipantDto>(),
"lastName", "displayname", String.Empty, "[email protected]", "0123456789",
new List<LinkedParticipantDto>(),
UserRole.Individual, "Litigant in person", "Applicant");
await _handler.Handle(command);

Expand All @@ -88,30 +89,30 @@ public async Task Should_update_participant_details()

updatedParticipant.UpdatedAt.Should().BeAfter(updatedParticipant.CreatedAt.Value);
}

[Test]
public async Task Should_update_participant_details_and_linked_participants()
{
var conference = new ConferenceBuilder(true, null, DateTime.UtcNow.AddMinutes(5))
.WithConferenceStatus(ConferenceState.InSession)
.Build();

var participantA = new ParticipantBuilder(true).Build();
var participantB = new ParticipantBuilder(true).Build();
var participantC = new ParticipantBuilder(true).Build();

participantA.LinkedParticipants.Add(new LinkedParticipant(participantA.Id, participantB.Id, LinkedParticipantType.Interpreter));
participantB.LinkedParticipants.Add(new LinkedParticipant(participantB.Id, participantA.Id, LinkedParticipantType.Interpreter));

conference.AddParticipant(participantA);
conference.AddParticipant(participantB);
conference.Participants.Add(participantC);

var seededConference = await TestDataManager.SeedConference(conference);

TestContext.WriteLine($"New seeded conference id: {seededConference.Id}");
_newConferenceId = seededConference.Id;

var participant = seededConference.GetParticipants().First();

var newLinkedParticipants = new List<LinkedParticipantDto>()
Expand All @@ -129,11 +130,11 @@ public async Task Should_update_participant_details_and_linked_participants()
Type = LinkedParticipantType.Interpreter
}
};

var command = new UpdateParticipantDetailsCommand(_newConferenceId, participant.Id, "fullname", "firstName",
"lastName", "displayname", String.Empty, "[email protected]", "0123456789", newLinkedParticipants,
UserRole.Individual, "Litigant in person", "Applicant");

await _handler.Handle(command);

var updatedConference = await _conferenceByIdHandler.Handle(new GetConferenceByIdQuery(_newConferenceId));
Expand All @@ -156,7 +157,8 @@ public async Task Should_update_participant_details_and_linked_participants()
}

[Test]
public async Task Should_update_participant_details_and_linked_participants_When_linked_participant_only_on_one_participant()
public async Task
Should_update_participant_details_and_linked_participants_When_linked_participant_only_on_one_participant()
{
var conference = new ConferenceBuilder(true, null, DateTime.UtcNow.AddMinutes(5))
.WithConferenceStatus(ConferenceState.InSession)
Expand All @@ -166,7 +168,8 @@ public async Task Should_update_participant_details_and_linked_participants_When
var participantB = new ParticipantBuilder(true).Build();
var participantC = new ParticipantBuilder(true).Build();

participantA.LinkedParticipants.Add(new LinkedParticipant(participantA.Id, participantB.Id, LinkedParticipantType.Interpreter));
participantA.LinkedParticipants.Add(new LinkedParticipant(participantA.Id, participantB.Id,
LinkedParticipantType.Interpreter));

conference.AddParticipant(participantA);
conference.AddParticipant(participantB);
Expand Down Expand Up @@ -213,35 +216,37 @@ public async Task Should_update_participant_details_and_linked_participants_When
updatedParticipantC.LinkedParticipants.Should().NotContain(x => x.LinkedId == participantB.Id);
updatedParticipantC.LinkedParticipants.Should().Contain(x => x.LinkedId == participantA.Id);
}

[Test]
public async Task Should_throw_participant_link_exception_when_id_doesnt_match()
{
var conference = new ConferenceBuilder(true, null, DateTime.UtcNow.AddMinutes(5))
.WithConferenceStatus(ConferenceState.InSession)
.Build();

var participantA = new ParticipantBuilder(true).Build();
var participantB = new ParticipantBuilder(true).Build();
var participantC = new ParticipantBuilder(true).Build();

participantA.LinkedParticipants.Add(new LinkedParticipant(participantA.Id, participantB.Id, LinkedParticipantType.Interpreter));
participantB.LinkedParticipants.Add(new LinkedParticipant(participantB.Id, participantA.Id, LinkedParticipantType.Interpreter));

participantA.LinkedParticipants.Add(new LinkedParticipant(participantA.Id, participantB.Id,
LinkedParticipantType.Interpreter));
participantB.LinkedParticipants.Add(new LinkedParticipant(participantB.Id, participantA.Id,
LinkedParticipantType.Interpreter));

conference.AddParticipant(participantA);
conference.AddParticipant(participantB);
conference.Participants.Add(participantC);

var seededConference = await TestDataManager.SeedConference(conference);

TestContext.WriteLine($"New seeded conference id: {seededConference.Id}");
_newConferenceId = seededConference.Id;

var participant = seededConference.GetParticipants().First();

var fakeIdA = Guid.NewGuid();
var fakeIdC = Guid.NewGuid();

var newLinkedParticipants = new List<LinkedParticipantDto>()
{
new LinkedParticipantDto()
Expand All @@ -257,16 +262,16 @@ public async Task Should_throw_participant_link_exception_when_id_doesnt_match()
Type = LinkedParticipantType.Interpreter
}
};

var command = new UpdateParticipantDetailsCommand(_newConferenceId, participant.Id, "fullname", "firstName",
"lastName", "displayname", String.Empty, "[email protected]", "0123456789", newLinkedParticipants,
UserRole.Individual, "Litigant in person", "Applicant");

var exception = Assert.ThrowsAsync<ParticipantLinkException>(() => _handler.Handle(command));
exception.LinkRefId.Should().Be(participantA.ParticipantRefId);
exception.ParticipantRefId.Should().Be(fakeIdC);
}

[Test]
public async Task Should_update_participant_username_when_provided()
{
Expand All @@ -276,7 +281,8 @@ public async Task Should_update_participant_username_when_provided()
var participant = seededConference.GetParticipants().First();

var command = new UpdateParticipantDetailsCommand(_newConferenceId, participant.Id, "fullname", "firstName",
"lastName", "displayname", String.Empty, "[email protected]", "0123456789", new List<LinkedParticipantDto>(),
"lastName", "displayname", String.Empty, "[email protected]", "0123456789",
new List<LinkedParticipantDto>(),
UserRole.Individual, "Litigant in person", "Applicant")
{
Username = "[email protected]"
Expand All @@ -302,6 +308,44 @@ public async Task Should_update_participant_username_when_provided()
}
}

[Test]
public async Task Update_participant_details_when_case_hearing_user_role_properties_are_null()
{

var seededConference = await TestDataManager.SeedConference();

_newConferenceId = seededConference.Id;
var judge = seededConference.GetParticipants().First(e => e.HearingRole == "Judge");

var command = new UpdateParticipantDetailsCommand(_newConferenceId, judge.Id, "fullname", "firstName",
"lastName", "displayname", String.Empty, "[email protected]", "0123456789", new List<LinkedParticipantDto>(),
UserRole.None, null, null);

await _handler.Handle(command);

var updatedConference = await _conferenceByIdHandler.Handle(new GetConferenceByIdQuery(_newConferenceId));
var updatedJudge =
updatedConference.GetParticipants().Single(x => x.Id == judge.Id);

if (updatedJudge is Participant updatedParticipantCasted)
{
//userRole assertion
updatedParticipantCasted.UserRole.Should().NotBe(UserRole.None);
updatedParticipantCasted.UserRole.Should().Be(judge.UserRole);

//HearingRole assertion
updatedParticipantCasted.HearingRole.Should().NotBeNullOrEmpty();
updatedParticipantCasted.HearingRole.Should().Be(judge.HearingRole);

//HearingRole assertion
updatedParticipantCasted.CaseTypeGroup.Should().NotBeNullOrEmpty();
}
else
{
Assert.Fail("Participant is not of type Participant");
}

}

[TearDown]
public async Task TearDown()
Expand Down
18 changes: 14 additions & 4 deletions VideoApi/VideoApi/Controllers/ParticipantsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,20 @@ public async Task<IActionResult> UpdateParticipantDetailsAsync(Guid conferenceId
Type = x.Type.MapToDomainEnum()
}).ToList();

var updateParticipantDetailsCommand = new UpdateParticipantDetailsCommand(conferenceId, participantId,
request.Fullname, request.FirstName, request.LastName, request.DisplayName, request.Representee,
request.ContactEmail, request.ContactTelephone, linkedParticipants,
request.UserRole.MapToDomainEnum(), request.HearingRole, request.CaseTypeGroup);
var updateParticipantDetailsCommand = new UpdateParticipantDetailsCommand(conferenceId,
participantId,
request.Fullname,
request.FirstName,
request.LastName,
request.DisplayName,
request.Representee,
request.ContactEmail,
request.ContactTelephone,
linkedParticipants,
request.UserRole.MapToDomainEnum(),
request.HearingRole,
request.CaseTypeGroup);

if (!request.Username.IsNullOrEmpty())
{
updateParticipantDetailsCommand.Username = request.Username;
Expand Down

0 comments on commit fd3f94b

Please sign in to comment.