-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/dp-875-Informal-consortium-add-addit…
…ional-organisations
- Loading branch information
Showing
31 changed files
with
542 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
Services/CO.CDP.Organisation.WebApi.Tests/UseCase/GetLatestMouUseCaseTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
using AutoMapper; | ||
using CO.CDP.Organisation.WebApi.Model; | ||
using CO.CDP.Organisation.WebApi.Tests.AutoMapper; | ||
using CO.CDP.Organisation.WebApi.UseCase; | ||
using CO.CDP.OrganisationInformation; | ||
using CO.CDP.OrganisationInformation.Persistence; | ||
using FluentAssertions; | ||
using Moq; | ||
using Persistence = CO.CDP.OrganisationInformation.Persistence; | ||
using Person = CO.CDP.OrganisationInformation.Persistence.Person; | ||
|
||
namespace CO.CDP.Organisation.WebApi.Tests.UseCase; | ||
|
||
public class GetLatestMouUseCaseTest(AutoMapperFixture mapperFixture) | ||
: IClassFixture<AutoMapperFixture> | ||
{ | ||
private readonly Mock<IOrganisationRepository> _organisationRepository = new(); | ||
private GetLatestMouUseCase _useCase => new GetLatestMouUseCase(_organisationRepository.Object, mapperFixture.Mapper); | ||
|
||
[Fact] | ||
public async Task Execute_ShouldReturnMappedMou_WhenLatestMouExists() | ||
{ | ||
var latestMouEntity = new Persistence.Mou | ||
{ | ||
Id = 1, | ||
Guid = Guid.NewGuid(), | ||
FilePath = "/path/to/mou.pdf", | ||
CreatedOn = DateTimeOffset.UtcNow, | ||
UpdatedOn = DateTimeOffset.UtcNow | ||
}; | ||
|
||
var mappedMou = new CO.CDP.Organisation.WebApi.Model.Mou | ||
{ | ||
Id = latestMouEntity.Guid, | ||
FilePath = latestMouEntity.FilePath, | ||
CreatedOn = latestMouEntity.CreatedOn | ||
}; | ||
|
||
_organisationRepository | ||
.Setup(repo => repo.GetLatestMou()) | ||
.ReturnsAsync(latestMouEntity); | ||
|
||
var result = await _useCase.Execute(); | ||
|
||
result.Should().BeEquivalentTo(mappedMou); | ||
|
||
_organisationRepository.Verify(repo => repo.GetLatestMou(), Times.Once); | ||
} | ||
|
||
[Fact] | ||
public async Task Execute_ShouldThrowUnknownMouException_WhenLatestMouIsNull() | ||
{ | ||
_organisationRepository | ||
.Setup(repo => repo.GetLatestMou()) | ||
.ReturnsAsync((Persistence.Mou)null!); | ||
|
||
Func<Task> act = async () => await _useCase.Execute(); | ||
|
||
await act.Should().ThrowAsync<UnknownMouException>() | ||
.WithMessage("No MOU found."); | ||
|
||
_organisationRepository.Verify(repo => repo.GetLatestMou(), Times.Once); | ||
} | ||
|
||
public static Person FakePerson( | ||
Guid? guid = null, | ||
string? userUrn = null, | ||
string firstname = "Jon", | ||
string lastname = "doe", | ||
string? email = null, | ||
string phone = "07925123123", | ||
List<string>? scopes = null, | ||
Tenant? tenant = null, | ||
List<(Persistence.Organisation, List<string>)>? organisationsWithScope = null | ||
) | ||
{ | ||
scopes = scopes ?? []; | ||
var personGuid = guid ?? Guid.NewGuid(); | ||
var person = new Person | ||
{ | ||
Guid = personGuid, | ||
UserUrn = userUrn ?? $"urn:fdc:gov.uk:2022:{Guid.NewGuid()}", | ||
FirstName = firstname, | ||
LastName = lastname, | ||
Email = email ?? $"jon{personGuid}@example.com", | ||
Phone = phone, | ||
Scopes = scopes | ||
}; | ||
if (tenant != null) | ||
{ | ||
person.Tenants.Add(tenant); | ||
} | ||
|
||
foreach (var organisationWithScope in organisationsWithScope ?? []) | ||
{ | ||
person.PersonOrganisations.Add( | ||
new OrganisationPerson | ||
{ | ||
Person = person, | ||
Organisation = organisationWithScope.Item1, | ||
Scopes = organisationWithScope.Item2 | ||
} | ||
); | ||
} | ||
|
||
return person; | ||
} | ||
|
||
private static Persistence.Organisation FakeOrganisation(bool? withBuyerInfo = true) | ||
{ | ||
Persistence.Organisation org = new() | ||
{ | ||
Id = 1, | ||
Guid = Guid.NewGuid(), | ||
Name = "FakeOrg", | ||
Tenant = new Tenant | ||
{ | ||
Guid = Guid.NewGuid(), | ||
Name = "Tenant 101" | ||
}, | ||
ContactPoints = | ||
[ | ||
new Persistence.Organisation.ContactPoint | ||
{ | ||
Email = "contact@test.org" | ||
} | ||
], | ||
Type = OrganisationType.Organisation | ||
}; | ||
|
||
if (withBuyerInfo == true) | ||
{ | ||
var devolvedRegulations = new List<DevolvedRegulation>(); | ||
devolvedRegulations.Add(DevolvedRegulation.NorthernIreland); | ||
|
||
org.BuyerInfo = new Persistence.Organisation.BuyerInformation | ||
{ | ||
BuyerType = "FakeBuyerType", | ||
DevolvedRegulations = devolvedRegulations, | ||
}; | ||
} | ||
|
||
return org; | ||
} | ||
} |
147 changes: 147 additions & 0 deletions
147
Services/CO.CDP.Organisation.WebApi.Tests/UseCase/GetMouUseCaseTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
using AutoMapper; | ||
using CO.CDP.Organisation.WebApi.Model; | ||
using CO.CDP.Organisation.WebApi.Tests.AutoMapper; | ||
using CO.CDP.Organisation.WebApi.UseCase; | ||
using CO.CDP.OrganisationInformation; | ||
using CO.CDP.OrganisationInformation.Persistence; | ||
using FluentAssertions; | ||
using Moq; | ||
using Persistence = CO.CDP.OrganisationInformation.Persistence; | ||
using Person = CO.CDP.OrganisationInformation.Persistence.Person; | ||
|
||
namespace CO.CDP.Organisation.WebApi.Tests.UseCase; | ||
|
||
public class GetMouUseCaseTest(AutoMapperFixture mapperFixture) | ||
: IClassFixture<AutoMapperFixture> | ||
{ | ||
private readonly Mock<IOrganisationRepository> _organisationRepository = new(); | ||
private GetMouUseCase _useCase => new GetMouUseCase(_organisationRepository.Object, mapperFixture.Mapper); | ||
|
||
[Fact] | ||
public async Task Execute_ShouldReturnMappedMou_WhenLatestMouExists() | ||
{ | ||
var mouId = Guid.NewGuid(); | ||
var mouEntity = new Persistence.Mou | ||
{ | ||
Id = 1, | ||
Guid = mouId, | ||
FilePath = "/path/to/mou.pdf", | ||
CreatedOn = DateTimeOffset.UtcNow, | ||
UpdatedOn = DateTimeOffset.UtcNow | ||
}; | ||
|
||
var mappedMou = new Model.Mou | ||
{ | ||
Id = mouId, | ||
FilePath = mouEntity.FilePath, | ||
CreatedOn = mouEntity.CreatedOn | ||
}; | ||
|
||
_organisationRepository | ||
.Setup(repo => repo.GetMou(mouId)) | ||
.ReturnsAsync(mouEntity); | ||
|
||
var result = await _useCase.Execute(mouId); | ||
|
||
result.Should().BeEquivalentTo(mappedMou); | ||
|
||
_organisationRepository.Verify(repo => repo.GetMou(mouId), Times.Once); | ||
} | ||
|
||
[Fact] | ||
public async Task Execute_ShouldThrowUnknownMouException_WhenLatestMouIsNull() | ||
{ | ||
var mouId = Guid.NewGuid(); | ||
_organisationRepository | ||
.Setup(repo => repo.GetMou(mouId)) | ||
.ReturnsAsync((Persistence.Mou)null!); | ||
|
||
Func<Task> act = async () => await _useCase.Execute(mouId); | ||
|
||
await act.Should().ThrowAsync<UnknownMouException>() | ||
.WithMessage("No MOU found."); | ||
|
||
_organisationRepository.Verify(repo => repo.GetMou(mouId), Times.Once); | ||
} | ||
|
||
public static Person FakePerson( | ||
Guid? guid = null, | ||
string? userUrn = null, | ||
string firstname = "Jon", | ||
string lastname = "doe", | ||
string? email = null, | ||
string phone = "07925123123", | ||
List<string>? scopes = null, | ||
Tenant? tenant = null, | ||
List<(Persistence.Organisation, List<string>)>? organisationsWithScope = null | ||
) | ||
{ | ||
scopes = scopes ?? []; | ||
var personGuid = guid ?? Guid.NewGuid(); | ||
var person = new Person | ||
{ | ||
Guid = personGuid, | ||
UserUrn = userUrn ?? $"urn:fdc:gov.uk:2022:{Guid.NewGuid()}", | ||
FirstName = firstname, | ||
LastName = lastname, | ||
Email = email ?? $"jon{personGuid}@example.com", | ||
Phone = phone, | ||
Scopes = scopes | ||
}; | ||
if (tenant != null) | ||
{ | ||
person.Tenants.Add(tenant); | ||
} | ||
|
||
foreach (var organisationWithScope in organisationsWithScope ?? []) | ||
{ | ||
person.PersonOrganisations.Add( | ||
new OrganisationPerson | ||
{ | ||
Person = person, | ||
Organisation = organisationWithScope.Item1, | ||
Scopes = organisationWithScope.Item2 | ||
} | ||
); | ||
} | ||
|
||
return person; | ||
} | ||
|
||
private static Persistence.Organisation FakeOrganisation(bool? withBuyerInfo = true) | ||
{ | ||
Persistence.Organisation org = new() | ||
{ | ||
Id = 1, | ||
Guid = Guid.NewGuid(), | ||
Name = "FakeOrg", | ||
Tenant = new Tenant | ||
{ | ||
Guid = Guid.NewGuid(), | ||
Name = "Tenant 101" | ||
}, | ||
ContactPoints = | ||
[ | ||
new Persistence.Organisation.ContactPoint | ||
{ | ||
Email = "contact@test.org" | ||
} | ||
], | ||
Type = OrganisationType.Organisation | ||
}; | ||
|
||
if (withBuyerInfo == true) | ||
{ | ||
var devolvedRegulations = new List<DevolvedRegulation>(); | ||
devolvedRegulations.Add(DevolvedRegulation.NorthernIreland); | ||
|
||
org.BuyerInfo = new Persistence.Organisation.BuyerInformation | ||
{ | ||
BuyerType = "FakeBuyerType", | ||
DevolvedRegulations = devolvedRegulations, | ||
}; | ||
} | ||
|
||
return org; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.