Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Moq;
using NUnit.Framework;
using SFA.DAS.ProviderCommitments.Infrastructure.OuterApi;
using SFA.DAS.ProviderCommitments.Infrastructure.OuterApi.Requests.Apprentices;
using SFA.DAS.ProviderCommitments.Infrastructure.OuterApi.Requests.Authorization;
using SFA.DAS.ProviderCommitments.Infrastructure.OuterApi.Requests.DraftApprenticeships;
using SFA.DAS.ProviderCommitments.Infrastructure.OuterApi.Requests.Provider;
Expand Down Expand Up @@ -123,4 +124,26 @@ public async Task Then_SyncLearnerData_Request_Is_Made_And_Response_Returned(
actual.Success.Should().Be(apiResponse.Success);
actual.Message.Should().Be(apiResponse.Message);
}

[Test, MoqAutoData]
public async Task Then_The_Request_Is_Made_And_GetApprenticeshipResponse_Returned(
long apprenticeshipId,
long provideId,
GetApprenticeshipResponse apiResponse,
[Frozen] Mock<IOuterApiClient> apiClient,
OuterApiService service)
{
//Arrange
var request = new GetApprenticeshipRequest(apprenticeshipId,provideId);
apiClient.Setup(x =>
x.Get<GetApprenticeshipResponse>(
It.Is<GetApprenticeshipRequest>(c => c.GetUrl.Equals(request.GetUrl))))
.ReturnsAsync(apiResponse);

//Act
var actual = await service.GetApprenticeship(apprenticeshipId,provideId);

//Assert
actual.Should().Be(apiResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
using SFA.DAS.CommitmentsV2.Types;
using SFA.DAS.ProviderCommitments.Infrastructure.OuterApi.Requests.DraftApprenticeship;
using SFA.DAS.ProviderCommitments.Infrastructure.OuterApi.Requests.OverlappingTrainingDateRequest;
using SFA.DAS.ProviderCommitments.Infrastructure.OuterApi.Responses;
using SFA.DAS.ProviderCommitments.Interfaces;
using SFA.DAS.ProviderCommitments.Web.Authentication;
using SFA.DAS.ProviderCommitments.Web.Controllers;
using SFA.DAS.ProviderCommitments.Web.Extensions;
using SFA.DAS.ProviderCommitments.Web.Models;
using SFA.DAS.ProviderCommitments.Web.Models.OveralppingTrainingDate;
using SFA.DAS.ProviderCommitments.Web.Services.Cache;
using SFA.DAS.ProviderUrlHelper;
using CreateCohortRequest = SFA.DAS.ProviderCommitments.Application.Commands.CreateCohort.CreateCohortRequest;
using CreateCohortResponse = SFA.DAS.ProviderCommitments.Application.Commands.CreateCohort.CreateCohortResponse;
Expand All @@ -33,8 +36,8 @@ public class OverlappingTrainingDateRequestControllerTestFixture
private readonly Mock<IOuterApiService> _outerApiService;
private readonly DraftApprenticeshipOverlapOptionRequest _draftApprenticeshipOverlapOptionRequest;
private readonly OverlapOptionsForChangeEmployerRequest _overlapOptionsForChangeEmployerRequest;
private GetApprenticeshipResponse _apprenticeshipDetails;
private CommitmentsV2.Api.Types.Responses.GetApprenticeshipResponse _apprenticeshipDetails;

private readonly DraftApprenticeshipOverlapOptionWithPendingRequest _overlapRequest;
private readonly DraftApprenticeshipOverlapOptionWithPendingRequestViewModel _overlapViewModel;

Expand All @@ -47,26 +50,41 @@ public class OverlappingTrainingDateRequestControllerTestFixture
private readonly DraftApprenticeshipOverlapAlertRequest _draftApprenticeshipOverlapAlertRequest;
private readonly UpdateDraftApprenticeshipApimRequest _updateDraftApprenticeshipRequest;

private readonly Mock<ICacheStorageService> _cacheStorageService;

private readonly Infrastructure.OuterApi.Responses.GetApprenticeshipResponse _getApprenticeshipResponse;

private readonly ChangeEmployerCacheItem _changeEmployerCacheItem;

private readonly ValidateUlnOverlapOnStartDateQueryResult _validateUlnOverlapOnStartDateQueryResult;

public OverlappingTrainingDateRequestControllerTestFixture()
{
_autoFixture = new Fixture();
_mockModelMapper = new Mock<IModelMapper>();

var linkGenerator = new Mock<ILinkGenerator>();

var providerId = _autoFixture.Create<long>();
var apprenticeShipId = _autoFixture.Create<long>();
_changeEmployerCacheItem = new ChangeEmployerCacheItem(Guid.NewGuid())
{ StartDate = "052026", EndDate = "052027", Uln = "123456" };

_draftApprenticeshipOverlapAlertRequest = _autoFixture.Create<DraftApprenticeshipOverlapAlertRequest>();
_updateDraftApprenticeshipRequest = _autoFixture.Create<UpdateDraftApprenticeshipApimRequest>();
_getApprenticeshipResponse = _autoFixture.Create<Infrastructure.OuterApi.Responses.GetApprenticeshipResponse>();
_cacheStorageService = new Mock<ICacheStorageService>();

_model = new DraftApprenticeshipViewModel
{
ProviderId = _autoFixture.Create<int>(),
ProviderId = providerId,
EmployerAccountLegalEntityPublicHashedId = _autoFixture.Create<string>(),
AccountLegalEntityId = _autoFixture.Create<long>(),
ReservationId = _autoFixture.Create<Guid>()
};

_draftApprenticeshipOverlapOptionRequest = new DraftApprenticeshipOverlapOptionRequest() { DraftApprenticeshipHashedId = "XXXXX", ApprenticeshipId = 1 };
_overlapOptionsForChangeEmployerRequest = new OverlapOptionsForChangeEmployerRequest { ProviderId = 2, ApprenticeshipId = 1, CacheKey = Guid.NewGuid() };
_draftApprenticeshipOverlapOptionRequest = new DraftApprenticeshipOverlapOptionRequest() { DraftApprenticeshipHashedId = "XXXXX", ApprenticeshipId = apprenticeShipId, ProviderId = providerId };
_overlapOptionsForChangeEmployerRequest = new OverlapOptionsForChangeEmployerRequest { ProviderId = providerId, ApprenticeshipId = apprenticeShipId, CacheKey = Guid.NewGuid() };

_tempData = new Mock<ITempDataDictionary>();

Expand Down Expand Up @@ -104,22 +122,28 @@ public OverlappingTrainingDateRequestControllerTestFixture()
.Returns(_linkGeneratorRedirectUrl)
.Callback((string value) => _ = value);


_outerApiService = new Mock<IOuterApiService>();
var commitmentsApiClient = new Mock<ICommitmentsApiClient>();
var validateUlnOverlapResult = new ValidateUlnOverlapResult();
_validateUlnOverlapOnStartDateQueryResult = new ValidateUlnOverlapOnStartDateQueryResult() { HasOverlapWithIlrWithdrawnApprenticeship = true, HasOverlapWithApprenticeshipId = _overlapOptionsForChangeEmployerRequest.ApprenticeshipId };
commitmentsApiClient.Setup(x => x.ValidateUlnOverlap(It.IsAny<ValidateUlnOverlapRequest>(), It.IsAny<CancellationToken>())).ReturnsAsync(() => validateUlnOverlapResult);
_outerApiService.Setup(x => x.ValidateUlnOverlapOnStartDate(It.Is<long>(t => t == _overlapOptionsForChangeEmployerRequest.ProviderId),
It.Is<string>(t => t == _changeEmployerCacheItem.Uln), It.Is<string>(t => t == DateTimeExtensions.FormatMonthYearDateToDateFormat(_changeEmployerCacheItem.StartDate)),
It.Is<string>(t => t == DateTimeExtensions.FormatMonthYearDateToDateFormat(_changeEmployerCacheItem.EndDate))))
.ReturnsAsync(() => _validateUlnOverlapOnStartDateQueryResult);

_mockModelMapper.Setup(x => x.Map<CreateOverlappingTrainingDateApimRequest>(It.IsAny<CreateCohortResponse>())).ReturnsAsync(() => new CreateOverlappingTrainingDateApimRequest());
_mockModelMapper.Setup(x => x.Map<CreateCohortRequest>(It.IsAny<DraftApprenticeshipOverlapOptionViewModel>())).ReturnsAsync(() => new CreateCohortRequest());
_mockModelMapper.Setup(x => x.Map<DraftApprenticeshipOverlapOptionViewModel>(It.IsAny<DraftApprenticeshipOverlapOptionRequest>())).ReturnsAsync(() => new DraftApprenticeshipOverlapOptionViewModel());

_apprenticeshipDetails = new GetApprenticeshipResponse()
_apprenticeshipDetails = new CommitmentsV2.Api.Types.Responses.GetApprenticeshipResponse()
{
Id = 1,
Status = ApprenticeshipStatus.Live
};
commitmentsApiClient.Setup(x => x.GetApprenticeship(It.IsAny<long>(), It.IsAny<CancellationToken>())).ReturnsAsync(() => _apprenticeshipDetails);

_outerApiService.Setup(x => x.GetApprenticeship(It.Is<long>(t => t == _draftApprenticeshipOverlapOptionRequest.ApprenticeshipId.Value),
It.Is<long>(t => t == _draftApprenticeshipOverlapOptionRequest.ProviderId))).ReturnsAsync(_getApprenticeshipResponse);

_overlapRequest = _autoFixture.Create<DraftApprenticeshipOverlapOptionWithPendingRequest>();
_overlapViewModel = _autoFixture.Create<DraftApprenticeshipOverlapOptionWithPendingRequestViewModel>();
Expand All @@ -130,20 +154,24 @@ public OverlappingTrainingDateRequestControllerTestFixture()
_changeOfEmployerNotifiedRequest = _autoFixture.Create<ChangeOfEmployerNotifiedRequest>();
_changeOfEmployerNotifiedViewModel = _autoFixture.Create<ChangeOfEmployerNotifiedViewModel>();

_cacheStorageService.Setup(x => x.RetrieveFromCache<ChangeEmployerCacheItem>(It.IsAny<Guid>())).
ReturnsAsync(_changeEmployerCacheItem);

_controller = new OverlappingTrainingDateRequestController(
mediator.Object,
_mockModelMapper.Object,
linkGenerator.Object,
commitmentsApiClient.Object,
Mock.Of<IAuthenticationService>(),
_outerApiService.Object
_outerApiService.Object,
_cacheStorageService.Object
);
_controller.TempData = _tempData.Object;
}

public OverlappingTrainingDateRequestControllerTestFixture SetApprenticeshipStatus(ApprenticeshipStatus status)
{
_apprenticeshipDetails.Status = status;
_getApprenticeshipResponse.Status = (short)status;
return this;
}

Expand Down Expand Up @@ -186,6 +214,15 @@ public OverlappingTrainingDateRequestControllerTestFixture VerifyOverlapOptionsF
return this;
}

public OverlappingTrainingDateRequestControllerTestFixture VerifyOverlapOptionsForChangeEmployerViewModelViewReturnedWithNoWithdrawnReasonCode()
{
var viewResult = _actionResult as ViewResult;
viewResult.Should().NotBeNull();
var model = viewResult.Model as OverlapOptionsForChangeEmployerViewModel;
model.HasWithdrawnStatusCode.Should().BeFalse();
return this;
}

public async Task<OverlappingTrainingDateRequestControllerTestFixture> DraftApprenticeshipOverlapOptions()
{
_actionResult = await _controller.DraftApprenticeshipOverlapOptions(_draftApprenticeshipOverlapOptionViewModel);
Expand Down Expand Up @@ -228,7 +265,7 @@ public OverlappingTrainingDateRequestControllerTestFixture SetupUpdateDraftAppre
{
_mockModelMapper.Setup(m => m.Map<UpdateDraftApprenticeshipApimRequest>(It.Is<EditDraftApprenticeshipViewModel>(x => x.Uln == _model.Uln))).ReturnsAsync(_updateDraftApprenticeshipRequest);
return this;
}
}

public OverlappingTrainingDateRequestControllerTestFixture GetChangeOfEmployerNotified()
{
Expand Down Expand Up @@ -289,8 +326,8 @@ public OverlappingTrainingDateRequestControllerTestFixture VerifyEmployerNotifie
using (new AssertionScope())
{
model.Should().NotBeNull();
_employerNotifiedRequest.CohortReference.Should().Be(model.CohortReference);
_employerNotifiedRequest.ProviderId.Should().Be(model.ProviderId);
_employerNotifiedRequest.CohortReference.Should().Be(model.CohortReference);
_employerNotifiedRequest.ProviderId.Should().Be(model.ProviderId);
}
return this;
}
Expand All @@ -314,9 +351,9 @@ public OverlappingTrainingDateRequestControllerTestFixture GetDraftApprenticeshi
return this;
}

