diff --git a/Frontend/CO.CDP.OrganisationApp.Tests/FormsEngineTests.cs b/Frontend/CO.CDP.OrganisationApp.Tests/FormsEngineTests.cs index 1795c3c91..5fba8863b 100644 --- a/Frontend/CO.CDP.OrganisationApp.Tests/FormsEngineTests.cs +++ b/Frontend/CO.CDP.OrganisationApp.Tests/FormsEngineTests.cs @@ -295,7 +295,7 @@ public async Task GetFormSectionAsync_ShouldFetchChoicesFromCustomChoiceProvider expectedResponse.Questions[0].Options.Choices = new Dictionary() { { $@"{{""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"; @@ -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())) .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); diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Forms/ChoiceProviderStrategies/ExclusionAppliesToChoiceProviderStrategy.cs b/Frontend/CO.CDP.OrganisationApp/Pages/Forms/ChoiceProviderStrategies/ExclusionAppliesToChoiceProviderStrategy.cs index 1ffcef16d..16ffda130 100644 --- a/Frontend/CO.CDP.OrganisationApp/Pages/Forms/ChoiceProviderStrategies/ExclusionAppliesToChoiceProviderStrategy.cs +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Forms/ChoiceProviderStrategies/ExclusionAppliesToChoiceProviderStrategy.cs @@ -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; }