Skip to content

Commit

Permalink
Updated to uses consts and added extra tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-nimbleapproach committed Oct 7, 2024
1 parent 018026f commit ec3a641
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Dfe.ManageFreeSchoolProjects.API.Contracts.Project.Tasks;
using Dfe.ManageFreeSchoolProjects.API.Tests.Fixtures;
using Dfe.ManageFreeSchoolProjects.API.Tests.Helpers;
using Dfe.ManageFreeSchoolProjects.API.Constants;
using System.Threading.Tasks;
using System;
using System.Linq;
Expand Down Expand Up @@ -47,8 +48,45 @@ public async Task Patch_DatesTask_Returns_201()
projectResponse.SchoolName.Should().Be(project.ProjectStatusCurrentFreeSchoolName);

using var contextPostSave = _testFixture.GetContext();
var createdProject = contextPostSave.Kpi.First(p => p.ProjectStatusProjectId == projectId);
createdProject.RyooWd.Should().Be(request.Dates.RealisticYearOfOpening);
var updatedProject = contextPostSave.Kpi.First(p => p.ProjectStatusProjectId == projectId);
updatedProject.RyooWd.Should().Be(request.Dates.RealisticYearOfOpening);
}

[Fact]
public async Task Patch_DatesTask_NoRYOOSetsDefaultValue()
{
var project = DatabaseModelBuilder.BuildProject();
var projectId = project.ProjectStatusProjectId;

using var context = _testFixture.GetContext();
context.Kpi.Add(project);
await context.SaveChangesAsync();

var DateTenDaysInFuture = new DateTime().AddDays(10);
var DateNineDaysInFuture = new DateTime().AddDays(9);

var request = new UpdateProjectByTaskRequest()
{
Dates = new DatesTask()
{
DateOfEntryIntoPreopening = DateTenDaysInFuture,
ProvisionalOpeningDateAgreedWithTrust = DateNineDaysInFuture,
ProjectClosedDate = DateTenDaysInFuture,
RealisticYearOfOpening = "",
}
};

var projectResponse = await _client.UpdateProjectTask(projectId, request, TaskName.Dates.ToString());

projectResponse.Dates.DateOfEntryIntoPreopening.Should().Be(DateTenDaysInFuture);
projectResponse.Dates.ProvisionalOpeningDateAgreedWithTrust.Should().Be(DateNineDaysInFuture);
projectResponse.Dates.ProjectClosedDate.Should().Be(DateTenDaysInFuture);
projectResponse.Dates.RealisticYearOfOpening.Should().Be(request.Dates.RealisticYearOfOpening);
projectResponse.SchoolName.Should().Be(project.ProjectStatusCurrentFreeSchoolName);

using var contextPostSave = _testFixture.GetContext();
var updatedProject = contextPostSave.Kpi.First(p => p.ProjectStatusProjectId == projectId);
updatedProject.RyooWd.Should().Be(ProjectConstants.RYOODefaultValue);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Dfe.ManageFreeSchoolProjects.API.Contracts.Project.Tasks;
using Dfe.ManageFreeSchoolProjects.API.Tests.Fixtures;
using Dfe.ManageFreeSchoolProjects.API.Tests.Helpers;
using Dfe.ManageFreeSchoolProjects.API.Constants;
using System;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -45,8 +46,8 @@ public async Task Patch_NewKickOffMeeting_Returns_201()
projectResponse.KickOffMeeting.FundingArrangementDetailsAgreed.Should().Be(request.KickOffMeeting.FundingArrangementDetailsAgreed);

using var contextPostSave = _testFixture.GetContext();
var createdProject = contextPostSave.Kpi.First(p => p.ProjectStatusProjectId == projectId);
createdProject.RyooWd.Should().Be(request.KickOffMeeting.RealisticYearOfOpening);
var updatedProject = contextPostSave.Kpi.First(p => p.ProjectStatusProjectId == projectId);
updatedProject.RyooWd.Should().Be(request.KickOffMeeting.RealisticYearOfOpening);
}

[Fact]
Expand Down Expand Up @@ -84,8 +85,47 @@ public async Task Patch_ExistingKickOffMeeting_Returns_201()
projectResponse.KickOffMeeting.FundingArrangementDetailsAgreed.Should().Be(request.KickOffMeeting.FundingArrangementDetailsAgreed);

using var contextPostSave = _testFixture.GetContext();
var createdProject = contextPostSave.Kpi.First(p => p.ProjectStatusProjectId == projectId);
createdProject.RyooWd.Should().Be(request.KickOffMeeting.RealisticYearOfOpening);
var updatedProject = contextPostSave.Kpi.First(p => p.ProjectStatusProjectId == projectId);
updatedProject.RyooWd.Should().Be(request.KickOffMeeting.RealisticYearOfOpening);
}

