Skip to content

Commit

Permalink
Merge pull request #142 from SkillsFundingAgency/CON-2502-CoP-inform-…
Browse files Browse the repository at this point in the history
…page

CON-2502 Change of provider inform page
  • Loading branch information
Najamuddin-Muhammad authored Oct 30, 2020
2 parents 2f8c7db + 944fe7b commit 6d50c64
Show file tree
Hide file tree
Showing 12 changed files with 261 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void DeleteApprentice_BuildsPathCorrectly(string accountHashedId, string
public void EmployerHome_BuildsPathCorrectly(string accountHashedId)
{
var url = _fixture.Sut.EmployerHome(accountHashedId);
Assert.AreEqual($"{_fixture.UsersLink}accounts/{accountHashedId}/teams", url);
Assert.AreEqual($"{_fixture.AccountsLink}accounts/{accountHashedId}/teams", url);
}

[Test, AutoData]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using AutoFixture;
using Moq;
using NUnit.Framework;
using SFA.DAS.CommitmentsV2.Api.Client;
using SFA.DAS.CommitmentsV2.Api.Types.Responses;
using SFA.DAS.CommitmentsV2.Types;
using SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Apprentice;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice;
using SFA.DAS.Encoding;
using SFA.DAS.Testing.AutoFixture;
using System.Threading;
using System.Threading.Tasks;

namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Mappers.Apprentice
{
public class ChangeProviderInformViewModelMapperTests
{
private Mock<ICommitmentsApiClient> _mockCommitmentsApiClient;
private Mock<IEncodingService> _mockEncodingService;
private GetApprenticeshipResponse _apprenticeshipResponse;

private ChangeProviderInformViewModelMapper _mapper;

private const long ApprenticeshipId = 10000000;

[SetUp]
public void Arrange()
{
var autoFixture = new Fixture();

_apprenticeshipResponse = autoFixture.Build<GetApprenticeshipResponse>()
.With(a => a.Status, ApprenticeshipStatus.Stopped)
.Create();


_mockCommitmentsApiClient = new Mock<ICommitmentsApiClient>();
_mockCommitmentsApiClient.Setup(a => a.GetApprenticeship(It.IsAny<long>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(_apprenticeshipResponse);

_mockEncodingService = new Mock<IEncodingService>();
_mockEncodingService.Setup(d => d.Decode(It.IsAny<string>(), EncodingType.ApprenticeshipId))
.Returns(ApprenticeshipId);


_mapper = new ChangeProviderInformViewModelMapper(_mockCommitmentsApiClient.Object, _mockEncodingService.Object);
}

[Test, MoqAutoData]
public async Task ApprenticeshipHashedId_IsMapped(ChangeProviderInformRequest request)
{
var result = await _mapper.Map(request);

Assert.AreEqual(request.ApprenticeshipHashedId, result.ApprenticeshipHashedId);
}

[Test, MoqAutoData]
public async Task AccountHashedId_IsMapped(ChangeProviderInformRequest request)
{
var result = await _mapper.Map(request);

Assert.AreEqual(request.AccountHashedId, result.AccountHashedId);
}

[Test, MoqAutoData]
public async Task ApprenticeshipStatus_IsMapped(ChangeProviderInformRequest request)
{
var result = await _mapper.Map(request);

Assert.AreEqual(ApprenticeshipStatus.Stopped, result.ApprenticeshipStatus);
}

[Test, MoqAutoData]
public async Task WhenRequestingChangeProviderInformPage_ThenHashedApprenticeshipIdIsDecoded(ChangeProviderInformRequest request)
{
var result = await _mapper.Map(request);

_mockEncodingService.Verify(a => a.Decode(request.ApprenticeshipHashedId, EncodingType.ApprenticeshipId), Times.Once);
}

[Test, MoqAutoData]
public async Task WhenRequestingChangeProviderInformPage_ThenGetApprenticeshipIsCalled(ChangeProviderInformRequest request)
{
var result = await _mapper.Map(request);

_mockCommitmentsApiClient.Verify(a => a.GetApprenticeship(ApprenticeshipId, It.IsAny<CancellationToken>()), Times.Once);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public ApprenticeController(IModelMapper modelMapper, ICookieStorageService<Inde
}

[Route("", Name = RouteNames.ApprenticesIndex)]
[DasAuthorize(EmployerFeature.ManageApprenticesV2)]
public async Task<IActionResult> Index(IndexRequest request)
{
IndexRequest savedRequest = null;
Expand All @@ -64,7 +63,6 @@ public async Task<IActionResult> Index(IndexRequest request)
}

[Route("download", Name = RouteNames.ApprenticesDownload)]
[DasAuthorize(EmployerFeature.ManageApprenticesV2)]
public async Task<IActionResult> Download(DownloadRequest request)
{
var downloadViewModel = await _modelMapper.Map<DownloadViewModel>(request);
Expand All @@ -73,15 +71,13 @@ public async Task<IActionResult> Download(DownloadRequest request)
}

[Route("{apprenticeshipHashedId}/details/editenddate", Name = RouteNames.ApprenticeEditEndDate)]
[DasAuthorize(EmployerFeature.ManageApprenticesV2)]
public async Task<IActionResult> EditEndDate(EditEndDateRequest request)
{
var viewModel = await _modelMapper.Map<EditEndDateViewModel>(request);
return View(viewModel);
}

[Route("{apprenticeshipHashedId}/details/editenddate", Name = RouteNames.ApprenticeEditEndDate)]
[DasAuthorize(EmployerFeature.ManageApprenticesV2)]
[HttpPost]
public async Task<IActionResult> EditEndDate(EditEndDateViewModel viewModel)
{
Expand All @@ -91,6 +87,31 @@ public async Task<IActionResult> EditEndDate(EditEndDateViewModel viewModel)
return Redirect(url);
}

[Route("{apprenticeshipHashedId}/details/changing-training-provider", Name = RouteNames.ChangeProviderInform)]
[DasAuthorize(EmployerFeature.ChangeOfProvider)]
public async Task<IActionResult> ChangeProviderInform(ChangeProviderInformRequest request)
{
var viewModel = await _modelMapper.Map<ChangeProviderInformViewModel>(request);

return View(viewModel);
}

// Placeholder for CON-2516 - url not specified yet
[Route("{apprenticeshipHashedId}/details/stopped-error", Name = RouteNames.ApprenticeNotStoppedError)]
[DasAuthorize(EmployerFeature.ChangeOfProvider)]
public IActionResult ApprenticeNotStoppedError()
{
return View();
}

// Placeholder for CON-2505
[Route("{apprenticeshipHashedId}/details/enter-new-training-provider-name-or-reference-number", Name = RouteNames.EnterNewTrainingProvider)]
[DasAuthorize(EmployerFeature.ChangeOfProvider)]
public IActionResult EnterNewTrainingProvider()
{
return View();
}

[Route("{apprenticeshipHashedId}/details/changestatus")]
[DasAuthorize(EmployerFeature.ManageApprenticesV2)]
[HttpGet]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace SFA.DAS.EmployerCommitmentsV2.Web.Extensions
{
public static class ILinkGeneratorExtensions
{
public static string YourOrganisationsAndAgreements(this ILinkGenerator linkGenerator, string accountHashedId)
public static string YourOrganisationsAndAgreements(this ILinkGenerator linkGenerator, string accountHashedId)
{
return linkGenerator.AccountsLink($"accounts/{accountHashedId}/agreements");
}
Expand Down Expand Up @@ -48,7 +48,7 @@ public static string DeleteApprentice(this ILinkGenerator linkGenerator,

public static string EmployerHome(this ILinkGenerator linkGenerator, string accountHashedId)
{
return linkGenerator.UsersLink($"accounts/{accountHashedId}/teams");
return linkGenerator.AccountsLink($"accounts/{accountHashedId}/teams");
}

public static string EmployerAccountsHome(this ILinkGenerator linkGenerator)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using SFA.DAS.CommitmentsV2.Api.Client;
using SFA.DAS.CommitmentsV2.Shared.Interfaces;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice;
using SFA.DAS.Encoding;
using System;
using System.Threading;
using System.Threading.Tasks;

namespace SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Apprentice
{
public class ChangeProviderInformViewModelMapper : IMapper<ChangeProviderInformRequest, ChangeProviderInformViewModel>
{
private readonly ICommitmentsApiClient _commitmentsApiClient;
private readonly IEncodingService _encodingService;

public ChangeProviderInformViewModelMapper(ICommitmentsApiClient commitmentsApiClient, IEncodingService encodingService)
{
_commitmentsApiClient = commitmentsApiClient;
_encodingService = encodingService;
}

public async Task<ChangeProviderInformViewModel> Map(ChangeProviderInformRequest source)
{
var apprenticeshipId = _encodingService.Decode(source.ApprenticeshipHashedId, EncodingType.ApprenticeshipId);

var apprenticeship = await _commitmentsApiClient.GetApprenticeship(apprenticeshipId, CancellationToken.None);

var result = new ChangeProviderInformViewModel
{
AccountHashedId = source.AccountHashedId,
ApprenticeshipHashedId = source.ApprenticeshipHashedId,
ApprenticeshipStatus = apprenticeship.Status
};

return result;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Microsoft.AspNetCore.Mvc;

namespace SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice
{
public class ChangeProviderInformRequest
{
[FromRoute]
public string AccountHashedId { get; set; }

[FromRoute]
public string ApprenticeshipHashedId { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

using SFA.DAS.CommitmentsV2.Types;

namespace SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice
{
public class ChangeProviderInformViewModel
{
public string AccountHashedId { get; set; }
public string ApprenticeshipHashedId { get; set; }
public ApprenticeshipStatus ApprenticeshipStatus { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@ public static class RouteNames
public const string ApprenticesDownload = "apprentices-download";
public const string ApprenticeDetail = "apprentice-details";
public const string ApprenticeEditEndDate = "apprentice-edit-enddate";

public const string ChangeProviderInform = "changing-training-provider-inform";
public const string ApprenticeNotStoppedError = "aprentice-not-stopped-error";
public const string EnterNewTrainingProvider = "enter-new-training-provider-name-or-reference-number";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

@*
Placeholder for CON-2516
*@

<h1> You need to wait until {apprentice} has stopped training </h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
@inject ILinkGenerator LinkGenerator;
@using SFA.DAS.EmployerCommitmentsV2.Web.Extensions
@using SFA.DAS.CommitmentsV2.Types
@using SFA.DAS.EmployerCommitmentsV2.Web.RouteValues
@model SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice.ChangeProviderInformViewModel;

@{
ViewData["Title"] = "Changing training provider - Apprenticeship service - GOV.UK";
}

<div class="das-panel das-panel--featured das-!-text-align-left">
<h1 class="das-panel__heading govuk-!-margin-top-0">
Changing training provider
</h1>
<div class="govuk-!-width-two-thirds das-panel__body">

@if (Model.ApprenticeshipStatus != ApprenticeshipStatus.Stopped)
{
<div class="govuk-warning-text">
<span class="govuk-warning-text__icon das-warning-text__icon--blue das-warning-text__icon--valign-middle" aria-hidden="true">!</span>
<strong class="govuk-warning-text__text das-!-colour-inherit">
<span class="govuk-warning-text__assistive">Warning</span>
When you change an apprentice's training provider, their apprenticeship record with the current training provider will be stopped.
</strong>
</div>
}

<p class="govuk-body das-!-colour-inherit">
Before you request this change, you must contact the new training provider to agree the new training dates and price.
</p>
<p class="govuk-body das-!-colour-inherit">
You should only change your apprentice's training provider if:
</p>
<ul class="govuk-list govuk-list--bullet das-!-colour-inherit">
<li>
you're not happy with their performance
</li>
<li>
they've stopped delivering the apprentice's training course
</li>
<li>
they're shutting down or have already shut down
</li>
</ul>
</div>

@if (Model.ApprenticeshipStatus != ApprenticeshipStatus.Stopped)
{
<a class="govuk-button das-button--inverted govuk-!-font-weight-bold govuk-!-margin-top-2" asp-route="@RouteNames.ApprenticeNotStoppedError"> Continue </a>
}
else
{
<a class="govuk-button das-button--inverted govuk-!-font-weight-bold govuk-!-margin-top-2" asp-route="@RouteNames.EnterNewTrainingProvider"> Continue </a>
}

<p class="govuk-body-s govuk-!-margin-top-0 govuk-!-margin-bottom-0">
<a class="das-panel__link" href="@LinkGenerator.EmployerHome(Model.AccountHashedId)">Cancel and return to account home</a>
</p>
</div>

@section Back
{
<div class="das-js-back-link"></div>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

@*
Placeholder for CON-2505
*@

<h1> Enter a new training provider </h1>
2 changes: 2 additions & 0 deletions src/SFA.DAS.EmployerCommitmentsV2/Features/EmployerFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ namespace SFA.DAS.EmployerCommitmentsV2.Features
public static class EmployerFeature
{
private const string Prefix = "EmployerFeature.";

public const string EnhancedApproval = Prefix + "EnhancedApproval";
public const string ManageApprenticesV2 = Prefix + "ManageApprenticesV2";
public const string ChangeOfProvider = Prefix + "ChangeOfProvider";
}
}

0 comments on commit 6d50c64

Please sign in to comment.