diff --git a/Dfe.ManageFreeSchoolProjects/Dfe.ManageFreeSchoolProjects.API.Contracts/Project/Tasks/ProjectByTaskSummaryResponse.cs b/Dfe.ManageFreeSchoolProjects/Dfe.ManageFreeSchoolProjects.API.Contracts/Project/Tasks/ProjectByTaskSummaryResponse.cs index f41325ce7..353ea6f3b 100644 --- a/Dfe.ManageFreeSchoolProjects/Dfe.ManageFreeSchoolProjects.API.Contracts/Project/Tasks/ProjectByTaskSummaryResponse.cs +++ b/Dfe.ManageFreeSchoolProjects/Dfe.ManageFreeSchoolProjects.API.Contracts/Project/Tasks/ProjectByTaskSummaryResponse.cs @@ -53,6 +53,10 @@ public class ProjectByTaskSummaryResponse public TaskSummaryResponse CommissionedExternalExpert { get; set; } public TaskSummaryResponse MovingToOpen { get; set; } + + public int TaskCount { get; set; } + + public int CompletedTasks { get; set; } } public class TaskSummaryResponse diff --git a/Dfe.ManageFreeSchoolProjects/Dfe.ManageFreeSchoolProjects.API.Tests/Integration/GetProjectByTaskSummaryApiTests.cs b/Dfe.ManageFreeSchoolProjects/Dfe.ManageFreeSchoolProjects.API.Tests/Integration/GetProjectByTaskSummaryApiTests.cs index 9f85eecb5..74dab6857 100644 --- a/Dfe.ManageFreeSchoolProjects/Dfe.ManageFreeSchoolProjects.API.Tests/Integration/GetProjectByTaskSummaryApiTests.cs +++ b/Dfe.ManageFreeSchoolProjects/Dfe.ManageFreeSchoolProjects.API.Tests/Integration/GetProjectByTaskSummaryApiTests.cs @@ -6,6 +6,9 @@ using System.Net; using System.Net.Http.Json; using System.Threading.Tasks; +using Dfe.ManageFreeSchoolProjects.API.Contracts.Task; +using DocumentFormat.OpenXml.Spreadsheet; +using Kpi = Dfe.ManageFreeSchoolProjects.Data.Entities.Existing.Kpi; namespace Dfe.ManageFreeSchoolProjects.API.Tests.Integration { @@ -31,7 +34,7 @@ public async Task GetProjectTaskList_Returns_200() var taskListResponse = await _client.GetAsync($"/api/v1/client/projects/{project.ProjectStatusProjectId}/tasks/summary"); taskListResponse.StatusCode.Should().Be(HttpStatusCode.OK); - + var content = await taskListResponse.Content.ReadFromJsonAsync>(); var result = content.Data; @@ -98,6 +101,60 @@ public async Task GetProjectTaskList_ApplicationsEvidence_HiddenWithSchoolType_R result.ApplicationsEvidence.Status.Should().Be(ProjectTaskStatus.NotStarted); result.ApplicationsEvidence.IsHidden.Should().BeTrue(); } + + [Fact] + public async Task GetProjectTaskList_HiddenApplicationsEvidence_ReturnsLowerTaskCount() + { + var project = await setUpProject(false); + + var taskListResponse = await _client.GetAsync($"/api/v1/client/projects/{project.ProjectStatusProjectId}/tasks/summary"); + taskListResponse.StatusCode.Should().Be(HttpStatusCode.OK); + + var content = await taskListResponse.Content.ReadFromJsonAsync>(); + + var result = content.Data; + + var taskCount = result.TaskCount; + + var projectWithAp = await setUpProject(true); + + var taskListResponseWithAp = await _client.GetAsync($"/api/v1/client/projects/{projectWithAp.ProjectStatusProjectId}/tasks/summary"); + taskListResponseWithAp.StatusCode.Should().Be(HttpStatusCode.OK); + + var contentWithAp = await taskListResponseWithAp.Content.ReadFromJsonAsync>(); + + var resultWithAp = contentWithAp.Data; + + resultWithAp.TaskCount.Should().Be(taskCount - 1); + } + + [InlineData("School", ProjectTaskStatus.Completed)] + [Theory] + public async Task GetProjectTaskList_CompletedTaskCountIsCorrect(string expectedTaskName, ProjectTaskStatus expectedProjectTaskStatus) + { + var project = await setUpProject(false); + + var updateTaskStatusRequest = new UpdateTaskStatusRequest + { + ProjectTaskStatus = expectedProjectTaskStatus, TaskName = expectedTaskName + }; + + var taskUpdateResponse = + await _client.PatchAsync($"/api/v1/{project.ProjectStatusProjectId}/task/status", updateTaskStatusRequest.ConvertToJson()); + taskUpdateResponse.StatusCode.Should().Be(HttpStatusCode.OK); + + var taskStatusResponse = + await _client.GetAsync($"/api/v1/{project.ProjectStatusProjectId}/task/status?taskName={expectedTaskName}"); + taskStatusResponse.StatusCode.Should().Be(HttpStatusCode.OK); + + var taskListResponse = await _client.GetAsync($"/api/v1/client/projects/{project.ProjectStatusProjectId}/tasks/summary"); + + var content = await taskListResponse.Content.ReadFromJsonAsync>(); + + var result = content.Data; + result.CompletedTasks.Should().Be(1); + } + [Fact] public async Task Get_ProjectTaskList_ProjectDoesNotExist_Returns_404() @@ -105,5 +162,23 @@ public async Task Get_ProjectTaskList_ProjectDoesNotExist_Returns_404() var taskListResponse = await _client.GetAsync($"/api/v1/client/projects/NotExist/tasks/summary"); taskListResponse.StatusCode.Should().Be(HttpStatusCode.NotFound); } + + public async Task setUpProject(bool schoolIsAp) + { + using var context = _testFixture.GetContext(); + + var project = DatabaseModelBuilder.BuildProject(); + + if (schoolIsAp) + { + project.SchoolDetailsSchoolTypeMainstreamApEtc = "FS - AP"; + } + + context.Kpi.Add(project); + + await context.SaveChangesAsync(); + + return project; + } } } diff --git a/Dfe.ManageFreeSchoolProjects/Dfe.ManageFreeSchoolProjects.API/UseCases/Tasks/GetAllTasksStatusService.cs b/Dfe.ManageFreeSchoolProjects/Dfe.ManageFreeSchoolProjects.API/UseCases/Tasks/GetAllTasksStatusService.cs index 6f0b9bd50..e3de8ef06 100644 --- a/Dfe.ManageFreeSchoolProjects/Dfe.ManageFreeSchoolProjects.API/UseCases/Tasks/GetAllTasksStatusService.cs +++ b/Dfe.ManageFreeSchoolProjects/Dfe.ManageFreeSchoolProjects.API/UseCases/Tasks/GetAllTasksStatusService.cs @@ -17,6 +17,9 @@ public class GetAllTasksStatusService : IGetTasksService { private readonly MfspContext _context; + private static int _hiddenCompletedTasks; + private static int _tasksCount; + public GetAllTasksStatusService(MfspContext context) { _context = context; @@ -49,6 +52,8 @@ public async Task Execute(string projectId) private static ProjectByTaskSummaryResponse BuildProjectByTaskSummaryResponse(Kpi dbKpi, IEnumerable projectTasks) { + _tasksCount = 0; + _hiddenCompletedTasks = 0; var result = new ProjectByTaskSummaryResponse { SchoolName = dbKpi.ProjectStatusCurrentFreeSchoolName, @@ -80,13 +85,21 @@ private static ProjectByTaskSummaryResponse BuildProjectByTaskSummaryResponse(Kp }; var applicationsEvidenceTask = SafeRetrieveTaskSummary(projectTasks, TaskName.ApplicationsEvidence.ToString()); + result.ApplicationsEvidence = BuildApplicationsEvidenceTask(applicationsEvidenceTask, dbKpi); - + + result.TaskCount = _tasksCount; + + RemoveHiddenCompletedTaskStatus(result.ApplicationsEvidence); + + result.CompletedTasks = projectTasks.Count(x => x.Status == ProjectTaskStatus.Completed) - _hiddenCompletedTasks; + return result; } private static TaskSummaryResponse SafeRetrieveTaskSummary(IEnumerable projectTasks, string taskName) { + _tasksCount++; return projectTasks.FirstOrDefault(x => x.Name == taskName, new TaskSummaryResponse { Name = taskName, Status = ProjectTaskStatus.NotStarted }); } @@ -97,10 +110,20 @@ private static TaskSummaryResponse BuildApplicationsEvidenceTask(TaskSummaryResp SchoolType = ProjectMapper.ToSchoolType(kpi.SchoolDetailsSchoolTypeMainstreamApEtc), TaskSummary = taskSummaryResponse }; - + var result = new ApplicationsEvidenceTaskSummaryBuilder().Build(parameters); - + + _tasksCount -= taskSummaryResponse.IsHidden ? 1 : 0; + return result; } + + private static void RemoveHiddenCompletedTaskStatus(TaskSummaryResponse taskSummaryResponse) + { + if (taskSummaryResponse.IsHidden && taskSummaryResponse.Status == ProjectTaskStatus.Completed) + { + _hiddenCompletedTasks++; + } + } } diff --git a/Dfe.ManageFreeSchoolProjects/Dfe.ManageFreeSchoolProjects/Pages/Project/Tasks/TaskList.cshtml b/Dfe.ManageFreeSchoolProjects/Dfe.ManageFreeSchoolProjects/Pages/Project/Tasks/TaskList.cshtml index 230a16a4e..136bc7eb2 100644 --- a/Dfe.ManageFreeSchoolProjects/Dfe.ManageFreeSchoolProjects/Pages/Project/Tasks/TaskList.cshtml +++ b/Dfe.ManageFreeSchoolProjects/Dfe.ManageFreeSchoolProjects/Pages/Project/Tasks/TaskList.cshtml @@ -97,7 +97,7 @@

Project progress

-

You have completed 0 of 22 sections.

+

You have completed @Model.ProjectTaskListSummary.CompletedTasks of @Model.ProjectTaskListSummary.TaskCount sections.