Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cv 610 change of party banner #152

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<PackageReference Include="nunit" Version="3.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.11.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Api.Client" Version="4.1.1346" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Types" Version="4.1.1346" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Api.Client" Version="4.1.1359" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Api.Types" Version="4.1.1359" />
<PackageReference Include="SFA.DAS.Testing.AutoFixture" Version="3.0.165" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<PackageReference Include="NUnit3TestAdapter" Version="3.11.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="CsvHelper" Version="12.3.2" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Api.Client" Version="4.1.1346" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Types" Version="4.1.1346" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Api.Client" Version="4.1.1359" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Api.Types" Version="4.1.1359" />
<PackageReference Include="SFA.DAS.Testing.AutoFixture" Version="3.0.165" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using System;
using Microsoft.AspNetCore.Mvc;
using Moq;
using NUnit.Framework;
using SFA.DAS.CommitmentsV2.Shared.Interfaces;
using SFA.DAS.ProviderCommitments.Web.Controllers;
using SFA.DAS.ProviderCommitments.Web.Models.Apprentice;
using System.Threading.Tasks;
using SFA.DAS.CommitmentsV2.Api.Client;

namespace SFA.DAS.ProviderCommitments.Web.UnitTests.Controllers.ApprenticesControllerTests
{
[TestFixture]
public class WhenGettingChangeEmployer
{
private GetChangeEmployerPageFixture _fixture;

[SetUp]
public void SetUp()
{
_fixture = new GetChangeEmployerPageFixture();
}

[TestCase(typeof(InformViewModel), "Inform")]
[TestCase(typeof(ChangeEmployerRequestDetailsViewModel), "ChangeEmployerRequestDetails")]
public async Task Then_Returns_Appropriate_View(Type mapperResultType, string expectedViewName)
{
_fixture.WithMapperResult(mapperResultType);
var result = await _fixture.Act();
var view = result.VerifyReturnsViewModel();
Assert.AreEqual(expectedViewName, view.ViewName);
Assert.AreEqual(mapperResultType, view.Model.GetType());
}
}

internal class GetChangeEmployerPageFixture
{
private string _apprenticeshipHashedId;
private long _apprenticeshipId;
private Mock<IModelMapper> _modelMapper;
private long _providerId;
private ChangeEmployerRequest _request;
private InformViewModel _informViewModel;
private ChangeEmployerRequestDetailsViewModel _changeEmployerRequestDetailsViewModel;
private ApprenticeController _sut;

public GetChangeEmployerPageFixture()
{
_providerId = 123;
_apprenticeshipId = 345;
_apprenticeshipHashedId = "DS23JF3";
_request = new ChangeEmployerRequest
{
ProviderId = _providerId,
ApprenticeshipHashedId = _apprenticeshipHashedId,
ApprenticeshipId = _apprenticeshipId
};
_informViewModel = new InformViewModel
{
ProviderId = _providerId,
ApprenticeshipHashedId = _apprenticeshipHashedId,
ApprenticeshipId = _apprenticeshipId
};
_changeEmployerRequestDetailsViewModel = new ChangeEmployerRequestDetailsViewModel();

_modelMapper = new Mock<IModelMapper>();
_modelMapper
.Setup(x => x.Map<IChangeEmployerViewModel>(_request))
.ReturnsAsync(_informViewModel);
_sut = new ApprenticeController(_modelMapper.Object, Mock.Of<ICookieStorageService<IndexRequest>>(), Mock.Of<ICommitmentsApiClient>());
}

public GetChangeEmployerPageFixture WithMapperResult(Type mapperResultType)
{
if (mapperResultType == typeof(InformViewModel))
{
_modelMapper
.Setup(x => x.Map<IChangeEmployerViewModel>(_request))
.ReturnsAsync(_informViewModel);
}
else
{
_modelMapper
.Setup(x => x.Map<IChangeEmployerViewModel>(_request))
.ReturnsAsync(_changeEmployerRequestDetailsViewModel);
}

return this;
}

public Task<IActionResult> Act() => _sut.ChangeEmployer(_request);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using SFA.DAS.Authorization.Features.Services;
using SFA.DAS.Authorization.ProviderFeatures.Models;
using SFA.DAS.ProviderCommitments.Features;
using SFA.DAS.Testing.Builders;

namespace SFA.DAS.ProviderCommitments.Web.UnitTests.Mappers.Apprentice
{
Expand Down Expand Up @@ -323,15 +324,56 @@ public async Task ThenChangeOfEmployerEnabledIsMappedCorrectly(bool enabled)
Assert.AreEqual(enabled, _fixture.Result.IsChangeOfEmployerEnabled);
}

[TestCase(null, false)]
[TestCase(ChangeOfPartyRequestStatus.Approved, false)]
[TestCase(ChangeOfPartyRequestStatus.Rejected, false)]
[TestCase(ChangeOfPartyRequestStatus.Withdrawn, false)]
[TestCase(ChangeOfPartyRequestStatus.Pending, true)]
public async Task ThenHasChangeOfPartyRequestPendingIsMappedCorrectly(ChangeOfPartyRequestStatus? status, bool expectHasPending)
{
if (status.HasValue)
{
_fixture.WithChangeOfPartyRequest(ChangeOfPartyRequestType.ChangeEmployer, status.Value);
}

await _fixture.Map();

Assert.AreEqual(expectHasPending, _fixture.Result.HasPendingChangeOfPartyRequest);
}

[Test]
public async Task ThenAPendingChangeOfPartyOriginatingFromEmployerDoesNotSetHasPendingChangeOfPartyRequest()
{
_fixture.WithChangeOfPartyRequest(ChangeOfPartyRequestType.ChangeProvider, ChangeOfPartyRequestStatus.Pending);

await _fixture.Map();

Assert.IsFalse(_fixture.Result.HasPendingChangeOfPartyRequest);
}

[TestCase(ChangeOfPartyRequestStatus.Approved, false)]
[TestCase(ChangeOfPartyRequestStatus.Pending, false)]
[TestCase(ChangeOfPartyRequestStatus.Rejected, true)]
[TestCase(ChangeOfPartyRequestStatus.Withdrawn, true)]
public async Task ThenPendingOrApprovedChangeOfPartyRequestPreventsChangeOfEmployer(ChangeOfPartyRequestStatus status, bool expectChangeEmployerEnabled)
{
_fixture
.WithChangeOfEmployerToggle(true)
.WithChangeOfPartyRequest(ChangeOfPartyRequestType.ChangeEmployer, status);
await _fixture.Map();
Assert.AreEqual(expectChangeEmployerEnabled, _fixture.Result.IsChangeOfEmployerEnabled);
}

public class DetailsViewModelMapperFixture
{
private readonly DetailsViewModelMapper _sut;
private DetailsViewModelMapper _sut;
public DetailsRequest Source { get; }
public DetailsViewModel Result { get; private set; }
public GetApprenticeshipResponse ApiResponse { get; }
public GetPriceEpisodesResponse PriceEpisodesApiResponse { get; }
public GetApprenticeshipUpdatesResponse GetApprenticeshipUpdatesResponse { get; private set; }
public GetDataLocksResponse GetDataLocksResponse { get; private set; }
public GetChangeOfPartyRequestsResponse GetChangeOfPartyRequestsResponse { get; private set; }

private readonly Mock<IEncodingService> _encodingService;
private readonly Mock<IFeatureTogglesService<ProviderFeatureToggle>> _featureToggleService;
Expand Down Expand Up @@ -365,6 +407,11 @@ public DetailsViewModelMapperFixture()
DataLocks = new List<GetDataLocksResponse.DataLock>()
};

GetChangeOfPartyRequestsResponse = new GetChangeOfPartyRequestsResponse
{
ChangeOfPartyRequests = new List<GetChangeOfPartyRequestsResponse.ChangeOfPartyRequest>()
};

_encodingService = new Mock<IEncodingService>();
_encodingService.Setup(x => x.Encode(It.IsAny<long>(), EncodingType.CohortReference)).Returns(CohortReference);
_encodingService.Setup(x => x.Encode(It.IsAny<long>(), EncodingType.PublicAccountLegalEntityId)).Returns(AgreementId);
Expand All @@ -378,7 +425,10 @@ public DetailsViewModelMapperFixture()
IsEnabled = false,
Whitelist = null
});
}