public OverlappingTrainingDateRequestControllerTestFixture GetOverlapOptionsForChangeEmployer()
public async Task<OverlappingTrainingDateRequestControllerTestFixture> GetOverlapOptionsForChangeEmployer()
{
_actionResult = _controller.OverlapOptionsForChangeEmployer(_overlapOptionsForChangeEmployerRequest);
_actionResult = await _controller.OverlapOptionsForChangeEmployer(_overlapOptionsForChangeEmployerRequest);
return this;
}

Expand All @@ -339,7 +376,7 @@ public OverlappingTrainingDateRequestControllerTestFixture VerifyOverlapRequests
}
return this;
}

public OverlappingTrainingDateRequestControllerTestFixture GetDraftApprenticeshipOverlapAlert()
{
_actionResult = _controller.DraftApprenticeshipOverlapAlert(_draftApprenticeshipOverlapAlertRequest);
Expand Down Expand Up @@ -394,5 +431,17 @@ public OverlappingTrainingDateRequestControllerTestFixture VerifyExistingDraftAp

return this;
}

public OverlappingTrainingDateRequestControllerTestFixture SetupWithdrawnStatusCode(int? statusCode)
{
_getApprenticeshipResponse.WithdrawnReasonCode = statusCode;
return this;
}

public OverlappingTrainingDateRequestControllerTestFixture SetupHasOverlapWithIlrWithdrawnApprenticeship(bool value)
{
_validateUlnOverlapOnStartDateQueryResult.HasOverlapWithIlrWithdrawnApprenticeship = value;
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ public async Task AndWhenIGetDraftApprenticeshipOverlapOptions_CorrectViewModelI
_fixture.VerifyDraftApprenticeshipOverlapOptionsViewReturned();
}

