Skip to content

Commit

Permalink
Merge pull request #242 from SkillsFundingAgency/CON-3712_History_Tab…
Browse files Browse the repository at this point in the history
…le_Not_Updating

CON-3712 Update User Info In History_Table
  • Loading branch information
Najamuddin-Muhammad authored Aug 6, 2021
2 parents 3ffc418 + 1b7f3db commit c7ae9b6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using Microsoft.AspNetCore.Http;
using AutoFixture;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Moq;
using NUnit.Framework;
using SFA.DAS.CommitmentsV2.Api.Types.Requests;
using SFA.DAS.CommitmentsV2.Types;
using SFA.DAS.EmployerCommitmentsV2.Web.Authentication;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice.Edit;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -54,20 +57,31 @@ public class WhenPostingReviewApprenticeshipUpdatesTestsFixture : ApprenticeCont
private const string ChangesRejectedMessage = "Changes rejected";

public ReviewApprenticeshipUpdatesViewModel ViewModel { get; set; }

public UserInfo UserInfo;
public Mock<IAuthenticationService> AuthenticationService { get; }

public WhenPostingReviewApprenticeshipUpdatesTestsFixture() : base ()
{
ViewModel = new ReviewApprenticeshipUpdatesViewModel { ApprenticeshipId = 1, AccountId = 1 };
_controller.TempData = new TempDataDictionary( Mock.Of<HttpContext>(), Mock.Of<ITempDataProvider>());

var autoFixture = new Fixture();
UserInfo = autoFixture.Create<UserInfo>();
AuthenticationService = new Mock<IAuthenticationService>();
AuthenticationService.Setup(x => x.UserInfo).Returns(UserInfo);
}

public async Task<IActionResult> ReviewApprenticeshipUpdates()
{
return await _controller.ReviewApprenticeshipUpdates(ViewModel);
return await _controller.ReviewApprenticeshipUpdates(AuthenticationService.Object, ViewModel);
}

