Skip to content

Commit

Permalink
DP-556 - OrganisationType implemented (#714)
Browse files Browse the repository at this point in the history
* DP-556 - OrganisationType (or rather OperationType) implemented
* DP-556 - Fixed return type to IList; Basic test coverage added
* DP-556 - OperationTypes test fixed
* DP-566 - Enum values fixed
* DP-566 - Tests parallel execution fixed
* DP-556 - Bad merge remains removed
  • Loading branch information
maciej-goaco authored Oct 7, 2024
1 parent 38cfe8b commit c035238
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public async Task OnGet_SetSupplierInformation()
_model.SupplierInformation.Should().Be(supplierInfo);
_model.SupplierInformation?.OperationTypes.Should().NotBeNull();
_model.SupplierInformation?.OperationTypes.Should().BeOfType<List<OperationType>>();
_model.SupplierInformation?.OperationTypes.Should().Contain(OperationType.SmallorMediumSized);
_model.SupplierInformation?.OperationTypes.Should().Contain(OperationType.SmallOrMediumSized);
_model.SupplierInformation?.OperationTypes.Should().Contain(OperationType.NonGovernmental);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static SupplierInformation CreateSupplierInformationClientModel(
return new SupplierInformation(
organisationName: "FakeOrg",
supplierType: SupplierType.Organisation,
operationTypes: new List<OperationType>() { OperationType.SmallorMediumSized, OperationType.NonGovernmental },
operationTypes: new List<OperationType>() { OperationType.SmallOrMediumSized, OperationType.NonGovernmental },
completedRegAddress: true,
completedPostalAddress: completedPostalAddress,
completedVat: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public async Task OnPost_ValidModelState_ReturnsRedirectToSupplierBasicInformati
{
var id = Guid.NewGuid();
_model.Id = id;
_model.SelectedOperationTypes = new List<OperationType> { OperationType.SmallorMediumSized };
_model.SelectedOperationTypes = new List<OperationType> { OperationType.SmallOrMediumSized };

_organisationClientMock.Setup(client => client.GetOrganisationAsync(id))
.ReturnsAsync(SupplierDetailsFactory.GivenOrganisationClientModel(id));
Expand Down Expand Up @@ -89,7 +89,7 @@ public void ValidateModel_WithNoneAndOtherOperationTypes_ShouldReturnValidationE
SelectedOperationTypes = new List<OperationType>
{
OperationType.None,
OperationType.SmallorMediumSized
OperationType.SmallOrMediumSized
}
};

Expand Down
4 changes: 2 additions & 2 deletions Frontend/CO.CDP.OrganisationApp/Constants/OperationTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static string Description(this OperationType operationType)
{
return operationType switch
{
OperationType.SmallorMediumSized => "As a small or medium-sized enterprise",
OperationType.SmallOrMediumSized => "As a small or medium-sized enterprise",
OperationType.NonGovernmental => "As a non-governmental organisation that is value-driven and which principally reinvests its surpluses to further social, environmental or cultural objectives",
OperationType.SupportedEmploymentProvider => "As a supported employment provider",
OperationType.PublicService => "As a public service mutual",
Expand All @@ -22,7 +22,7 @@ public static string ShortDescription(this OperationType operationType)
{
return operationType switch
{
OperationType.SmallorMediumSized => "Small or medium-sized enterprise",
OperationType.SmallOrMediumSized => "Small or medium-sized enterprise",
OperationType.NonGovernmental => "Non-governmental organisation ",
OperationType.SupportedEmploymentProvider => "Supported employment provider",
OperationType.PublicService => "Public service mutual",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
<div class="govuk-checkboxes" data-module="govuk-checkboxes">
<div class="govuk-checkboxes__item">
<input class="govuk-checkboxes__input" id="chkSmallOrMediumAized"
name="SelectedOperationTypes" type="checkbox" value="@OperationType.SmallorMediumSized" @IsSelected(OperationType.SmallorMediumSized) />
name="SelectedOperationTypes" type="checkbox" value="@OperationType.SmallOrMediumSized" @IsSelected(OperationType.SmallOrMediumSized) />
<label class="govuk-label govuk-checkboxes__label" for="chkSmallOrMediumAized">
@OperationType.SmallorMediumSized.Description()
@OperationType.SmallOrMediumSized.Description()
</label>
</div>
<details class="govuk-details" data-module="govuk-details">
Expand Down
7 changes: 7 additions & 0 deletions Services/CO.CDP.DataSharing.WebApi.Tests/EntityFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ internal static List<ConnectedEntity> GetMockAdditionalEntities()
return mockEntities;
}

internal static IList<OperationType> GetOperationTypes()
{
var mockOperationType = new List<OperationType> { OperationType.SmallOrMediumSized };

return mockOperationType;
}

public static Organisation GivenOrganisation(
Guid? guid = null,
Tenant? tenant = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,17 @@ public async Task ItReturnsMappedSupplierInformationWhenSharedConsentIsFound()

var mockAssociatedPersons = EntityFactory.GetMockAssociatedPersons();
var mockAdditionalEntities = EntityFactory.GetMockAdditionalEntities();
var mockOperationTypes = EntityFactory.GetOperationTypes();

_organisationRepository.Setup(repo => repo.GetConnectedIndividualTrusts(organisationId))
.ReturnsAsync(mockAssociatedPersons);

_organisationRepository.Setup(repo => repo.GetConnectedOrganisations(organisationId))
.ReturnsAsync(mockAdditionalEntities);

_organisationRepository.Setup(repo => repo.GetOperationTypes(organisationId))
.ReturnsAsync(mockOperationTypes);

return (shareCode, organisationId, organisationGuid, formId);
}

Expand Down Expand Up @@ -172,6 +176,10 @@ private void AssertRoles(IEnumerable<PartyRole>? roles)
private void AssertDetails(Details? details)
{
details.Should().NotBeNull();
details?.Scale.Should().Be("small");
details?.Vcse.Should().Be(false);
details?.ShelteredWorkshop.Should().Be(false);
details?.PublicServiceMissionOrganization.Should().Be(false);
}

private void AssertSupplierInformationData(SupplierInformationData? supplierInformationData)
Expand Down
4 changes: 4 additions & 0 deletions Services/CO.CDP.DataSharing.WebApi/Model/Details.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ namespace CO.CDP.DataSharing.WebApi.Model;
public class Details
{
public LegalForm? LegalForm { get; set; }
public string? Scale { get; set; }
public bool Vcse { get; set; }
public bool ShelteredWorkshop { get; set; }
public bool PublicServiceMissionOrganization { get; set; }
}

public record LegalForm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,15 @@ public class GetSharedDataUseCase(
private async Task<Details> GetDetails(SharedConsent sharedConsent)
{
var legalForm = await organisationRepository.GetLegalForm(sharedConsent.OrganisationId);
var operationTypes = await organisationRepository.GetOperationTypes(sharedConsent.OrganisationId);

return new Details
{
LegalForm = legalForm != null ? mapper.Map<LegalForm>(legalForm) : null
LegalForm = legalForm != null ? mapper.Map<LegalForm>(legalForm) : null,
Scale = operationTypes.Contains(OperationType.SmallOrMediumSized) ? "small" : "large",
Vcse = operationTypes.Contains(OperationType.NonGovernmental),
ShelteredWorkshop = operationTypes.Contains(OperationType.SupportedEmploymentProvider),
PublicServiceMissionOrganization = operationTypes.Contains(OperationType.PublicService)
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,43 @@ public async Task GetConnectedOrganisations_WhenNoConnectedEntitiesExist_Returns
result.Should().BeEmpty();
}

[Fact]
public async Task GetOperationTypes_WhenNoOperationTypeExists_ReturnsNull()
{
using var repository = OrganisationRepository();

var organisation = GivenOrganisation();
organisation.SupplierInfo = GivenSupplierInformation();
organisation.SupplierInfo.OperationTypes = [];

using var context = postgreSql.OrganisationInformationContext();
await context.Organisations.AddAsync(organisation);
await context.SaveChangesAsync();

var result = await repository.GetOperationTypes(organisation.Id);

result.Should().BeEmpty();
}

[Fact]
public async Task GetOperationTypes_WhenOperationTypeExists_ReturnsEmptyList()
{
using var repository = OrganisationRepository();

var organisation = GivenOrganisation();
organisation.SupplierInfo = GivenSupplierInformation();
organisation.SupplierInfo.OperationTypes = [OperationType.SmallOrMediumSized];

using var context = postgreSql.OrganisationInformationContext();
await context.Organisations.AddAsync(organisation);
await context.SaveChangesAsync();

var result = await repository.GetOperationTypes(organisation.Id);

result.Should().NotBeNull();
result.Should().Contain(OperationType.SmallOrMediumSized);
}

private IOrganisationRepository OrganisationRepository()
{
return new DatabaseOrganisationRepository(postgreSql.OrganisationInformationContext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ public async Task<IList<ConnectedEntity>> GetConnectedOrganisations(int organisa
return organisation?.SupplierInfo?.LegalForm;
}

public async Task<IList<OperationType>> GetOperationTypes(int organisationId)
{
var organisation = await context.Organisations
.Where(x => x.Id == organisationId)
.Include(x => x.SupplierInfo)
.FirstOrDefaultAsync();

return organisation?.SupplierInfo?.OperationTypes ?? [];
}

public void Save(Organisation organisation)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ public class DuplicateOrganisationException(string message, Exception? cause = n
public Task<IList<ConnectedEntity>> GetConnectedOrganisations(int organisationId);

public Task<Organisation.LegalForm?> GetLegalForm(int organisationId);

public Task<IList<OperationType>> GetOperationTypes(int organisationId);
}
2 changes: 1 addition & 1 deletion Services/CO.CDP.OrganisationInformation/OperationType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace CO.CDP.OrganisationInformation;
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum OperationType
{
SmallorMediumSized = 1,
SmallOrMediumSized,
NonGovernmental,
SupportedEmploymentProvider,
PublicService,
Expand Down

0 comments on commit c035238

Please sign in to comment.