-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #180 from DFE-Digital/feature/mark-tasks-as-complete
Feature/mark Tasks as Complete
- Loading branch information
Showing
33 changed files
with
12,420 additions
and
57 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
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
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
8 changes: 8 additions & 0 deletions
8
...eFreeSchoolProjects/Dfe.ManageFreeSchoolProjects.API.Contracts/Task/TaskStatusResponse.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,8 @@ | ||
using Dfe.ManageFreeSchoolProjects.API.Contracts.Project.Tasks; | ||
|
||
namespace Dfe.ManageFreeSchoolProjects.API.Contracts.Task; | ||
|
||
public class TaskStatusResponse | ||
{ | ||
public ProjectTaskStatus ProjectTaskStatus { get; set; } | ||
} |
13 changes: 13 additions & 0 deletions
13
...SchoolProjects/Dfe.ManageFreeSchoolProjects.API.Contracts/Task/UpdateTaskStatusRequest.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,13 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using Dfe.ManageFreeSchoolProjects.API.Contracts.Project.Tasks; | ||
|
||
namespace Dfe.ManageFreeSchoolProjects.API.Contracts.Task; | ||
|
||
public class UpdateTaskStatusRequest | ||
{ | ||
[Required] | ||
public string TaskName { get; set; } | ||
|
||
[Required] | ||
public ProjectTaskStatus ProjectTaskStatus { get; set; } | ||
} |
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
140 changes: 140 additions & 0 deletions
140
...eFreeSchoolProjects/Dfe.ManageFreeSchoolProjects.API.Tests/Integration/TaskStatusTests.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,140 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Net.Http.Json; | ||
using System.Threading.Tasks; | ||
using Dfe.ManageFreeSchoolProjects.API.Contracts.Project.Tasks; | ||
using Dfe.ManageFreeSchoolProjects.API.Contracts.ResponseModels; | ||
using Dfe.ManageFreeSchoolProjects.API.Contracts.Task; | ||
using Dfe.ManageFreeSchoolProjects.API.Tests.Fixtures; | ||
using Dfe.ManageFreeSchoolProjects.API.Tests.Helpers; | ||
using Dfe.ManageFreeSchoolProjects.API.Tests.Utils; | ||
using Dfe.ManageFreeSchoolProjects.API.UseCases.Tasks; | ||
using Dfe.ManageFreeSchoolProjects.Data.Entities.Existing; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Dfe.ManageFreeSchoolProjects.API.Tests.Integration; | ||
|
||
[Collection(ApiTestCollection.ApiTestCollectionName)] | ||
public class TaskStatusTests : ApiTestsBase | ||
{ | ||
public TaskStatusTests(ApiTestFixture apiTestFixture) : base(apiTestFixture) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public async Task When_Get_Returns_TaskStatus_200_OK() | ||
{ | ||
using var context = _testFixture.GetContext(); | ||
|
||
var project = DatabaseModelBuilder.BuildProject(); | ||
context.Kpi.Add(project); | ||
|
||
var tasks = TasksStub.BuildListOfTasks(project.Rid); | ||
context.Tasks.AddRange(tasks); | ||
|
||
await context.SaveChangesAsync(); | ||
|
||
var taskStatusResponse = | ||
await _client.GetAsync($"/api/v1/{project.ProjectStatusProjectId}/task/status?taskName={TaskName.School}"); | ||
taskStatusResponse.StatusCode.Should().Be(HttpStatusCode.OK); | ||
|
||
var responseContent = | ||
await taskStatusResponse.Content.ReadFromJsonAsync<ApiSingleResponseV2<TaskStatusResponse>>(); | ||
|
||
responseContent.Data.ProjectTaskStatus.Should().Be(Status.NotStarted.Map()); | ||
} | ||
|
||
[Fact] | ||
public async Task When_Get_With_No_TaskName_Returns_400BadRequest() | ||
{ | ||
using var context = _testFixture.GetContext(); | ||
|
||
var project = DatabaseModelBuilder.BuildProject(); | ||
context.Kpi.Add(project); | ||
|
||
var tasks = TasksStub.BuildListOfTasks(project.Rid); | ||
context.Tasks.AddRange(tasks); | ||
|
||
await context.SaveChangesAsync(); | ||
|
||
var taskStatusResponse = | ||
await _client.GetAsync($"/api/v1/{project.ProjectStatusProjectId}/task/status"); | ||
taskStatusResponse.StatusCode.Should().Be(HttpStatusCode.BadRequest); | ||
} | ||
|
||
|
||
[InlineData("School", ProjectTaskStatus.InProgress)] | ||
[InlineData("Construction", ProjectTaskStatus.Completed)] | ||
[Theory] | ||
public async Task When_Patch_TaskStatus_Updated_Returns_200_OK(string expectedTaskName, ProjectTaskStatus expectedProjectTaskStatus) | ||
{ | ||
using var context = _testFixture.GetContext(); | ||
|
||
var project = DatabaseModelBuilder.BuildProject(); | ||
context.Kpi.Add(project); | ||
|
||
var tasks = TasksStub.BuildListOfTasks(project.Rid); | ||
context.Tasks.AddRange(tasks); | ||
|
||
await context.SaveChangesAsync(); | ||
|
||
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 responseContent = | ||
await taskStatusResponse.Content.ReadFromJsonAsync<ApiSingleResponseV2<TaskStatusResponse>>(); | ||
|
||
responseContent.Data.ProjectTaskStatus.Should().Be(expectedProjectTaskStatus); | ||
} | ||
|
||
[Fact] | ||
public async Task When_Patch_TaskStatus_With_No_TaskName_Returns_400BadRequest() | ||
{ | ||
using var context = _testFixture.GetContext(); | ||
|
||
var project = DatabaseModelBuilder.BuildProject(); | ||
context.Kpi.Add(project); | ||
|
||
var tasks = TasksStub.BuildListOfTasks(project.Rid); | ||
context.Tasks.AddRange(tasks); | ||
|
||
await context.SaveChangesAsync(); | ||
|
||
var updateTaskStatusRequest = new UpdateTaskStatusRequest | ||
{ | ||
}; | ||
|
||
var taskUpdateResponse = | ||
await _client.PatchAsync($"/api/v1/{project.ProjectStatusProjectId}/task/status", updateTaskStatusRequest.ConvertToJson()); | ||
taskUpdateResponse.StatusCode.Should().Be(HttpStatusCode.BadRequest); | ||
} | ||
|
||
[Fact] | ||
public async Task When_Post_Creates_Tasks_Returns_201Created() | ||
{ | ||
using var context = _testFixture.GetContext(); | ||
var project = DatabaseModelBuilder.BuildProject(); | ||
context.Kpi.Add(project); | ||
await context.SaveChangesAsync(); | ||
|
||
var createTasksRequest = await _client.PostAsync($"/api/v1/{project.ProjectStatusProjectId}/task/status", null); | ||
|
||
createTasksRequest.StatusCode.Should().Be(HttpStatusCode.Created); | ||
|
||
var tasks = await context.Tasks.Where(x => x.Rid == project.Rid).ToListAsync(); | ||
|
||
tasks.Should().NotBeNull(); | ||
tasks.Count.Should().BeGreaterThan(1); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
Dfe.ManageFreeSchoolProjects/Dfe.ManageFreeSchoolProjects.API.Tests/Utils/TasksStub.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,26 @@ | ||
using System.Collections.Generic; | ||
using Dfe.ManageFreeSchoolProjects.Data.Entities.Existing; | ||
|
||
namespace Dfe.ManageFreeSchoolProjects.API.Tests.Utils; | ||
|
||
public static class TasksStub | ||
{ | ||
public static List<Tasks> BuildListOfTasks(string projectRid) | ||
{ | ||
return new List<Tasks>() | ||
{ | ||
new() | ||
{ | ||
Rid = projectRid, | ||
Status = Status.NotStarted, | ||
TaskName = TaskName.School | ||
}, | ||
new() | ||
{ | ||
Rid = projectRid, | ||
Status = Status.InProgress, | ||
TaskName = TaskName.Construction | ||
} | ||
}; | ||
} | ||
} |
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.