internal void VerifyAcceptApprenticeshipUpdatesApiIsCalled()
{
_mockCommitmentsApiClient.Verify(x => x.AcceptApprenticeshipUpdates(ViewModel.ApprenticeshipId, It.IsAny<AcceptApprenticeshipUpdatesRequest>(), It.IsAny<CancellationToken>()), Times.Once());
_mockCommitmentsApiClient
.Verify(x => x.AcceptApprenticeshipUpdates(ViewModel.ApprenticeshipId, It.Is<AcceptApprenticeshipUpdatesRequest>(o => o.UserInfo != null), It.IsAny<CancellationToken>()), Times.Once());

Assert.IsTrue(_controller.TempData.Values.Contains(ChangesApprovedMessage));
Assert.IsTrue(_controller.TempData.ContainsKey(FlashMessageBodyTempDataKey));
Assert.IsTrue(_controller.TempData.ContainsKey(FlashMessageLevelTempDataKey));
Expand All @@ -76,7 +90,7 @@ internal void VerifyAcceptApprenticeshipUpdatesApiIsCalled()

internal void VerifyRejectApprenticeshipUpdatesApiIsCalled()
{
_mockCommitmentsApiClient.Verify(x => x.RejectApprenticeshipUpdates(ViewModel.ApprenticeshipId, It.IsAny<RejectApprenticeshipUpdatesRequest>(), It.IsAny<CancellationToken>()), Times.Once());
_mockCommitmentsApiClient.Verify(x => x.RejectApprenticeshipUpdates(ViewModel.ApprenticeshipId, It.Is<RejectApprenticeshipUpdatesRequest>(o => o.UserInfo != null), It.IsAny<CancellationToken>()), Times.Once());
Assert.IsTrue(_controller.TempData.Values.Contains(ChangesRejectedMessage));
Assert.IsTrue(_controller.TempData.ContainsKey(FlashMessageBodyTempDataKey));
Assert.IsTrue(_controller.TempData.ContainsKey(FlashMessageLevelTempDataKey));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
using Moq;
using NUnit.Framework;
using SFA.DAS.CommitmentsV2.Api.Types.Requests;
using SFA.DAS.EmployerCommitmentsV2.Web.Authentication;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice.Edit;
using System.Threading;
using System.Threading.Tasks;
using AutoFixture;
using SFA.DAS.CommitmentsV2.Types;

namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Controllers.ApprenticeControllerTests
{
Expand Down Expand Up @@ -48,21 +51,29 @@ public async Task VerifyIsRedirectedToApprenticeshipDetails()

public class WhenPostingViewApprenticeshipUpdatesTestsFixture : ApprenticeControllerTestFixtureBase
{
public Mock<IAuthenticationService> AuthenticationService { get; }
public UserInfo UserInfo;

public ViewApprenticeshipUpdatesViewModel ViewModel { get; set; }
public WhenPostingViewApprenticeshipUpdatesTestsFixture() : base ()
{
ViewModel = new ViewApprenticeshipUpdatesViewModel { ApprenticeshipId = 1, AccountId = 1 };
_controller.TempData = new TempDataDictionary( Mock.Of<HttpContext>(), Mock.Of<ITempDataProvider>());

var autoFixture = new Fixture();
UserInfo = autoFixture.Create<UserInfo>();
AuthenticationService = new Mock<IAuthenticationService>();
AuthenticationService.Setup(x => x.UserInfo).Returns(UserInfo);
}

public async Task<IActionResult> ViewApprenticeshipUpdates()
{
return await _controller.ViewApprenticeshipUpdates(ViewModel);
return await _controller.ViewApprenticeshipUpdates(AuthenticationService.Object, ViewModel);
}

internal void Verify_UndoApprenticeshipUpdatesApi_Is_Called()
{
_mockCommitmentsApiClient.Verify(x => x.UndoApprenticeshipUpdates(ViewModel.ApprenticeshipId, It.IsAny<UndoApprenticeshipUpdatesRequest>(), It.IsAny<CancellationToken>()), Times.Once());
_mockCommitmentsApiClient.Verify(x => x.UndoApprenticeshipUpdates(ViewModel.ApprenticeshipId, It.Is<UndoApprenticeshipUpdatesRequest>(o => o.UserInfo != null), It.IsAny<CancellationToken>()), Times.Once());
}

internal void Verify_UndoApprenticeshipUpdatesApi_IsNot_Called()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice.Edit;
using SFA.DAS.EmployerCommitmentsV2.Web.RouteValues;
using SFA.DAS.EmployerUrlHelper;
using SFA.DAS.EmployerCommitmentsV2.Web.Authentication;
using EditEndDateRequest = SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice.EditEndDateRequest;

namespace SFA.DAS.EmployerCommitmentsV2.Web.Controllers
Expand Down Expand Up @@ -655,14 +656,15 @@ public async Task<IActionResult> ReviewApprenticeshipUpdates(ReviewApprenticeshi

[HttpPost]
[Route("{apprenticeshipHashedId}/changes/review")]
public async Task<IActionResult> ReviewApprenticeshipUpdates(ReviewApprenticeshipUpdatesViewModel viewModel)
public async Task<IActionResult> ReviewApprenticeshipUpdates([FromServices] IAuthenticationService authenticationService, ReviewApprenticeshipUpdatesViewModel viewModel)
{
if (viewModel.ApproveChanges.Value)
{
var request = new AcceptApprenticeshipUpdatesRequest
{
ApprenticeshipId = viewModel.ApprenticeshipId,
AccountId = viewModel.AccountId
AccountId = viewModel.AccountId,
UserInfo = authenticationService.UserInfo
};

await _commitmentsApiClient.AcceptApprenticeshipUpdates(viewModel.ApprenticeshipId, request);
Expand All @@ -673,7 +675,8 @@ public async Task<IActionResult> ReviewApprenticeshipUpdates(ReviewApprenticeshi
var request = new RejectApprenticeshipUpdatesRequest
{
ApprenticeshipId = viewModel.ApprenticeshipId,
AccountId = viewModel.AccountId
AccountId = viewModel.AccountId,
UserInfo = authenticationService.UserInfo
};

await _commitmentsApiClient.RejectApprenticeshipUpdates(viewModel.ApprenticeshipId, request);
Expand All @@ -695,14 +698,15 @@ public async Task<IActionResult> ViewApprenticeshipUpdates(ViewApprenticeshipUpd

[HttpPost]
[Route("{apprenticeshipHashedId}/changes/view")]
public async Task<IActionResult> ViewApprenticeshipUpdates(ViewApprenticeshipUpdatesViewModel viewModel)
public async Task<IActionResult> ViewApprenticeshipUpdates([FromServices] IAuthenticationService authenticationService, ViewApprenticeshipUpdatesViewModel viewModel)
{
if (viewModel.UndoChanges.Value)
{
var request = new UndoApprenticeshipUpdatesRequest
{
ApprenticeshipId = viewModel.ApprenticeshipId,
AccountId = viewModel.AccountId
AccountId = viewModel.AccountId,
UserInfo = authenticationService.UserInfo
};

await _commitmentsApiClient.UndoApprenticeshipUpdates(viewModel.ApprenticeshipId, request);
Expand Down

0 comments on commit c7ae9b6

Please sign in to comment.