Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DP-692 - Display first name and last name of connected entities of type individual or trustee on exclusions form #743

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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