Skip to content

Commit

Permalink
Merge branch 'main' into feature/160874-dao-revoked
Browse files Browse the repository at this point in the history
  • Loading branch information
dneed-nimble authored Jun 4, 2024
2 parents 324e2dd + cf33922 commit 73abbd3
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class ExportedTransferProjectModel
public string? IncomingTrustUkprn { get; init; }
public string? LocalAuthority { get; init; }
public string? OutgoingTrustName { get; init; }
public string? OutgoingTrustUKPRN { get; init; }
public DateTime? ProposedAcademyTransferDate { get; init; }
public string? Region { get; init; }
public string? SchoolName { get; init; }
Expand All @@ -22,5 +23,6 @@ public class ExportedTransferProjectModel
public string? TransferReason { get; init; }
public string? TransferType { get; init; }
public string? Urn { get; init; }
public string? PFI { get; init; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,35 @@ public async Task GetExportedTransferProjects_ShouldReturnExpectedResponse()

// Mocking the data
var mockDecision = new Mock<IConversionAdvisoryBoardDecision>();

var mockTransferProject = new MockTransferProject("dummyOutgoingTrustUkprn", "dummyOutgoingTrustName", new List<MockTransferAcademyRecord>() {
new("dummyIncomingTrustUkprn1", "dummyOutgoingAcademyUkprn1", "dummyIncomingTrustName1", "dummyRegion", "dummyLocalAuthority")
}).CreateMock();

// Mock establishment data
var establishmentDto = new EstablishmentDto
{
Ukprn = "dummyOutgoingAcademyUkprn1",
Urn = "123456",
Name = "Dummy Academy",
LocalAuthorityName = "Local Authority1",
EstablishmentType = new NameAndCodeDto { Name = "Type1" },
Gor = new NameAndCodeDto { Name = "Region1" }
};


// Mock the setup to return the dummy project
mockRepository.Setup(repo => repo.SearchProjects(It.IsAny<IEnumerable<string>>(), It.IsAny<string>(), It.IsAny<IEnumerable<string>>(), It.IsAny<int>(), It.IsAny<int>())).ReturnsAsync((new List<ITransferProject>() { mockTransferProject.Object }, 1));
mockRepository.Setup(repo => repo.SearchProjects(It.IsAny<IEnumerable<string>>(), It.IsAny<string>(), It.IsAny<IEnumerable<string>>(), It.IsAny<int>(), It.IsAny<int>()))
.ReturnsAsync((new List<ITransferProject>() { mockTransferProject.Object }, 1));

// Set up behavior for methods
mockAdvisoryBoardDecisionGetDataByProjectIdQuery
.Setup(query => query.GetAdvisoryBoardDecisionById(It.IsAny<int>()))
.ReturnsAsync(mockDecision.Object);

mockAcademiesQueryService
.Setup(academiesQueryService => academiesQueryService.GetEstablishmentByUkprn(It.IsAny<string>()))
.ReturnsAsync(It.IsAny<EstablishmentDto>());
.Setup(service => service.GetBulkEstablishmentsByUkprn(It.IsAny<IEnumerable<string>>()))
.ReturnsAsync(new List<EstablishmentDto> { establishmentDto });

var service = new TransferProjectQueryService(
mockRepository.Object,
Expand All @@ -138,13 +150,22 @@ public async Task GetExportedTransferProjects_ShouldReturnExpectedResponse()

// Setting up Test Data
var dummyProjects = new List<ExportedTransferProjectModel>
{
GetDummyTransferProjectModel(
"dummyIncomingTrustName1",
"dummyIncomingTrustUkprn1",
"dummyOutgoingTrustName"
)
};
{
new ExportedTransferProjectModel
{
Id = 0,
IncomingTrustName = "dummyIncomingTrustName1",
IncomingTrustUkprn = "dummyIncomingTrustUkprn1",
OutgoingTrustName = "dummyOutgoingTrustName",
OutgoingTrustUKPRN = "dummyOutgoingTrustUkprn",
LocalAuthority = "Local Authority1",
Region = "Region1",
SchoolName = "Dummy Academy",
SchoolType = "Type1",
Urn = "123456",
PFI = " "
}
};
var expectedResponse = new PagedResultResponse<ExportedTransferProjectModel>(dummyProjects, 1);

// Testing the Method
Expand All @@ -154,6 +175,7 @@ public async Task GetExportedTransferProjects_ShouldReturnExpectedResponse()
result.Should().BeEquivalentTo(expectedResponse);
}


[Fact]
public async Task GetExportedTransferProjects_ShouldReturnNoResultsWhenFiltered()
{
Expand Down Expand Up @@ -192,6 +214,7 @@ public async Task GetExportedTransferProjectsWithMultipleAcademies_ShouldReturnE
// Mocking the data
var mockDecision = new Mock<IConversionAdvisoryBoardDecision>();
var mockTransferProject = new MockTransferProject("dummyOutgoingTrustUkprn", "dummyOutgoingTrustName", new List<MockTransferAcademyRecord>() {

new("dummyIncomingTrustUkprn1", "dummyOutgoingAcademyUkprn1", "dummyIncomingTrustName1", "dummyRegion", "dummyLocalAuthority"),
new("dummyIncomingTrustUkprn2", "dummyOutgoingAcademyUkprn2", "dummyIncomingTrustName2", "dummyRegion", "dummyLocalAuthority")
}).CreateMock();
Expand All @@ -204,12 +227,11 @@ public async Task GetExportedTransferProjectsWithMultipleAcademies_ShouldReturnE
.Setup(query => query.GetAdvisoryBoardDecisionById(It.IsAny<int>()))
.ReturnsAsync(mockDecision.Object);


List<EstablishmentDto> establishments = new List<EstablishmentDto>()
{
new EstablishmentDto() { Name = "dummyAcademy1", LocalAuthorityName = "dummyLocalAuthority1", Ukprn = "dummyOutgoingAcademyUkprn1" },
new EstablishmentDto() { Name = "dummyAcademy2", Ukprn = "dummyOutgoingAcademyUkprn2" }
};
{
new EstablishmentDto() { Name = "dummyAcademy1", LocalAuthorityName = "dummyLocalAuthority1", Ukprn = "dummyOutgoingAcademyUkprn1" },
new EstablishmentDto() { Name = "dummyAcademy2", Ukprn = "dummyOutgoingAcademyUkprn2" }
};

mockAcademiesQueryService.Setup(academiesQueryService => academiesQueryService.GetBulkEstablishmentsByUkprn(It.IsAny<IEnumerable<string>>()))
.ReturnsAsync(establishments);
Expand All @@ -222,16 +244,37 @@ public async Task GetExportedTransferProjectsWithMultipleAcademies_ShouldReturnE

// Setting up Test Data
var dummyProjects = new List<ExportedTransferProjectModel>
{
GetDummyTransferProjectModel(
"dummyIncomingTrustName1",
"dummyIncomingTrustUkprn1",
"dummyOutgoingTrustName",
"dummyAcademy1, dummyAcademy2",
"dummyLocalAuthority1"
)
};
var expectedResponse = new PagedResultResponse<ExportedTransferProjectModel>(dummyProjects, 1);
{
new ExportedTransferProjectModel
{
Id = 0,
IncomingTrustName = "dummyIncomingTrustName1",
IncomingTrustUkprn = "dummyIncomingTrustUkprn1",
OutgoingTrustName = "dummyOutgoingTrustName",
OutgoingTrustUKPRN = "dummyOutgoingTrustUkprn",
LocalAuthority = "dummyLocalAuthority1",
Region = null,
SchoolName = "dummyAcademy1",
SchoolType = null,
Urn = null,
PFI = " "
},
new ExportedTransferProjectModel
{
Id = 0,
IncomingTrustName = "dummyIncomingTrustName1",
IncomingTrustUkprn = "dummyIncomingTrustUkprn1",
OutgoingTrustName = "dummyOutgoingTrustName",
OutgoingTrustUKPRN = "dummyOutgoingTrustUkprn",
LocalAuthority = null,
Region = null,
SchoolName = "dummyAcademy2",
SchoolType = null,
Urn = null,
PFI = " "
}
};
var expectedResponse = new PagedResultResponse<ExportedTransferProjectModel>(dummyProjects, 2);

// Testing the Method
var result = await service.GetExportedTransferProjects(Enumerable.Empty<string>(), null, Enumerable.Empty<string>(), 1, 10);
Expand All @@ -240,27 +283,6 @@ public async Task GetExportedTransferProjectsWithMultipleAcademies_ShouldReturnE
result.Should().BeEquivalentTo(expectedResponse);
}

private static ExportedTransferProjectModel GetDummyTransferProjectModel(
string incomingTrustName,
string incomingTrustUkprn,
string outgoingTrustName,
string schoolName = "",
string localAuthority = ""
)
{
return new()
{
IncomingTrustName = incomingTrustName,
IncomingTrustUkprn = incomingTrustUkprn,
OutgoingTrustName = outgoingTrustName,
SchoolName = schoolName,
LocalAuthority = localAuthority,
Region = "",
SchoolType = "",
Urn = "0"
};
}


[Fact]
public async Task GetProjects_ReturnsFilteredProjects()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public TransferProjectExportService(ITransferProjectQueryService transferProject
private static Task<Stream> GenerateSpreadsheet(IEnumerable<ExportedTransferProjectModel> projects)
{
string[] headers = new[]{
"School", "URN", "School Type", "Incoming Trust", "Outgoing Trust", "Incoming Trust UKPRN", "Local Authority", "Region",
"Academy", "URN", "Academy Type", "Incoming Trust", "Incoming Trust UKPRN","Outgoing Trust", "Outgoing Trust UKPRN", "Local Authority", "Region",
"Advisory Board Date", "Decision Date", "Status", "Assigned To", "Reason for transfer", "Type of transfer",
"Proposed academy transfer date"
"Proposed academy transfer date", "PFI (Private Finance Initiative)"
};

var workbook = new XLWorkbook();
Expand All @@ -53,17 +53,19 @@ private static Task<Stream> GenerateSpreadsheet(IEnumerable<ExportedTransferProj
worksheet.Cell(row, 2).Value = project.Urn;
worksheet.Cell(row, 3).Value = project.SchoolType;
worksheet.Cell(row, 4).Value = project.IncomingTrustName;
worksheet.Cell(row, 5).Value = project.OutgoingTrustName;
worksheet.Cell(row, 6).Value = project.IncomingTrustUkprn;
worksheet.Cell(row, 7).Value = project.LocalAuthority;
worksheet.Cell(row, 8).Value = project.Region;
worksheet.Cell(row, 9).Value = project.AdvisoryBoardDate;
worksheet.Cell(row, 10).Value = project.DecisionDate;
worksheet.Cell(row, 11).Value = project.Status;
worksheet.Cell(row, 12).Value = project.AssignedUserFullName;
worksheet.Cell(row, 13).Value = project.TransferReason;
worksheet.Cell(row, 14).Value = project.TransferType;
worksheet.Cell(row, 15).Value = project.ProposedAcademyTransferDate;
worksheet.Cell(row, 5).Value = project.IncomingTrustUkprn;
worksheet.Cell(row, 6).Value = project.OutgoingTrustName;
worksheet.Cell(row, 7).Value = project.OutgoingTrustUKPRN;
worksheet.Cell(row, 8).Value = project.LocalAuthority;
worksheet.Cell(row, 9).Value = project.Region;
worksheet.Cell(row, 10).Value = project.AdvisoryBoardDate;
worksheet.Cell(row, 11).Value = project.DecisionDate;
worksheet.Cell(row, 12).Value = project.Status;
worksheet.Cell(row, 13).Value = project.AssignedUserFullName;
worksheet.Cell(row, 14).Value = project.TransferReason;
worksheet.Cell(row, 15).Value = project.TransferType;
worksheet.Cell(row, 16).Value = project.ProposedAcademyTransferDate;
worksheet.Cell(row, 17).Value = project.PFI;
row++;
}
worksheet.Columns().AdjustToContents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,30 +136,34 @@ private async Task<IEnumerable<ExportedTransferProjectModel>> MapExportedTransfe

foreach (var transferProject in atp)
{

if (transferProject == null)
{
continue;
}

var _ukprns = transferProject.TransferringAcademies.Select(ta => ta.OutgoingAcademyUkprn);
var establishmentsForTheseAcademies = establishments.Where(e => _ukprns.Contains(e.Ukprn));

var decision = decisions.SingleOrDefault(x => x.AdvisoryBoardDecisionDetails.TransferProjectId == transferProject.Id);
var project = await MapProject(transferProject, establishmentsForTheseAcademies, decision).ConfigureAwait(false);
projects.Add(project);
foreach (var transferringEstablishment in establishmentsForTheseAcademies)
{
var decision = decisions.SingleOrDefault(x => x.AdvisoryBoardDecisionDetails.TransferProjectId == transferProject.Id);
var transferringAcademy = transferProject.TransferringAcademies.Where(s => s.OutgoingAcademyUkprn == transferringEstablishment.Ukprn).Single();
var project = await MapProject(transferProject, transferringEstablishment, decision, $"{transferringAcademy.PFIScheme} {transferringAcademy.PFISchemeDetails}").ConfigureAwait(false);
projects.Add(project);
}
}

return projects.AsEnumerable();
}

private async Task<ExportedTransferProjectModel> MapProject(ITransferProject? project, IEnumerable<EstablishmentDto?> schools, IConversionAdvisoryBoardDecision? advisoryBoardDecision)
private async Task<ExportedTransferProjectModel> MapProject(ITransferProject? project, EstablishmentDto? school, IConversionAdvisoryBoardDecision? advisoryBoardDecision, string transferringAcademyPfi)
{
var transferringAcademies = project.TransferringAcademies;

var schoolNames = schools.Select(s => s?.Name).Distinct().JoinNonEmpty(", ");
var schoolTypes = schools.Select(s => s?.EstablishmentType?.Name).Distinct().JoinNonEmpty(", ");
var regions = schools.Select(s => s?.Gor?.Name).Distinct().JoinNonEmpty(", ");
var localAuthorities = schools.Select(s => s?.LocalAuthorityName).Distinct().JoinNonEmpty(", ");
var schoolName = school?.Name;
var schoolType = school.EstablishmentType?.Name;
var region = school.Gor?.Name;
var localAuthority = school.LocalAuthorityName;
var reason = project.SpecificReasonsForTransfer?.JoinNonEmpty(", ");

return new ExportedTransferProjectModel
Expand All @@ -170,16 +174,18 @@ private async Task<ExportedTransferProjectModel> MapProject(ITransferProject? pr
DecisionDate = advisoryBoardDecision?.AdvisoryBoardDecisionDetails?.AdvisoryBoardDecisionDate,
IncomingTrustName = transferringAcademies.FirstOrDefault()?.IncomingTrustName,
IncomingTrustUkprn = transferringAcademies.FirstOrDefault()?.IncomingTrustUkprn,
LocalAuthority = localAuthorities,
OutgoingTrustName = project.OutgoingTrustName,
LocalAuthority = localAuthority,
OutgoingTrustName = project?.OutgoingTrustName,
OutgoingTrustUKPRN = project?.OutgoingTrustUkprn,
ProposedAcademyTransferDate = project.TargetDateForTransfer,
Region = regions,
SchoolName = schoolNames,
SchoolType = schoolTypes,
Region = region,
SchoolName = schoolName,
SchoolType = schoolType,
Status = project.Status,
TransferReason = reason,
TransferType = project.WhoInitiatedTheTransfer,
Urn = project.Urn.ToString(),
Urn = school.Urn,
PFI = transferringAcademyPfi
};
}

Expand Down
Loading

0 comments on commit 73abbd3

Please sign in to comment.