Skip to content

Commit

Permalink
Merge pull request #102 from SkillsFundingAgency/CV-398-remove-toggle…
Browse files Browse the repository at this point in the history
…features

Cv 398 remove togglefeatures
  • Loading branch information
Najamuddin-Muhammad authored Feb 21, 2020
2 parents 6a888ae + 5cf5468 commit 5a0beae
Show file tree
Hide file tree
Showing 38 changed files with 134 additions and 503 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@
using SFA.DAS.CommitmentsV2.Api.Types.Requests;
using SFA.DAS.CommitmentsV2.Api.Types.Responses;
using SFA.DAS.CommitmentsV2.Shared.Interfaces;
using SFA.DAS.EmployerCommitmentsV2.Features;
using SFA.DAS.EmployerCommitmentsV2.Web.Controllers;
using SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Cohort;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Cohort;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.DraftApprenticeship;
using SFA.DAS.EmployerUrlHelper;

namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Controllers.CohortControllerTests
Expand Down Expand Up @@ -52,31 +49,13 @@ public async Task PostAddDraftApprenticeship_WithValidModel_WithEnhancedApproval
{
var fixtures = new CreateCohortWithDraftApprenticeshipControllerTestFixtures()
.ForPostRequest()
.WithCreatedCohort("ABC123", 123)
.WithEnhancedApproval();
.WithCreatedCohort("ABC123", 123);

var result = await fixtures.CheckPost();

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


[Test]
public async Task PostAddDraftApprenticeship_WithValidModel_WithoutEnhancedApproval_ShouldRedirectToCohortDetailsV1()
{
var redirectUrl = "V1CohortDetailsPage";

var fixtures = new CreateCohortWithDraftApprenticeshipControllerTestFixtures()
.ForPostRequest()
.WithCreatedCohort("ABC123", 123)
.WithReviewCohortLink(redirectUrl);

var result = await fixtures.CheckPost();

result.VerifyReturnsRedirect().WithUrl(redirectUrl);
}


[Test]
public async Task PostAddDraftApprenticeship_WithValidModel_ShouldSaveCohort()
{
Expand All @@ -103,8 +82,6 @@ public CreateCohortWithDraftApprenticeshipControllerTestFixtures()
ModelMapperMock.Setup(x => x.Map<ApprenticeViewModel>(It.IsAny<ApprenticeRequest>()))
.ReturnsAsync(new ApprenticeViewModel());
AuthorizationServiceMock = new Mock<IAuthorizationService>();
AuthorizationServiceMock.Setup(x => x.IsAuthorized(EmployerFeature.EnhancedApproval))
.Returns(false);
}

public Mock<ILinkGenerator> LinkGeneratorMock { get; }
Expand Down Expand Up @@ -164,15 +141,6 @@ public CreateCohortWithDraftApprenticeshipControllerTestFixtures WithTrainingPro
return this;
}

public CreateCohortWithDraftApprenticeshipControllerTestFixtures WithEnhancedApproval()
{
AuthorizationServiceMock
.Setup(x => x.IsAuthorized(EmployerFeature.EnhancedApproval))
.Returns(true);

return this;
}

