Skip to content

Commit

Permalink
DP-557 - Basic test coverage for Legal Form added
Browse files Browse the repository at this point in the history
  • Loading branch information
maciej-goaco committed Oct 7, 2024
1 parent c035238 commit 5f90062
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
13 changes: 13 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,19 @@ internal static List<ConnectedEntity> GetMockAdditionalEntities()
return mockEntities;
}

internal static Organisation.LegalForm GetLegalForm()
{
var mockLegalForm = new Organisation.LegalForm
{
RegisteredUnderAct2006 = false,
RegisteredLegalForm = "Registered Legal Form 1",
LawRegistered = "Law Registered 1",
RegistrationDate = DateTimeOffset.UtcNow
};

return mockLegalForm;
}

internal static IList<OperationType> GetOperationTypes()
{
var mockOperationType = new List<OperationType> { OperationType.SmallOrMediumSized };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public async Task ItReturnsMappedSupplierInformationWhenSharedConsentIsFound()

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

_organisationRepository.Setup(repo => repo.GetConnectedIndividualTrusts(organisationId))
Expand All @@ -96,6 +97,9 @@ public async Task ItReturnsMappedSupplierInformationWhenSharedConsentIsFound()
_organisationRepository.Setup(repo => repo.GetConnectedOrganisations(organisationId))
.ReturnsAsync(mockAdditionalEntities);

_organisationRepository.Setup(repo => repo.GetLegalForm(organisationId))
.ReturnsAsync(mockLegalForm);

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

Expand Down Expand Up @@ -176,6 +180,10 @@ private void AssertRoles(IEnumerable<PartyRole>? roles)
private void AssertDetails(Details? details)
{
details.Should().NotBeNull();
details?.LegalForm?.RegisteredUnderAct2006.Should().Be(false);
details?.LegalForm?.RegisteredLegalForm.Should().Be("Registered Legal Form 1");
details?.LegalForm?.LawRegistered.Should().Be("Law Registered 1");
details?.LegalForm?.RegistrationDate.Should().Be(DateTimeOffset.UtcNow.ToString("yyyy-MM-dd"));
details?.Scale.Should().Be("small");
details?.Vcse.Should().Be(false);
details?.ShelteredWorkshop.Should().Be(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,46 @@ public async Task GetConnectedOrganisations_WhenNoConnectedEntitiesExist_Returns
result.Should().BeEmpty();
}

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

var organisation = GivenOrganisation();
organisation.SupplierInfo = GivenSupplierInformation();
organisation.SupplierInfo.LegalForm = null;

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

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

result.Should().BeNull();
}

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

var organisation = GivenOrganisation();
organisation.SupplierInfo = GivenSupplierInformation();
organisation.SupplierInfo.LegalForm = GivenSupplierLegalForm();

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

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

result?.Should().NotBeNull();
result?.RegisteredUnderAct2006.Should().Be(true);
result?.RegisteredLegalForm.Should().Be("Limited company");
result?.LawRegistered.Should().Be("England and Wales");
result?.RegistrationDate.Should().Be(DateTimeOffset.Parse("2005-12-02T00:00:00Z"));
}

[Fact]
public async Task GetOperationTypes_WhenNoOperationTypeExists_ReturnsNull()
{
Expand Down

0 comments on commit 5f90062

Please sign in to comment.