Skip to content

Commit

Permalink
Merge pull request #1000 from DFE-Digital/feature/157115-no-trust-spo…
Browse files Browse the repository at this point in the history
…nsored

Feature/157115 no trust sponsored
  • Loading branch information
paullocknimble authored Mar 5, 2024
2 parents a17f60f + dcbf9b0 commit 23092d9
Show file tree
Hide file tree
Showing 15 changed files with 223 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public async Task GivenAValidProject_PostToApi([Frozen] Mock<IHttpClientService>
It.IsAny<HttpClient>(), @"legacy/project/new-conversion-project", It.IsAny<CreateNewProject>()))
.ReturnsAsync(new ApiResponse<string>(HttpStatusCode.OK, string.Empty));

CreateNewProject project = new(null, null, null);
CreateNewProject project = new(null, null, null, null);
await subject.CreateProject(project);

httpService.Verify(m => m.Post<CreateNewProject, string>(
Expand All @@ -114,7 +114,7 @@ public async Task GivenAFailedResponse_ThrowAnException([Frozen] Mock<IHttpClien
It.IsAny<HttpClient>(), @"legacy/project/new-conversion-project", It.IsAny<CreateNewProject>()))
.ReturnsAsync(new ApiResponse<string>(HttpStatusCode.InternalServerError, string.Empty));

CreateNewProject project = new(null, null, null);
CreateNewProject project = new(null, null, null, null);
ApiResponseException exception = await Assert.ThrowsAsync<ApiResponseException>(() => subject.CreateProject(project));

Assert.Equal("Request to Api failed | StatusCode - InternalServerError", exception.Message);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Dfe.PrepareConversions.Data.Models.NewProject;

public record CreateNewProject(NewProjectSchool School, NewProjectTrust Trust, string HasSchoolApplied);
public record CreateNewProject(NewProjectSchool School, NewProjectTrust Trust, string HasSchoolApplied, string HasPreferredTrust);

public record NewProjectTrust(string Name, string ReferenceNumber);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ public void Should_Map_Establishment_With_PfiScheme_And_Trust_Into_Dto_CreateSpo
};

string HasSchoolApplied = "no";
string HasPreferredTrust = "yes";

// Act
var result = CreateProjectMapper.MapToDto(establishment, trust, HasSchoolApplied);
var result = CreateProjectMapper.MapToDto(establishment, trust, HasSchoolApplied, HasPreferredTrust);

// Assert
result.School.PartOfPfiScheme.Should().BeTrue();
Expand Down Expand Up @@ -77,8 +78,9 @@ public void Should_Map_Establishment_Without_PfiScheme_And_Trust_Into_Dto_Create
CompaniesHouseNumber = fixture.Create<string>()
};
string HasSchoolApplied = "no";
string HasPreferredTrust = "no";
// Act
var result = CreateProjectMapper.MapToDto(establishment, trust, HasSchoolApplied);
var result = CreateProjectMapper.MapToDto(establishment, trust, HasSchoolApplied, HasPreferredTrust);

// Assert
using (var scope = new AssertionScope())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public async Task OnGetSearch_SearchTrust_Prepopulated([Frozen] Mock<ITrustsRepo
new TrustDtoResponse { Data = new List<TrustDto> { trust } });

// Act
await sut.OnGet(trust.Ukprn, string.Empty, string.Empty);
await sut.OnGet(trust.Ukprn, string.Empty, string.Empty, string.Empty);