public CohortController CreateController()
{
var controller = new CohortController(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ public void VerifyDeleteCohortWasCalledCorrectly()

public void VerifyRedirectsToBingoPage(IActionResult result)
{
var redirect = (RedirectResult)result;
Assert.AreEqual($"/accounts/{ConfirmDeleteViewModel.AccountHashedId}/apprentices/cohorts", redirect.Url);
var redirect = (RedirectToActionResult)result;
Assert.AreEqual($"Cohorts", redirect.ActionName);
Assert.AreEqual(ConfirmDeleteViewModel.AccountHashedId, redirect.RouteValues["AccountHashedId"]);
}
public void VerifyRedirectsToCohortDetailsPage(IActionResult result)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
using SFA.DAS.CommitmentsV2.Api.Client;
using SFA.DAS.CommitmentsV2.Api.Types.Validation;
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;

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

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

[Test]
public async Task WhenPostingAction_ThenShouldRedirectToCohortDetailsUrl()
{
await TestAsync(
f => f.Post(),
(f, r) => r.Should().NotBeNull()
.And.BeOfType<RedirectResult>().Which
.Url.Should().Be(f.CohortDetailsUrl));
}

[Test]
public async Task WhenPostingAction_WithEnhancedApproval_ThenShouldRedirectToCohortDetailsV2()
{
await TestAsync(
a => a.WithEnhancedApproval(),
f => f.Post(),
(f, r) => r.Should().NotBeNull()
.And.BeOfType<RedirectToActionResult>().Which.ActionName.Should().Be("Details"));
}

}

public class AddDraftApprenticeshipTestsFixture
Expand All @@ -93,7 +78,6 @@ public class AddDraftApprenticeshipTestsFixture
public Mock<ICommitmentsApiClient> CommitmentsApiClient { get; set; }
public Mock<ITrainingProgrammeApiClient> TrainingProgrammeApiClient { get; set; }
public Mock<IModelMapper> ModelMapper { get; set; }
public Mock<ILinkGenerator> LinkGenerator { get; set; }
public Mock<IAuthorizationService> AuthorizationService { get; set; }
public DraftApprenticeshipController Controller { get; set; }

Expand Down Expand Up @@ -133,32 +117,24 @@ public AddDraftApprenticeshipTestsFixture()
AddDraftApprenticeshipRequest = new CommitmentsV2.Api.Types.Requests.AddDraftApprenticeshipRequest();
StandardCourses = new List<ITrainingProgramme>();
Courses = new List<ITrainingProgramme>();
CohortDetailsUrl = $"accounts/{Request.AccountHashedId}/apprentices/{Request.CohortReference}/details";
CohortDetailsUrl = $"{Request.AccountHashedId}/unapproved/{Request.CohortReference}";
CommitmentsApiModelException = new CommitmentsApiModelException(new List<ErrorDetail> { new ErrorDetail("Foo", "Bar") });
CommitmentsService = new Mock<ICommitmentsService>();
CommitmentsApiClient = new Mock<ICommitmentsApiClient>();
TrainingProgrammeApiClient = new Mock<ITrainingProgrammeApiClient>();
ModelMapper = new Mock<IModelMapper>();
LinkGenerator = new Mock<ILinkGenerator>();
AuthorizationService = new Mock<IAuthorizationService>();
AuthorizationService.Setup(x => x.IsAuthorized(EmployerFeature.EnhancedApproval)).Returns(false);

Controller = new DraftApprenticeshipController(
CommitmentsService.Object,
LinkGenerator.Object,
ModelMapper.Object,
CommitmentsApiClient.Object,
AuthorizationService.Object
);
CommitmentsApiClient.Object);

CommitmentsService.Setup(c => c.GetCohortDetail(Cohort.CohortId)).ReturnsAsync(Cohort);
TrainingProgrammeApiClient.Setup(c => c.GetAllTrainingProgrammes()).ReturnsAsync(Courses);
TrainingProgrammeApiClient.Setup(c => c.GetStandardTrainingProgrammes()).ReturnsAsync(StandardCourses);
ModelMapper.Setup(m => m.Map<CommitmentsV2.Api.Types.Requests.AddDraftApprenticeshipRequest>(ViewModel)).Returns(Task.FromResult(AddDraftApprenticeshipRequest));

ModelMapper.Setup(m => m.Map<AddDraftApprenticeshipViewModel>(It.IsAny<AddDraftApprenticeshipRequest>())).ReturnsAsync(ViewModel);

LinkGenerator.Setup(g => g.CommitmentsLink(CohortDetailsUrl)).Returns(CohortDetailsUrl);
}

public Task<IActionResult> Get()
Expand All @@ -185,11 +161,5 @@ public AddDraftApprenticeshipTestsFixture SetCohortWithOtherParty()

return this;
}

