Skip to content

Commit

Permalink
Merge pull request #743 from cabinetoffice/feature/exclusions-connect…
Browse files Browse the repository at this point in the history
…ed-person-last-name

DP-692 - Display first name and last name of connected entities of type individual or trustee on exclusions form
  • Loading branch information
andymantell authored Oct 10, 2024
2 parents 6530f66 + 5dba534 commit 41dc47a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
41 changes: 39 additions & 2 deletions Frontend/CO.CDP.OrganisationApp.Tests/FormsEngineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public async Task GetFormSectionAsync_ShouldFetchChoicesFromCustomChoiceProvider

expectedResponse.Questions[0].Options.Choices = new Dictionary<string, string>() {
{ $@"{{""id"":""{organisationId}"",""type"":""organisation""}}", "User's current organisation" },
{ "{\"id\":\"e4bdd7ef-8200-4257-9892-b16f43d1803e\",\"type\":\"connected-entity\"}", "Connected person" },
{ "{\"id\":\"e4bdd7ef-8200-4257-9892-b16f43d1803e\",\"type\":\"connected-entity\"}", "First name Last name" },
{ "{\"id\":\"4c8dccba-df39-4997-814b-7599ed9b5bed\",\"type\":\"connected-entity\"}", "Connected organisation" } };

expectedResponse.Questions[0].Options.ChoiceAnswerFieldName = "JsonValue";
Expand All @@ -315,11 +315,48 @@ public async Task GetFormSectionAsync_ShouldFetchChoicesFromCustomChoiceProvider
}
};

var connectedIndividualGuid = new Guid("e4bdd7ef-8200-4257-9892-b16f43d1803e");

_organisationClientMock.Setup(c => c.GetConnectedEntitiesAsync(It.IsAny<Guid>()))
.ReturnsAsync([
new ConnectedEntityLookup(new Guid("e4bdd7ef-8200-4257-9892-b16f43d1803e"), ConnectedEntityType.Individual, "Connected person", new Uri("http://whatever")),
new ConnectedEntityLookup(connectedIndividualGuid, ConnectedEntityType.Individual, "Connected person", new Uri("http://whatever")),
new ConnectedEntityLookup(new Guid("4c8dccba-df39-4997-814b-7599ed9b5bed"), ConnectedEntityType.Organisation, "Connected organisation", new Uri("http://whatever"))
]);
_organisationClientMock.Setup(c => c.GetConnectedEntityAsync(organisationId, connectedIndividualGuid))
.ReturnsAsync(new ConnectedEntity(
[],
"123",
null,
ConnectedEntityType.Individual,
false,
connectedIndividualGuid,
new ConnectedIndividualTrust(
ConnectedIndividualAndTrustCategory.PersonWithSignificantControlForIndividual,
ConnectedPersonType.Individual,
[],
null,
"First name",
3,
"Last name",
"British",
new Guid(),
"UK"
),
new ConnectedOrganisation(
ConnectedOrganisationCategory.AnyOtherOrganisationWithSignificantInfluenceOrControl,
[],
4,
null,
"law",
"name",
organisationId,
"legal form"
),
"123",
null,
"register name",
null
));
_organisationClientMock.Setup(c => c.GetOrganisationAsync(organisationId))
.ReturnsAsync(new Organisation.WebApiClient.Organisation([], [], null, null, organisationId, null, "User's current organisation", []));
_userInfoServiceMock.Setup(u => u.GetOrganisationId()).Returns(organisationId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@ public class ExclusionAppliesToChoiceProviderStrategy(IUserInfoService userInfoS

foreach (var entity in connectedEntities)
{
result[JsonSerializer.Serialize(new { id = entity.EntityId, type = "connected-entity" }, jsonSerializerOptions)] = entity.Name;
var name = entity.Name;

if (entity.EntityType == ConnectedEntityType.TrustOrTrustee || entity.EntityType == ConnectedEntityType.Individual)
{
var connectedEntityDetails = await organisationClient.GetConnectedEntityAsync((Guid)organisationId, entity.EntityId);
name = connectedEntityDetails.IndividualOrTrust.FirstName + " " + connectedEntityDetails.IndividualOrTrust.LastName;
}

result[JsonSerializer.Serialize(new { id = entity.EntityId, type = "connected-entity" }, jsonSerializerOptions)] = name;
}


Expand Down

0 comments on commit 41dc47a

Please sign in to comment.