[Fact]
public async Task Patch_ExistingKickOffMeeting_NoRYOOSetsDefaultValue()
{
var project = DatabaseModelBuilder.BuildProject();
var projectId = project.ProjectStatusProjectId;

using var context = _testFixture.GetContext();
context.Kpi.Add(project);

var kickOffMeetingTask = DatabaseModelBuilder.BuildKickOffMeetingTask(project.Rid);
context.Milestones.Add(kickOffMeetingTask);

await context.SaveChangesAsync();

var dateNineDaysInFuture = new DateTime().AddDays(9);

var request = new UpdateProjectByTaskRequest()
{
KickOffMeeting = new KickOffMeetingTask()
{
FundingArrangementAgreed = true,
RealisticYearOfOpening = "",
FundingArrangementDetailsAgreed = "text",
SavedDocumentsInWorkplacesFolder = true
}
};

var projectResponse = await _client.UpdateProjectTask(projectId, request, TaskName.KickOffMeeting.ToString());

projectResponse.KickOffMeeting.SavedDocumentsInWorkplacesFolder.Should().Be(request.KickOffMeeting.SavedDocumentsInWorkplacesFolder);
projectResponse.KickOffMeeting.RealisticYearOfOpening.Should().Be(request.KickOffMeeting.RealisticYearOfOpening);
projectResponse.KickOffMeeting.FundingArrangementAgreed.Should().Be(request.KickOffMeeting.FundingArrangementAgreed);
projectResponse.KickOffMeeting.FundingArrangementDetailsAgreed.Should().Be(request.KickOffMeeting.FundingArrangementDetailsAgreed);

using var contextPostSave = _testFixture.GetContext();
var updatedProject = contextPostSave.Kpi.First(p => p.ProjectStatusProjectId == projectId);
updatedProject.RyooWd.Should().Be(ProjectConstants.RYOODefaultValue);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Dfe.ManageFreeSchoolProjects.API.Constants
{
public static class ProjectConstants
{
public const string RYOODefaultValue = "Awaiting Year";
public const string MATUnitProjects = "Other";
public const string SponsorUnitProjects = "Free Schools (including Studio Schools)";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Dfe.ManageFreeSchoolProjects.API.UseCases.Tasks;
using Dfe.ManageFreeSchoolProjects.Data;
using Dfe.ManageFreeSchoolProjects.Data.Entities.Existing;
using Dfe.ManageFreeSchoolProjects.API.Constants;
using Microsoft.EntityFrameworkCore;

namespace Dfe.ManageFreeSchoolProjects.API.UseCases.Project
Expand Down Expand Up @@ -83,6 +84,7 @@ private Po MapToPo(ProjectDetails proj, string rid)

private static Kpi MapToKpi(ProjectDetails proj, string rid, Trust trust)
{

return new Kpi
{
Rid = rid,
Expand All @@ -96,8 +98,8 @@ private static Kpi MapToKpi(ProjectDetails proj, string rid, Trust trust)
UpperStatus = "",
FsType = "",
FsType1 = "",
MatUnitProjects = "Other",
SponsorUnitProjects = "Free Schools (including Studio Schools)",
MatUnitProjects = ProjectConstants.MATUnitProjects,
SponsorUnitProjects = ProjectConstants.SponsorUnitProjects,
SchoolDetailsGeographicalRegion = proj.Region,
SchoolDetailsLocalAuthority = proj.LocalAuthorityCode,
LocalAuthority = proj.LocalAuthority,
Expand All @@ -122,7 +124,7 @@ private static Kpi MapToKpi(ProjectDetails proj, string rid, Trust trust)
ProjectStatusProvisionalOpeningDateAgreedWithTrust = proj.ProvisionalOpeningDate,
KeyContactsFsgLeadContact = proj.ProjectAssignedToName,
KeyContactsFsgLeadContactEmail = proj.ProjectAssignedToEmail,
RyooWd = "Awaiting Year"
RyooWd = ProjectConstants.RYOODefaultValue

};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace Dfe.ManageFreeSchoolProjects.API.UseCases.Project.Tasks.Dates
using Microsoft.IdentityModel.Tokens;
using Dfe.ManageFreeSchoolProjects.API.Constants;

namespace Dfe.ManageFreeSchoolProjects.API.UseCases.Project.Tasks.Dates
{
public class UpdateDatesTaskService : IUpdateTaskService
{
Expand All @@ -7,6 +10,7 @@ public async Task Update(UpdateTaskServiceParameters parameters)
var dbKpi = parameters.Kpi;
var task = parameters.Request.Dates;


if (task == null)
{
return;
Expand All @@ -18,7 +22,7 @@ public async Task Update(UpdateTaskServiceParameters parameters)
dbKpi.ProjectStatusDateCancelled = task.ProjectCancelledDate;
dbKpi.ProjectStatusDateWithdrawn = task.ProjectWithdrawnDate;
dbKpi.ProjectStatusRealisticYearOfOpening = task.RealisticYearOfOpening;
dbKpi.RyooWd = task.RealisticYearOfOpening.Length > 0 ? task.RealisticYearOfOpening : "Awaiting Year";
dbKpi.RyooWd = task.RealisticYearOfOpening.IsNullOrEmpty() ? ProjectConstants.RYOODefaultValue : task.RealisticYearOfOpening;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Dfe.ManageFreeSchoolProjects.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;
using Dfe.ManageFreeSchoolProjects.API.Constants;

namespace Dfe.ManageFreeSchoolProjects.API.UseCases.Project.Tasks.KickOffMeeting
{
Expand Down Expand Up @@ -32,7 +34,7 @@ public async Task Update(UpdateTaskServiceParameters parameters)
}

dbKpi.ProjectStatusRealisticYearOfOpening = task.RealisticYearOfOpening;
dbKpi.RyooWd = task.RealisticYearOfOpening.Length > 0 ? task.RealisticYearOfOpening : "Awaiting Year";
dbKpi.RyooWd = task.RealisticYearOfOpening.IsNullOrEmpty() ? ProjectConstants.RYOODefaultValue : task.RealisticYearOfOpening;
db.FsgPreOpeningMilestonesFundingArrangementAgreedBetweenLaAndSponsor = task.FundingArrangementAgreed;
db.FsgPreOpeningMilestonesDetailsOfFundingArrangementAgreedBetweenLaAndSponsor =
task.FundingArrangementDetailsAgreed;
Expand Down

0 comments on commit ec3a641

Please sign in to comment.