public AddDraftApprenticeshipTestsFixture WithEnhancedApproval()
{
AuthorizationService.Setup(x => x.IsAuthorized(EmployerFeature.EnhancedApproval)).Returns(true);
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Moq;
using NUnit.Framework;
using SFA.DAS.Authorization.Services;
using SFA.DAS.CommitmentsV2.Api.Client;
using SFA.DAS.CommitmentsV2.Api.Types.Requests;
using SFA.DAS.CommitmentsV2.Api.Types.Responses;
using SFA.DAS.CommitmentsV2.Shared.Interfaces;
using SFA.DAS.EmployerCommitmentsV2.Features;
using SFA.DAS.EmployerCommitmentsV2.Web.Controllers;
using SFA.DAS.EmployerCommitmentsV2.Web.Exceptions;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.DraftApprenticeship;
Expand All @@ -28,7 +26,6 @@ public class DeleteDraftApprenticeshipTests
public async Task WhenGettingDelete_ThenRequestIsMapped()
{
var fixture = new DeleteDraftApprenticeshipTestsFixture()
.WithEnhancedApproval()
.WithDeleteDraftApprenticeshipRequest(DeleteDraftApprenticeshipOrigin.CohortDetails);

await fixture.DeleteDraftApprenticeshipGet();
Expand All @@ -40,7 +37,6 @@ public async Task WhenGettingDelete_ThenRequestIsMapped()
public async Task WhenGettingDelete_ThenViewIsReturned()
{
var fixture = new DeleteDraftApprenticeshipTestsFixture()
.WithEnhancedApproval()
.WithDeleteDraftApprenticeshipRequest(DeleteDraftApprenticeshipOrigin.CohortDetails);

var result = await fixture.DeleteDraftApprenticeshipGet();
Expand All @@ -52,7 +48,6 @@ public async Task WhenGettingDelete_ThenViewIsReturned()
public async Task WhenGettingDelete_OriginIsEditDraftApprenticeship_AndCohortEmployerUpdateDeniedExceptionIsThrown_ThenGeneratesRedirectUrl()
{
var fixture = new DeleteDraftApprenticeshipTestsFixture()
.WithEnhancedApproval()
.WithDeleteDraftApprenticeshipRequest(DeleteDraftApprenticeshipOrigin.EditDraftApprenticeship)
.WithMapperThrowingCohortEmployerUpdateDeniedException();

Expand All @@ -66,7 +61,6 @@ public async Task WhenGettingDelete_OriginIsEditDraftApprenticeship_AndCohortEmp
public async Task WhenGettingDelete_OriginIsCohortDetails_AndCohortEmployerUpdateDeniedExceptionIsThrown_ThenRedirectsOrigin()
{
var fixture = new DeleteDraftApprenticeshipTestsFixture()
.WithEnhancedApproval()
.WithDeleteDraftApprenticeshipRequest(DeleteDraftApprenticeshipOrigin.CohortDetails)
.WithMapperThrowingCohortEmployerUpdateDeniedException();

Expand All @@ -81,7 +75,6 @@ public async Task WhenGettingDelete_OriginIsCohortDetails_AndCohortEmployerUpdat
public async Task WhenGettingDelete_OriginIsCohortDetails_AndDraftApprenticeshipNotFoundExceptionIsThrown_ThenRedirectsOrigin()
{
var fixture = new DeleteDraftApprenticeshipTestsFixture()
.WithEnhancedApproval()
.WithDeleteDraftApprenticeshipRequest(DeleteDraftApprenticeshipOrigin.CohortDetails)
.WithMapperThrowingDraftApprenticeshipNotFoundException();

Expand All @@ -96,7 +89,6 @@ public async Task WhenGettingDelete_OriginIsCohortDetails_AndDraftApprenticeship
public async Task PostDeleteApprenticeshipViewModel_WithValidModel_WithConfirmDeleteTrue_ShouldDeleteDraftApprenticeshipAndRedirectToCohortDetailsV2Page()
{
var fixture = new DeleteDraftApprenticeshipTestsFixture()
.WithEnhancedApproval()
.WithDeleteDraftApprenticeshipViewModel(confirmDelete: true);

var result = await fixture.DeleteDraftApprenticeship();
Expand All @@ -111,22 +103,21 @@ public async Task PostDeleteApprenticeshipViewModel_WithValidModel_WithConfirmDe
public async Task PostDeleteApprenticeshipViewModel_WithValidModel_WithConfirmDeleteTrue_ShouldDeleteDraftApprenticeshipAndTheCohortAndRedirectToBingoPage()
{
var fixture = new DeleteDraftApprenticeshipTestsFixture()
.WithEnhancedApproval()
.WithNoCohortFoundAfterDeletion()
.WithDeleteDraftApprenticeshipViewModel(confirmDelete: true);

var result = await fixture.DeleteDraftApprenticeship();

fixture.Verify_CommitmentApiClient_DeleteApprenticeShip_IsCalled_OnlyOnce();
var redirect = result.VerifyReturnsRedirect();
Assert.AreEqual($"/accounts/{fixture.AccountHashedId}/apprentices/cohorts", redirect.Url);
var redirect = result.VerifyReturnsRedirectToActionResult();
Assert.AreEqual("Cohorts", redirect.ActionName);
Assert.AreEqual("Cohort", redirect.ControllerName);
}

[Test]
public async Task PostDeleteApprenticeshipViewModel_WithValidModel_WithConfirmDeleteFalse_ShouldNotDeleteDraftApprenticeshipAndRedirectToOrigin()
{
var fixture = new DeleteDraftApprenticeshipTestsFixture()
.WithEnhancedApproval()
.WithDeleteDraftApprenticeshipViewModel(confirmDelete: false);

var result = await fixture.DeleteDraftApprenticeship();
Expand All @@ -141,7 +132,6 @@ public async Task PostDeleteApprenticeshipViewModel_WithValidModel_WithConfirmDe
public class DeleteDraftApprenticeshipTestsFixture
{
public Mock<ICommitmentsApiClient> CommitmentApiClient { get; }
public Mock<ILinkGenerator> LinkGeneratorMock { get; }
public string AccountHashedId => "ACHID";
public long CohortId => 1;
public string CohortReference => "CHREF";
Expand All @@ -151,7 +141,6 @@ public class DeleteDraftApprenticeshipTestsFixture
public DeleteDraftApprenticeshipViewModel DeleteDraftApprenticeshipViewModel { get; set; }
public DeleteApprenticeshipRequest DeleteDraftApprenticeshipRequest { get; set; }
public Mock<IModelMapper> ModelMapperMock { get; }
public Mock<IAuthorizationService> AuthorizationServiceMock { get; }
public DraftApprenticeshipController Sut { get; }

public DeleteDraftApprenticeshipTestsFixture()
Expand All @@ -160,9 +149,6 @@ public DeleteDraftApprenticeshipTestsFixture()
CommitmentApiClient = new Mock<ICommitmentsApiClient>();
CommitmentApiClient.Setup(x => x.GetCohort(It.IsAny<long>(), It.IsAny<CancellationToken>())).ReturnsAsync(new GetCohortResponse());

LinkGeneratorMock = new Mock<ILinkGenerator>();
LinkGeneratorMock.Setup(x => x.CommitmentsLink(It.IsAny<string>())).Returns<string>(s => s);

var deleteDraftApprenticeshipViewModel = new DeleteDraftApprenticeshipViewModel
{
FirstName = "John",
Expand All @@ -176,22 +162,12 @@ public DeleteDraftApprenticeshipTestsFixture()
ModelMapperMock.Setup(x => x.Map<DeleteDraftApprenticeshipViewModel>(It.IsAny<DeleteApprenticeshipRequest>()))
.ReturnsAsync(deleteDraftApprenticeshipViewModel);

AuthorizationServiceMock = new Mock<IAuthorizationService>();

Sut = new DraftApprenticeshipController(Mock.Of<ICommitmentsService>(),
LinkGeneratorMock.Object,
ModelMapperMock.Object,
CommitmentApiClient.Object,
AuthorizationServiceMock.Object);
CommitmentApiClient.Object);
Sut.TempData = new Mock<ITempDataDictionary>().Object;
}

public DeleteDraftApprenticeshipTestsFixture WithEnhancedApproval()
{
AuthorizationServiceMock.Setup(x => x.IsAuthorized(EmployerFeature.EnhancedApproval)).Returns(true);
return this;
}

public DeleteDraftApprenticeshipTestsFixture WithDeleteDraftApprenticeshipRequest(DeleteDraftApprenticeshipOrigin origin)
{
DeleteDraftApprenticeshipRequest = new DeleteApprenticeshipRequest
Expand Down
Loading

0 comments on commit 5a0beae

Please sign in to comment.