[Test]
public async Task AndWhenIGetDraftApprenticeshipOverlapOptions_NotWithdrawnFromIlrPreviousApprenticeship_CorrectViewModelIsReturned()
{
await _fixture.SetupWithdrawnStatusCode(null).GetDraftApprenticeshipOverlapOptions();
_fixture.VerifyDraftApprenticeshipOverlapOptionsViewReturned();
}

[Test]
public async Task AndWhenIGetDraftApprenticeshipOverlapOptions_ModelIsMapped()
{
Expand All @@ -30,6 +37,14 @@ await _fixture
_fixture.VerifyWhenGettingOverlappingTrainingDate_ModelIsMapped();
}

[Test]
public async Task AndWhenIGetDraftApprenticeshipOverlapOptions_NotWithdrawnFromIlrPreviousApprenticeship_ModelIsMapped()
{
await _fixture.SetupWithdrawnStatusCode(null)
.GetDraftApprenticeshipOverlapOptions();
_fixture.VerifyWhenGettingOverlappingTrainingDate_ModelIsMapped();
}

[Test]
public async Task AndWhenWhenUserSelectsToSendOverlapEmailToEmployer()
{
Expand Down Expand Up @@ -63,6 +78,7 @@ public async Task ThenEnableStopRequestEmailIsMappedCorrectly(CommitmentsV2.Type
{
await _fixture
.SetApprenticeshipStatus(apprenticeshipStatus)
.SetupWithdrawnStatusCode(null)
.GetDraftApprenticeshipOverlapOptions();

_fixture.VerifyEnableEmployerRequestEmail(sendEmail);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@ public void Arrange()
}

[Test]
public void AndWhenGetDraftApprenticeshipOverlapOptionsChangeEmployerEndpointIsCalled_CorrectViewModelIsReturned()
public async Task AndWhenGetDraftApprenticeshipOverlapOptionsChangeEmployerEndpointIsCalled_CorrectViewModelIsReturned()
{
_fixture.GetOverlapOptionsForChangeEmployer();
await _fixture.GetOverlapOptionsForChangeEmployer();
_fixture.VerifyOverlapOptionsForChangeEmployerViewModelViewReturned();
}

Comment thread
cofaulco marked this conversation as resolved.
[Test]
public async Task AndWhenGetDraftApprenticeshipOverlapOptionsChangeEmployerEndpointIsCalled_NotWithdrawnFromIlrPreviousApprenticeship_CorrectViewModelIsReturned()
{
await _fixture.SetupWithdrawnStatusCode(null).SetupHasOverlapWithIlrWithdrawnApprenticeship(false).GetOverlapOptionsForChangeEmployer();
_fixture.VerifyOverlapOptionsForChangeEmployerViewModelViewReturnedWithNoWithdrawnReasonCode();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using SFA.DAS.ProviderCommitments.Web.Models.OveralppingTrainingDate;

namespace SFA.DAS.ProviderCommitments.Web.UnitTests.Models;

public class WhenGettingOverlapOptionsForChangeEmployerViewModelTests
{
[Test]
public void WhenHasWithdrawnReasonCode_ShouldSelectChangeEmployerOverlapIlrWithdrawnPartial()
{
// Arrange
var model = new OverlapOptionsForChangeEmployerViewModel { HasWithdrawnStatusCode = true };

// Act
string partialName = model.GetTargetPartialViewName();

// Assert
Assert.That(partialName, Is.EqualTo("_ChangeEmployerOverlapIlrWithdrawnPartial"));
}

[Test]
public void WhenHasWithdrawnReasonCode_ShouldSelectOverlapOptionsForChangeEmployerPartial()
{
// Arrange
var model = new OverlapOptionsForChangeEmployerViewModel { HasWithdrawnStatusCode = false };

// Act
string partialName = model.GetTargetPartialViewName();

// Assert
Assert.That(partialName, Is.EqualTo("_OverlapOptionsForChangeEmployerPartial"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,35 @@ public class OverlapOptionsForChangeEmployerViewModelValidatorTests
[TestCase(1, true)]
public void Validate_ProviderId_ShouldBeValidated(int providerId, bool expectedValid)
{
var model = new OverlapOptionsForChangeEmployerViewModel { ProviderId = providerId };
var model = new OverlapOptionsForChangeEmployerViewModel { ProviderId = providerId, HasWithdrawnStatusCode = false };
AssertValidationResult(request => request.ProviderId, model, expectedValid);
}


[TestCase(0, false)]
[TestCase(1, true)]
public void Validate_ApprenticeshipId_ShouldBeValidated(int apprenticeshipId, bool expectedValid)
{
var model = new OverlapOptionsForChangeEmployerViewModel { ApprenticeshipId = apprenticeshipId };
var model = new OverlapOptionsForChangeEmployerViewModel { ApprenticeshipId = apprenticeshipId, HasWithdrawnStatusCode = false };
AssertValidationResult(request => request.ApprenticeshipId, model, expectedValid);
}


[TestCase(null, false)]
[TestCase(OverlapOptions.CompleteActionLater, true)]
[TestCase(OverlapOptions.ContactTheEmployer, true)]
[TestCase(OverlapOptions.SendStopRequest, true)]
public void Validate_Selection_ShouldBeValidated(OverlapOptions? selection, bool expectedValid)
{
var model = new OverlapOptionsForChangeEmployerViewModel { OverlapOptions = selection };
var model = new OverlapOptionsForChangeEmployerViewModel { OverlapOptions = selection, HasWithdrawnStatusCode = false };
AssertValidationResult(request => request.OverlapOptions, model, expectedValid);
}

[TestCase(0, true)]
public void Validate_ProviderId_ShouldBeValidated_HasWithdrawnStatusCode(int providerId, bool expectedValid)
{
var model = new OverlapOptionsForChangeEmployerViewModel { ProviderId = providerId, HasWithdrawnStatusCode = true };
AssertValidationResult(request => request.ProviderId, model, expectedValid);
}

private static void AssertValidationResult<T>(Expression<Func<OverlapOptionsForChangeEmployerViewModel, T>> property, OverlapOptionsForChangeEmployerViewModel instance, bool expectedValid)
{
var validator = new OverlapOptionsForChangeEmployerViewModelValidator();
Expand All @@ -51,4 +56,4 @@ private static void AssertValidationResult<T>(Expression<Func<OverlapOptionsForC
}
}
}
}
}
Loading
Loading