Skip to content

Commit

Permalink
Merge pull request #227 from SkillsFundingAgency/CS-875-Test-Branch-f…
Browse files Browse the repository at this point in the history
…or-CS-727-CS-631-CS-632-CS-649-CS-650

Cs 875 test branch for cs 727 cs 631 cs 632 cs 649 cs 650
  • Loading branch information
SreekanthBadigenchula authored Jul 5, 2021
2 parents 873b34e + d5bd142 commit b08b017
Show file tree
Hide file tree
Showing 18 changed files with 341 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
using Microsoft.Extensions.Logging;
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.Types;
using SFA.DAS.EmployerCommitmentsV2.Features;
using SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Apprentice;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice;
using SFA.DAS.Encoding;
Expand All @@ -25,8 +27,10 @@ namespace SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Mappers.Apprentice
{
public class ApprenticeshipDetailsRequestToViewModelMapperTests
{
Fixture autoFixture = new Fixture();
private Mock<ICommitmentsApiClient> _mockCommitmentsApiClient;
private Mock<IEncodingService> _mockEncodingService;
private Mock<IAuthorizationService> _authorizationService;
private GetApprenticeshipResponse _apprenticeshipResponse;
private GetPriceEpisodesResponse _priceEpisodesResponse;
private GetApprenticeshipUpdatesResponse _apprenticeshipUpdatesResponse;
Expand All @@ -45,7 +49,6 @@ public class ApprenticeshipDetailsRequestToViewModelMapperTests
public void SetUp()
{
//Arrange
var autoFixture = new Fixture();
_request = autoFixture.Build<ApprenticeshipDetailsRequest>()
.With(x => x.AccountHashedId, $"A123")
.With(x => x.ApprenticeshipHashedId, $"A{ApprenticeshipIdFirst}")
Expand Down Expand Up @@ -90,7 +93,9 @@ public void SetUp()
_mockEncodingService.Setup(t => t.Decode(It.IsAny<string>(), It.IsAny<EncodingType>()))
.Returns((string value, EncodingType encodingType) => long.Parse(Regex.Replace(value, "[A-Za-z ]", "")));

_mapper = new ApprenticeshipDetailsRequestToViewModelMapper(_mockCommitmentsApiClient.Object, _mockEncodingService.Object, Mock.Of<ILogger<ApprenticeshipDetailsRequestToViewModelMapper>>());
_authorizationService = new Mock<IAuthorizationService>();

_mapper = new ApprenticeshipDetailsRequestToViewModelMapper(_mockCommitmentsApiClient.Object, _mockEncodingService.Object, Mock.Of<ILogger<ApprenticeshipDetailsRequestToViewModelMapper>>(), _authorizationService.Object);
}

[Test]
Expand Down Expand Up @@ -623,5 +628,40 @@ public async Task TrainingProviderHistory_IsMapped_When_Change_Of_Provider_Chain
Assert.IsTrue(result.TrainingProviderHistory[counter].ShowLink);
}
}

[TestCase(null)]
[TestCase(ConfirmationStatus.Unconfirmed)]
[TestCase(ConfirmationStatus.Confirmed)]
[TestCase(ConfirmationStatus.Overdue)]
public async Task GetApprenticeshipConfirmationStatus_IsMappedCorrectly(ConfirmationStatus? confirmationStatus)
{
// Arrange
_apprenticeshipResponse = autoFixture.Build<GetApprenticeshipResponse>()
.With(x => x.Id, ApprenticeshipIdFirst)
.With(x => x.CourseCode, "ABC")
.With(x => x.DateOfBirth, autoFixture.Create<DateTime>())
.With(x => x.ConfirmationStatus, confirmationStatus).Create();

_mockCommitmentsApiClient.Setup(x => x.GetApprenticeship(It.IsAny<long>(), CancellationToken.None))
.ReturnsAsync(_apprenticeshipResponse);

// Act
var result = await _mapper.Map(_request);

// Assert
Assert.AreEqual(result.ConfirmationStatus, confirmationStatus);
}

