Skip to content

Commit

Permalink
Merge pull request #309 from SkillsFundingAgency/CON-4554-Remove-Redu…
Browse files Browse the repository at this point in the history
…ndant-Features

CON 4554 remove redundant features
  • Loading branch information
cofaulco authored May 3, 2022
2 parents 610035a + 380f415 commit 5e06a02
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,21 @@ public async Task GetAddDraftApprenticeship_ValidModel_ShouldReturnViewModel()
}

[Test]
public async Task PostAddDraftApprenticeship_WithValidModel_WithEnhancedApproval_WithoutCourseSelected_ShouldRedirectToCohortDetailsV2()
public async Task PostAddDraftApprenticeship_WithValidModel_WithoutCourseSelected_ShouldRedirectToCohortDetailsV2()
{
var fixtures = new CreateCohortWithDraftApprenticeshipControllerTestFixtures()
.ForPostRequest()
.SetupEncodingService()
.WithCreatedCohort("ABC123", 123)
.WithDraftApprenticeship(123, withCourseSelected : false);
.WithDraftApprenticeship(123, withCourseSelected: false);

var result = await fixtures.CheckPost();

result.VerifyReturnsRedirectToActionResult().WithActionName("Details");
}

[Test]
public async Task PostAddDraftApprenticeship_WithValidModel_WithEnhancedApproval_WithCourseSelected_ShouldRedirectToSelectOptions()
public async Task PostAddDraftApprenticeship_WithValidModel_WithCourseSelected_ShouldRedirectToSelectOptions()
{
var fixtures = new CreateCohortWithDraftApprenticeshipControllerTestFixtures()
.ForPostRequest()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using FluentAssertions;
using Microsoft.AspNetCore.Mvc;
using Moq;
using NUnit.Framework;
using SFA.DAS.Authorization.Services;
using SFA.DAS.CommitmentsV2.Shared.Interfaces;
using SFA.DAS.CommitmentsV2.Shared.Models;
using SFA.DAS.CommitmentsV2.Api.Client;
using SFA.DAS.CommitmentsV2.Api.Types.Responses;
using SFA.DAS.CommitmentsV2.Api.Types.Validation;
using SFA.DAS.CommitmentsV2.Shared.Interfaces;
using SFA.DAS.CommitmentsV2.Shared.Models;
using SFA.DAS.CommitmentsV2.Types;
using SFA.DAS.EmployerCommitmentsV2.Features;
using SFA.DAS.EmployerCommitmentsV2.Web.Controllers;
using SFA.DAS.EmployerCommitmentsV2.Web.Exceptions;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.DraftApprenticeship;
using SFA.DAS.EmployerUrlHelper;
using SFA.DAS.Testing;
using SFA.DAS.Encoding;
using SFA.DAS.Testing;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Controllers.DraftApprenticeshipControllerTests
{
Expand All @@ -45,7 +44,7 @@ await TestAsync(
f => f.SetCohortWithOtherParty(),
f => f.Get(),
(f, r) => r.Should().NotBeNull()
.And.BeEquivalentTo(new {ActionName = "Details", ControllerName = "Cohort"}, op => op.ExcludingMissingMembers()));
.And.BeEquivalentTo(new { ActionName = "Details", ControllerName = "Cohort" }, op => op.ExcludingMissingMembers()));
}

[Test]
Expand All @@ -55,7 +54,7 @@ await TestAsync(
f => f.Post(),
f => f.CommitmentsApiClient.Verify(c => c.AddDraftApprenticeship(f.ViewModel.CohortId.Value, f.AddDraftApprenticeshipRequest, It.IsAny<CancellationToken>())));
}

[Test]
public async Task WhenPostingAction_ThenShouldRedirectToSelectOptionPage()
{
Expand Down Expand Up @@ -91,7 +90,7 @@ public AddDraftApprenticeshipTestsFixture()
ProviderName = "Foobar",
WithParty = Party.Employer
};

Request = new AddDraftApprenticeshipRequest
{
AccountHashedId = "AAA000",
Expand All @@ -103,7 +102,7 @@ public AddDraftApprenticeshipTestsFixture()
StartMonthYear = "092019",
CourseCode = "DDD333"
};