// Assert
Assert.Equal($"{trust.Name} ({trust.Ukprn})", sut.SearchQuery);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public async Task Should_render_summary_page_with_school_and_trust(Establishment
_factory.AddGetWithJsonResponse($"/v4/establishment/urn/{establishment.Urn}", establishment);
_factory.AddGetWithJsonResponse("/v4/trusts*", TrustDtoResponse);

await OpenAndConfirmPathAsync($"/start-new-project/check-school-trust-details?ukprn={ukprn}&urn={establishment.Urn}");
await OpenAndConfirmPathAsync($"/start-new-project/check-school-trust-details?ukprn={ukprn}&urn={establishment.Urn}&hasSchoolApplied=true&hasPreferredTrust=yes");

Document.QuerySelector<IHtmlElement>("[data-cy=school-name]")!.Text().Trim().Should()
.Be(establishment.Name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Dfe.PrepareConversions.Mappings;

public static class CreateProjectMapper
{
public static CreateNewProject MapToDto(EstablishmentDto establishment, TrustDto trust, string HasSchoolApplied)
public static CreateNewProject MapToDto(EstablishmentDto establishment, TrustDto trust, string HasSchoolApplied, string HasPreferredTrust)
{
if (establishment == null)
{
Expand All @@ -25,10 +25,14 @@ public static CreateNewProject MapToDto(EstablishmentDto establishment, TrustDto
establishment.LocalAuthorityName,
establishment.Gor.Name);

NewProjectTrust createTrust = new(
trust.Name,
trust.ReferenceNumber);
NewProjectTrust createTrust = null;
if (trust != null)
{
createTrust = new(
trust.Name,
trust.ReferenceNumber);
}

return new CreateNewProject(createSchool, createTrust, HasSchoolApplied);
return new CreateNewProject(createSchool, createTrust, HasSchoolApplied, HasPreferredTrust);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ public static class NewProject
public static readonly LinkItem NewConversionInformation = AddLinkItem(page: "/NewProject/NewConversionInformation");
public static readonly LinkItem SchoolApply = AddLinkItem(page: "/NewProject/SchoolApply");
public static readonly LinkItem SearchTrusts = AddLinkItem(page: "/NewProject/SearchTrust");
public static readonly LinkItem PreferredTrust = AddLinkItem(page: "/NewProject/PreferredTrust");
public static readonly LinkItem Summary = AddLinkItem(page: "/NewProject/Summary");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
<p class="govuk-body">
All online applications are automatically added to the project list.
</p>
<p class="govuk-body">You cannot add conversions that are part of a project to form a multi-academy trust yet.</p>
</div>
<button class="govuk-button" type="submit" data-id="submit">Create a new conversion</button>
</form>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
@page "/start-new-project/preferred-trust"
@using Dfe.PrepareConversions.Pages.Shared
@model Dfe.PrepareConversions.Pages.SponsoredProject.PreferredTrustModel

@{
Layout = "_Layout";
ViewBag.Title = (!ViewData.ModelState.IsValid ? "Error: " : "") + "Preferred trust";
var routeParams = new Dictionary<string, string>
{
{ "urn", Request.Query["urn"] },
{ "ukprn", Request.Query["ukprn"] },
{ "hasSchoolApplied", Request.Query["hasSchoolApplied"] }
};
}

@section BeforeMain
{
<partial name="_BackLink" model="@(new BackLink(Links.NewProject.SchoolApply.Page, routeParams))" />
<partial name="_ErrorSummary" />
}



<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<form method="post">

<input hidden="" type="text" name="returnToSummary" value="no">
<input type="hidden" asp-for="Urn" />
<input type="hidden" asp-for="HasSchoolApplied" />
<h1 class="govuk-heading-l" data-cy="select-heading">Is there a preferred trust for this school?</h1>

<div class="govuk-form-group" @ModelState.GetErrorStyleClass()>
<div class="govuk-radios">
<div class="govuk-radios__item">
<input asp-for="HasPreferredTrust" class="govuk-radios__input" type="radio" value="Yes" id="DoneYes" data-cy="select-legal-input-yes">
<label class="govuk-label govuk-radios__label" for="DoneYes">
Yes
</label>
</div>

<div class="govuk-radios__item">
<input asp-for="HasPreferredTrust" class="govuk-radios__input" type="radio" value="No" id="DoneNo" data-cy="select-legal-input-no">
<label class="govuk-label govuk-radios__label" for="DoneNo">
No
</label>
</div>
</div>
</div>

<button class="govuk-button pt-3" data-module="govuk-button" data-cy="select-common-submitbutton">
Continue
</button>
</form>

</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using Dfe.PrepareConversions.Data.Services;
using Dfe.PrepareConversions.Models;
using Dfe.PrepareConversions.Models.ProjectList;
using Dfe.PrepareConversions.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.IdentityModel.Tokens;
using System.Threading.Tasks;
using EstablishmentDto = Dfe.Academies.Contracts.V4.Establishments.EstablishmentDto;

namespace Dfe.PrepareConversions.Pages.SponsoredProject;

public class PreferredTrustModel : PageModel
{
private readonly ErrorService _errorService;
private readonly IGetEstablishment _getEstablishment;

public PreferredTrustModel(IGetEstablishment getEstablishment, ErrorService errorService)
{
_getEstablishment = getEstablishment;
_errorService = errorService;
}
[BindProperty]
public string HasPreferredTrust { get; set; }

[BindProperty]
public string HasSchoolApplied { get; set; }

public string Urn { get; set; }

public async Task<IActionResult> OnGet(string urn, string hasSchoolApplied, string isPreferredTrust)
{
ProjectListFilters.ClearFiltersFrom(TempData);
HasSchoolApplied = hasSchoolApplied;
HasPreferredTrust = isPreferredTrust ?? "yes"; // Default to Yes if not used backlink to access

EstablishmentDto establishment = await _getEstablishment.GetEstablishmentByUrn(urn);
Urn = establishment.Urn;

return Page();
}

public async Task<IActionResult> OnPost(string urn, string redirect)
{

if (HasPreferredTrust.IsNullOrEmpty())
{
_errorService.AddError("IsPreferredTrust", "Select yes if there is a preferred trust");
return Page();
}

var nextPage = HasPreferredTrust.ToLower().Equals("yes") ? Links.NewProject.SearchTrusts.Page : Links.NewProject.Summary.Page;

redirect = string.IsNullOrEmpty(redirect) ? nextPage : redirect;

return RedirectToPage(redirect, new { urn, HasSchoolApplied, HasPreferredTrust });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public async Task<IActionResult> OnPost(string ukprn, string urn, string redirec
_errorService.AddError("HasSchoolApplied", "Select yes if the school has applied for academy conversion");
return Page();
}
redirect = string.IsNullOrEmpty(redirect) ? Links.NewProject.SearchTrusts.Page : redirect;
var nextPage = HasSchoolApplied.ToLower().Equals("yes") ? Links.NewProject.SearchTrusts.Page : Links.NewProject.PreferredTrust.Page;

redirect = string.IsNullOrEmpty(redirect) ? nextPage : redirect;

return RedirectToPage(redirect, new { ukprn, urn, HasSchoolApplied });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,24 @@
{
{ "urn", Request.Query["urn"] },
{ "ukprn", Request.Query["ukprn"] },
{ "hasSchoolApplied", Request.Query["hasSchoolApplied"] }
{ "hasSchoolApplied", Request.Query["hasSchoolApplied"] },
{ "hasPreferredTrust", Request.Query["hasPreferredTrust"] }
};

var backLink = Model.HasSchoolApplied.ToLower().Equals("yes") ? Links.NewProject.SchoolApply.Page : Links.NewProject.PreferredTrust.Page ;
}

@section BeforeMain
{
<partial name="_BackLink" model="@(new BackLink(Links.NewProject.SchoolApply.Page, routeParams))" />
{
<partial name="_BackLink" model="@(new BackLink(backLink, routeParams))" />
<partial name="_ErrorSummary" />
}

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<form method="post" data-id="form">
<input type="hidden" asp-for="HasSchoolApplied" />
<input type="hidden" asp-for="HasPreferredTrust" />
<div class="govuk-form-group @ModelState.GetErrorStyleClass()">
<h1 class="govuk-label-wrapper">
<label class="govuk-label govuk-label--xl" for="SearchQuery">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,19 @@ public SearchTrustModel(ITrustsRepository trustsRepository, ErrorService errorSe
public string SearchQuery { get; set; } = "";
[BindProperty]
public string HasSchoolApplied { get; set; }
[BindProperty]
public string HasPreferredTrust { get; set; }

public string Urn { get; set; }
public string Ukprn { get; set; }
public AutoCompleteSearchModel AutoCompleteSearchModel { get; set; }

public async Task<IActionResult> OnGet(string ukprn, string urn, string hasSchoolApplied)
public async Task<IActionResult> OnGet(string ukprn, string urn, string hasSchoolApplied, string hasPreferredTrust)
{
Urn = urn;
Ukprn = ukprn;
HasSchoolApplied = string.IsNullOrEmpty(hasSchoolApplied) ? "yes" : hasSchoolApplied;
HasPreferredTrust = string.IsNullOrEmpty(hasPreferredTrust) ? "yes" : hasPreferredTrust;

if (string.IsNullOrWhiteSpace(ukprn)) return Page();

Expand Down Expand Up @@ -102,7 +105,7 @@ public async Task<IActionResult> OnPost(string urn)
return Page();
}

return RedirectToPage(Links.NewProject.Summary.Page, new { ukprn, urn, HasSchoolApplied });
return RedirectToPage(Links.NewProject.Summary.Page, new { ukprn, urn, HasSchoolApplied, HasPreferredTrust });
}

private static string HighlightSearchMatch(string input, string toReplace, TrustDto trust)
Expand Down
Loading

0 comments on commit 23092d9

Please sign in to comment.