[TestCase(true)]
[TestCase(false)]
public async Task CheckShowConfirmationColumnIsMappedCorrectly(bool show)
{
_authorizationService.Setup(x => x.IsAuthorizedAsync(EmployerFeature.ApprenticeEmail))
.ReturnsAsync(show);

var result = await _mapper.Map(_request);

Assert.AreEqual(show, result.ShowApprenticeConfirmationColumn);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ public async Task Then_Maps_ApprenticeshipStatus(
result.Status.Should().Be(source.ApprenticeshipStatus);
}


[Test, MoqAutoData]
public async Task Then_Maps_ConfirmationStatus(
GetApprenticeshipsResponse.ApprenticeshipDetailsResponse source,
ApprenticeshipDetailsToViewModelMapper mapper)
{
var result = await mapper.Map(source);

result.ConfirmationStatus.Should().Be(source.ConfirmationStatus);
}


[Test, MoqAutoData]
public async Task Then_Maps_Alerts(
GetApprenticeshipsResponse.ApprenticeshipDetailsResponse source,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
using FluentAssertions;
using Moq;
using NUnit.Framework;
using SFA.DAS.Authorization.Services;
using SFA.DAS.CommitmentsV2.Api.Client;
using SFA.DAS.CommitmentsV2.Api.Types.Responses;
using SFA.DAS.CommitmentsV2.Shared.Interfaces;
using SFA.DAS.CommitmentsV2.Types;
using SFA.DAS.EmployerCommitmentsV2.Features;
using SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Apprentice;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice;
using SFA.DAS.Encoding;
Expand All @@ -36,6 +38,21 @@ public async Task Then_Defaults_To_Page_One_If_Less_Than_One(
Times.Once);
}

[Test, MoqAutoData]
public async Task Then_Shows_Apprentice_Confirmation_Column(
bool show,
[Frozen] Mock<IAuthorizationService> mockAuthorizationService,
IndexViewModelMapper mapper)
{
var request = new IndexRequest { PageNumber = 0 };
mockAuthorizationService.Setup(x => x.IsAuthorizedAsync(EmployerFeature.ApprenticeEmail))
.ReturnsAsync(show);

var viewModel = await mapper.Map(request);

viewModel.ShowApprenticeConfirmationColumn.Should().Be(show);
}

[Test, MoqAutoData]
public async Task Should_Pass_Params_To_Api_Call(
IndexRequest webRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<PackageReference Include="Moq" Version="4.10.1" />
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Api.Client" Version="7.38.0" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Shared" Version="7.38.0" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Types" Version="7.38.0" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Api.Client" Version="7.39.0" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Shared" Version="7.39.0" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Types" Version="7.39.0" />
<PackageReference Include="SFA.DAS.Testing" Version="3.0.22" />
<PackageReference Include="SFA.DAS.Testing.AutoFixture" Version="3.0.121" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static void Initialize(Registry registry)
registry.IncludeRegistry<WebRegistry>();

// Enable if you want to by pass MI locally.
//registry.IncludeRegistry<LocalDevRegistry>();
//registry.IncludeRegistry<LocalDevRegistry.LocalDevRegistry>();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;
using SFA.DAS.EAS.Account.Api.Client;
using SFA.DAS.EAS.Account.Api.Types;
using SFA.DAS.EmployerCommitmentsV2.Services.Stubs;

namespace SFA.DAS.EmployerCommitmentsV2.Web.LocalDevRegistry
{
public class LocalAccountApiClient : IAccountApiClient
{
private readonly HttpClient _httpClient;

public LocalAccountApiClient()
{
_httpClient = new HttpClient { BaseAddress = new System.Uri("https://das-commitments-stub-accapi.herokuapp.com/") };
}

public Task<AccountDetailViewModel> GetAccount(string hashedAccountId)
{
throw new NotImplementedException();
}

public Task<AccountDetailViewModel> GetAccount(long accountId)
{
throw new NotImplementedException();
}

public Task<ICollection<TeamMemberViewModel>> GetAccountUsers(string accountId)
{
throw new NotImplementedException();
}

public Task<ICollection<TeamMemberViewModel>> GetAccountUsers(long accountId)
{
throw new NotImplementedException();
}

public Task<EmployerAgreementView> GetEmployerAgreement(string accountId, string legalEntityId, string agreementId)
{
throw new NotImplementedException();
}

public async Task<ICollection<ResourceViewModel>> GetLegalEntitiesConnectedToAccount(string hashedAccountId)
{
var response = await _httpClient.GetAsync($"api/accounts/{hashedAccountId}/legalentities", CancellationToken.None).ConfigureAwait(false);
if (!response.IsSuccessStatusCode)
{
return new Collection<ResourceViewModel>();
}
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var ales = JsonConvert.DeserializeObject<Collection<ResourceViewModel>>(content);
return ales;
}

public async Task<LegalEntityViewModel> GetLegalEntity(string hashedAccountId, long id)
{
var response = await _httpClient.GetAsync($"api/accounts/{hashedAccountId}/legalentities/{id}", CancellationToken.None).ConfigureAwait(false);
if (!response.IsSuccessStatusCode)
{
return null;
}
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var ale = JsonConvert.DeserializeObject<LegalEntityViewModel>(content);
return ale;
}

public Task<ICollection<LevyDeclarationViewModel>> GetLevyDeclarations(string accountId)
{
throw new NotImplementedException();
}

public Task<PagedApiResponseViewModel<AccountLegalEntityViewModel>> GetPageOfAccountLegalEntities(int pageNumber = 1, int pageSize = 1000)
{
throw new NotImplementedException();
}

public Task<PagedApiResponseViewModel<AccountWithBalanceViewModel>> GetPageOfAccounts(int pageNumber = 1, int pageSize = 1000, DateTime? toDate = null)
{
throw new NotImplementedException();
}

public Task<ICollection<ResourceViewModel>> GetPayeSchemesConnectedToAccount(string accountId)
{
throw new NotImplementedException();
}

public Task<T> GetResource<T>(string uri)
{
throw new NotImplementedException();
}

public Task<StatisticsViewModel> GetStatistics()
{
throw new NotImplementedException();
}

public Task<TransactionsViewModel> GetTransactions(string accountId, int year, int month)
{
throw new NotImplementedException();
}

public Task<ICollection<TransactionSummaryViewModel>> GetTransactionSummary(string accountId)
{
throw new NotImplementedException();
}

public async Task<ICollection<TransferConnectionViewModel>> GetTransferConnections(string accountHashedId)
{

var response = await _httpClient.GetAsync($"api/accounts/{accountHashedId}/transfers/connections", CancellationToken.None).ConfigureAwait(false);
if (!response.IsSuccessStatusCode)
{
return new Collection<TransferConnectionViewModel>();
}
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var connections = JsonConvert.DeserializeObject<Collection<TransferConnectionViewModel>>(content);
return connections;
}

public Task<ICollection<AccountDetailViewModel>> GetUserAccounts(string userId)
{
throw new NotImplementedException();
}

public Task Ping()
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using SFA.DAS.Authorization.CommitmentPermissions.Client;
using System;
using SFA.DAS.Authorization.CommitmentPermissions.Client;
using SFA.DAS.CommitmentsV2.Api.Client;
using SFA.DAS.EAS.Account.Api.Client;
using StructureMap;
using System;

namespace SFA.DAS.EmployerCommitmentsV2.Web
namespace SFA.DAS.EmployerCommitmentsV2.Web.LocalDevRegistry
{
public class LocalDevRegistry : Registry
{
Expand All @@ -14,6 +15,7 @@ public LocalDevRegistry()
{
For<ICommitmentsApiClientFactory>().ClearAll().Use<LocalDevApiClientFactory>();
For<ICommitmentPermissionsApiClientFactory>().ClearAll().Use<LocalDevApiClientFactory>();
For<IAccountApiClient>().ClearAll().Use<LocalAccountApiClient>();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using SFA.DAS.CommitmentsV2.Types;
using SFA.DAS.EmployerCommitmentsV2.Web.Extensions;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Apprentice;
using SFA.DAS.EmployerCommitmentsV2.Features;
using SFA.DAS.Authorization.Services;
using SFA.DAS.Encoding;
using System;
using System.Collections.Generic;
Expand All @@ -19,12 +21,18 @@ public class ApprenticeshipDetailsRequestToViewModelMapper : IMapper<Apprentices
private readonly ICommitmentsApiClient _commitmentsApiClient;
private readonly IEncodingService _encodingService;
private readonly ILogger<ApprenticeshipDetailsRequestToViewModelMapper> _logger;
private readonly IAuthorizationService _authorizationService;

public ApprenticeshipDetailsRequestToViewModelMapper(ICommitmentsApiClient commitmentsApiClient, IEncodingService encodingService, ILogger<ApprenticeshipDetailsRequestToViewModelMapper> logger)
public ApprenticeshipDetailsRequestToViewModelMapper(
ICommitmentsApiClient commitmentsApiClient,
IEncodingService encodingService,
ILogger<ApprenticeshipDetailsRequestToViewModelMapper> logger,
IAuthorizationService authorizationService)
{
_commitmentsApiClient = commitmentsApiClient;
_encodingService = encodingService;
_logger = logger;
_authorizationService = authorizationService;
}

public async Task<ApprenticeshipDetailsRequestViewModel> Map(ApprenticeshipDetailsRequest source)
Expand Down Expand Up @@ -108,7 +116,9 @@ public async Task<ApprenticeshipDetailsRequestViewModel> Map(ApprenticeshipDetai
.ToList(),

PendingDataLockChange = dataLockPriceTriaged || dataLockCourseChangedTraiged,
PendingDataLockRestart = dataLockCourseTriaged
PendingDataLockRestart = dataLockCourseTriaged,
ConfirmationStatus = apprenticeship.ConfirmationStatus,
ShowApprenticeConfirmationColumn = await _authorizationService.IsAuthorizedAsync(EmployerFeature.ApprenticeEmail)
};

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public Task<ApprenticeshipDetailsViewModel> Map(GetApprenticeshipsResponse.Appre
PlannedStartDate = source.StartDate,
PlannedEndDate = source.EndDate,
Status = source.ApprenticeshipStatus,
ConfirmationStatus = source.ConfirmationStatus,
Alerts = source.Alerts.Select(x => x.GetDescription())
};

Expand Down
Loading

0 comments on commit b08b017

Please sign in to comment.