ViewModel = new AddDraftApprenticeshipViewModel
{
AccountHashedId = Request.AccountHashedId,
Expand All @@ -125,24 +124,20 @@ public AddDraftApprenticeshipTestsFixture()
CommitmentsApiClient = new Mock<ICommitmentsApiClient>();
ModelMapper = new Mock<IModelMapper>();
LinkGenerator = new Mock<ILinkGenerator>();
AuthorizationService = new Mock<IAuthorizationService>();
EncodingService = new Mock<IEncodingService>();

AuthorizationService.Setup(x => x.IsAuthorized(EmployerFeature.EnhancedApproval)).Returns(false);

EncodingService.Setup(x => x.Encode(It.IsAny<long>(), EncodingType.ApprenticeshipId))
.Returns("APP123");

Controller = new DraftApprenticeshipController(
ModelMapper.Object,
CommitmentsApiClient.Object,
AuthorizationService.Object,
Mock.Of<IEncodingService>());

CommitmentsApiClient.Setup(c => c.GetAllTrainingProgrammes(CancellationToken.None)).ReturnsAsync(new GetAllTrainingProgrammesResponse{TrainingProgrammes = Courses});
CommitmentsApiClient.Setup(c => c.GetAllTrainingProgrammeStandards(CancellationToken.None)).ReturnsAsync(new GetAllTrainingProgrammeStandardsResponse{TrainingProgrammes = StandardCourses});
CommitmentsApiClient.Setup(c => c.GetAllTrainingProgrammes(CancellationToken.None)).ReturnsAsync(new GetAllTrainingProgrammesResponse { TrainingProgrammes = Courses });
CommitmentsApiClient.Setup(c => c.GetAllTrainingProgrammeStandards(CancellationToken.None)).ReturnsAsync(new GetAllTrainingProgrammeStandardsResponse { TrainingProgrammes = StandardCourses });
CommitmentsApiClient.Setup(c => c.AddDraftApprenticeship(ViewModel.CohortId.Value, AddDraftApprenticeshipRequest, It.IsAny<CancellationToken>()))
.ReturnsAsync(new AddDraftApprenticeshipResponse { DraftApprenticeshipId = 123456});
.ReturnsAsync(new AddDraftApprenticeshipResponse { DraftApprenticeshipId = 123456 });

ModelMapper.Setup(m => m.Map<CommitmentsV2.Api.Types.Requests.AddDraftApprenticeshipRequest>(ViewModel)).Returns(Task.FromResult(AddDraftApprenticeshipRequest));

Expand All @@ -162,15 +157,15 @@ public Task<IActionResult> Post()
public AddDraftApprenticeshipTestsFixture SetInvalidModelState()
{
Controller.ModelState.AddModelError("Foo", "Bar");

return this;
}

public AddDraftApprenticeshipTestsFixture SetCohortWithOtherParty()
{
ModelMapper.Setup(x => x.Map<AddDraftApprenticeshipViewModel>(It.IsAny<AddDraftApprenticeshipRequest>()))
.Throws(new CohortEmployerUpdateDeniedException("Cohort With Other Party"));

return this;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ public DeleteDraftApprenticeshipTestsFixture()
Sut = new DraftApprenticeshipController(
ModelMapperMock.Object,
CommitmentApiClient.Object,
AuthorizationServiceMock.Object,
Mock.Of<IEncodingService>());


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public async Task PostDetails_WithValidModel_ShouldSaveDraftApprenticeshipAndRed
}

[Test]
public async Task PostDetails_WithValidModel__WithEnhancedApproval_ShouldSaveDraftApprenticeshipAndRedirectToSelectOptionPage()
public async Task PostDetails_WithValidModel_ShouldSaveDraftApprenticeshipAndRedirectToSelectOptionPage()
{
var fixtures = new DetailsTestFixture()
.WithCohort();
Expand Down Expand Up @@ -114,12 +114,10 @@ public DetailsTestFixture()
.ReturnsAsync(ViewModel.Object);

AuthorizationServiceMock = new Mock<IAuthorizationService>();
AuthorizationServiceMock.Setup(x => x.IsAuthorized(EmployerFeature.EnhancedApproval)).Returns(false);

Sut = new DraftApprenticeshipController(
ModelMapperMock.Object,
CommitmentsApiClientMock.Object,
AuthorizationServiceMock.Object,
Mock.Of<IEncodingService>());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void Arrange()
_mockModelMapper = new Mock<IModelMapper>();
_mockCommitmentsApiClient = new Mock<ICommitmentsApiClient>();

_controller = new DraftApprenticeshipController(_mockModelMapper.Object, _mockCommitmentsApiClient.Object, Mock.Of<IAuthorizationService>(), Mock.Of<IEncodingService>());
_controller = new DraftApprenticeshipController(_mockModelMapper.Object, _mockCommitmentsApiClient.Object, Mock.Of<IEncodingService>());

_mockModelMapper.Setup(m => m.Map<UpdateDraftApprenticeshipRequest>(_viewModel))
.ReturnsAsync(_updateRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ public async Task<IActionResult> EditEndDate(EditEndDateViewModel viewModel)
}

[Route("{apprenticeshipHashedId}/details/changestatus")]
[DasAuthorize(CommitmentOperation.AccessApprenticeship, EmployerFeature.ManageApprenticesV2)]
[HttpGet]
public async Task<IActionResult> ChangeStatus(ChangeStatusRequest request)
{
Expand All @@ -116,7 +115,6 @@ public async Task<IActionResult> ChangeStatus(ChangeStatusRequest request)
}

[Route("{apprenticeshipHashedId}/details/changestatus")]
[DasAuthorize(EmployerFeature.ManageApprenticesV2)]
[HttpPost]
public IActionResult ChangeStatus(ChangeStatusRequestViewModel viewModel)
{
Expand Down Expand Up @@ -509,7 +507,6 @@ public IActionResult ApprenticeshipStoppedInform()
}

[Route("{apprenticeshipHashedId}/details/pause")]
[DasAuthorize(CommitmentOperation.AccessApprenticeship, EmployerFeature.ManageApprenticesV2)]
[HttpGet]
public async Task<IActionResult> PauseApprenticeship(PauseRequest request)
{
Expand All @@ -518,7 +515,6 @@ public async Task<IActionResult> PauseApprenticeship(PauseRequest request)
}

[Route("{apprenticeshipHashedId}/details/pause")]
[DasAuthorize(EmployerFeature.ManageApprenticesV2)]
[HttpPost]
public async Task<IActionResult> PauseApprenticeship(PauseRequestViewModel viewModel)
{
Expand All @@ -534,7 +530,6 @@ public async Task<IActionResult> PauseApprenticeship(PauseRequestViewModel viewM
return RedirectToAction(nameof(ApprenticeshipDetails), new ApprenticeshipDetailsRequest { AccountHashedId = viewModel.AccountHashedId, ApprenticeshipHashedId = viewModel.ApprenticeshipHashedId });
}

[DasAuthorize(CommitmentOperation.AccessApprenticeship, EmployerFeature.ManageApprenticesV2)]
[Route("{apprenticeshipHashedId}/details/resume")]
[HttpGet]
public async Task<IActionResult> ResumeApprenticeship(ResumeRequest request)
Expand All @@ -543,7 +538,6 @@ public async Task<IActionResult> ResumeApprenticeship(ResumeRequest request)
return View(viewModel);
}

[DasAuthorize(EmployerFeature.ManageApprenticesV2)]
[Route("{apprenticeshipHashedId}/details/resume")]
[HttpPost]
public async Task<IActionResult> ResumeApprenticeship(ResumeRequestViewModel viewModel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,17 @@ public class DraftApprenticeshipController : Controller
{
private readonly IModelMapper _modelMapper;
private readonly ICommitmentsApiClient _commitmentsApiClient;
private readonly IAuthorizationService _authorizationService;
private readonly IEncodingService _encodingService;

public const string ApprenticeDeletedMessage = "Apprentice record deleted";

public DraftApprenticeshipController(
IModelMapper modelMapper,
ICommitmentsApiClient commitmentsApiClient,
IAuthorizationService authorizationService,
IEncodingService encodingService)
{
_modelMapper = modelMapper;
_commitmentsApiClient = commitmentsApiClient;
_authorizationService = authorizationService;
_encodingService = encodingService;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ public static class EmployerFeature
{
private const string Prefix = "EmployerFeature.";

public const string EnhancedApproval = Prefix + "EnhancedApproval";
public const string ManageApprenticesV2 = Prefix + "ManageApprenticesV2";
public const string DeliveryModel = Prefix + "DeliveryModel";
}
Expand Down

0 comments on commit 5e06a02

Please sign in to comment.