public async Task<DetailsViewModelMapperFixture> Map()
{
var apiClient = new Mock<ICommitmentsApiClient>();
apiClient.Setup(x => x.GetApprenticeship(It.IsAny<long>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(ApiResponse);
Expand All @@ -388,15 +438,15 @@ public DetailsViewModelMapperFixture()

apiClient.Setup(x => x.GetApprenticeshipUpdates(It.IsAny<long>(), It.IsAny<GetApprenticeshipUpdatesRequest>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(() => GetApprenticeshipUpdatesResponse);

apiClient.Setup(x => x.GetApprenticeshipDatalocksStatus(It.IsAny<long>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(GetDataLocksResponse);

apiClient.Setup(x => x.GetChangeOfPartyRequests(It.IsAny<long>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(GetChangeOfPartyRequestsResponse);

_sut = new DetailsViewModelMapper(apiClient.Object, _encodingService.Object, _featureToggleService.Object, Mock.Of<ILogger<DetailsViewModelMapper>>());
}

public async Task<DetailsViewModelMapperFixture> Map()
{
Result = await _sut.Map(Source);
return this;
}
Expand Down Expand Up @@ -531,6 +581,25 @@ public DetailsViewModelMapperFixture WithChangeOfEmployerToggle(bool enabled)
});
return this;
}

public DetailsViewModelMapperFixture WithChangeOfPartyRequest(ChangeOfPartyRequestType requestType, ChangeOfPartyRequestStatus status)
{
GetChangeOfPartyRequestsResponse = new GetChangeOfPartyRequestsResponse
{
ChangeOfPartyRequests = new List<GetChangeOfPartyRequestsResponse.ChangeOfPartyRequest>
{
new GetChangeOfPartyRequestsResponse.ChangeOfPartyRequest
{
Id = 1,
ChangeOfPartyType = requestType,
OriginatingParty = requestType == ChangeOfPartyRequestType.ChangeEmployer ? Party.Provider : Party.Employer,
Status = status
}
}
};

return this;
}
}
}
}
Loading