Skip to content

Commit

Permalink
Merge pull request #193 from SkillsFundingAgency/CS-428-Add-email-add…
Browse files Browse the repository at this point in the history
…ress

CS-428 add apprentice email address to add and edit pages (draft apprenticeship)
  • Loading branch information
SreekanthBadigenchula authored Apr 21, 2021
2 parents 51e5ad6 + 15c0e9f commit 45457da
Show file tree
Hide file tree
Showing 23 changed files with 142 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public void Map_WhenMapping_ThenShouldSetProperties()
r.ProviderId.Should().Be(1);
r.FirstName.Should().Be(f.ViewModel.FirstName);
r.LastName.Should().Be(f.ViewModel.LastName);
r.Email.Should().Be(f.ViewModel.Email);
r.DateOfBirth.Should().Be(f.ViewModel.DateOfBirth.Date);
r.Uln.Should().Be(f.ViewModel.Uln);
r.CourseCode.Should().Be(f.ViewModel.CourseCode);
Expand All @@ -46,6 +47,7 @@ public AddDraftApprenticeshipViewModelToAddDraftApprenticeshipRequestMapperTests
{
FirstName = "John",
LastName = "Doe",
Email = "test@test.com",
BirthDay = 1,
BirthMonth = 2,
BirthYear = 2000,
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.Models;
using SFA.DAS.CommitmentsV2.Types;
using SFA.DAS.EmployerCommitmentsV2.Features;
using SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Cohort;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Cohort;

Expand All @@ -20,6 +22,7 @@ public class ApprenticeViewModelMapperTests
{
private ApprenticeViewModelMapper _mapper;
private Mock<ICommitmentsApiClient> _commitmentsApiClient;
private Mock<IAuthorizationService> _authorizationService;
private GetProviderResponse _providerResponse;
private AccountLegalEntityResponse _accountLegalEntityResponse;
private ApprenticeRequest _source;
Expand Down Expand Up @@ -62,10 +65,10 @@ public async Task Arrange()
{
TrainingProgrammes = _allTrainingProgrammes
});

_authorizationService = new Mock<IAuthorizationService>();

_mapper = new ApprenticeViewModelMapper(
_commitmentsApiClient.Object);
_commitmentsApiClient.Object, _authorizationService.Object);

_result = await _mapper.Map(TestHelper.Clone(_source));
}
Expand Down Expand Up @@ -159,5 +162,16 @@ public async Task NonLevyCohortsAllowStandardCoursesOnlyRegardlessOfTransferStat
_result = await _mapper.Map(TestHelper.Clone(_source));
_result.Courses.Should().BeEquivalentTo(_standardTrainingProgrammes);
}

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

_result = await _mapper.Map(TestHelper.Clone(_source));
_result.ShowEmail.Should().Be(show);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ public void ThenUniqueLearnerNumberIsMappedCorrectly()
Assert.AreEqual(_source.Uln, _result.Uln);
}

[Test]
public void ThenEmailIsMappedCorrectly()
{
Assert.AreEqual(_source.Email, _result.Email);
}


[Test]
public void ThenCourseCodeIsMappedCorrectly()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ public async Task ThenLastNameIsMappedCorrectly()
Assert.AreEqual(_source.LastName, result.LastName);
}

[Test]
public async Task ThenEmailIsMappedCorrectly()
{
var result = await _act();
Assert.AreEqual(_source.Email, result.Email);
}

[Test]
public async Task ThenUniqueLearnerNumberIsMappedCorrectly()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ public async Task ThenUniqueLearnerNumberIsMappedToNull()
Assert.AreEqual(_source.Uln, result.Uln);
}

[Test]
public async Task ThenEmailIsMappedCorrectly()
{
var result = await _act();
Assert.AreEqual(_source.Email, result.Email);
}

[Test]
public async Task ThenCourseCodeIsMappedCorrectly()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
using System.Threading;
using System.Threading.Tasks;
using AutoFixture;
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.Models;
using SFA.DAS.CommitmentsV2.Types;
using SFA.DAS.EmployerCommitmentsV2.Features;
using SFA.DAS.EmployerCommitmentsV2.Web.Exceptions;
using SFA.DAS.EmployerCommitmentsV2.Web.Mappers.DraftApprenticeship;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.DraftApprenticeship;
Expand All @@ -24,6 +27,7 @@ public class AddDraftApprenticeshipViewModelMapperTests
private AddDraftApprenticeshipViewModel _result;

private Mock<ICommitmentsApiClient> _commitmentsApiClient;
private Mock<IAuthorizationService> _authorizationService;
private Mock<IEncodingService> _encodingService;
private string _encodedTransferSenderId;
private GetCohortResponse _cohort;
Expand Down Expand Up @@ -64,7 +68,9 @@ public async Task Arrange()
.Setup(x => x.Encode(It.IsAny<long>(), It.Is<EncodingType>(e => e == EncodingType.PublicAccountId)))
.Returns(_encodedTransferSenderId);

_mapper = new AddDraftApprenticeshipViewModelMapper(_commitmentsApiClient.Object, _encodingService.Object);
_authorizationService = new Mock<IAuthorizationService>();

_mapper = new AddDraftApprenticeshipViewModelMapper(_commitmentsApiClient.Object, _encodingService.Object, _authorizationService.Object);

_source = autoFixture.Create<AddDraftApprenticeshipRequest>();
_source.StartMonthYear = "092020";
Expand Down Expand Up @@ -178,5 +184,16 @@ public void ThrowsWhenCohortNotWithEditingParty()
_cohort.WithParty = Party.Provider;
Assert.ThrowsAsync<CohortEmployerUpdateDeniedException>(() => _mapper.Map(_source));
}

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

_result = await _mapper.Map(TestHelper.Clone(_source));
_result.ShowEmail.Should().Be(show);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
using System.Threading;
using System.Threading.Tasks;
using AutoFixture;
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.Types;
using SFA.DAS.EmployerCommitmentsV2.Features;
using SFA.DAS.EmployerCommitmentsV2.Web.Mappers.DraftApprenticeship;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.DraftApprenticeship;
using SFA.DAS.EmployerCommitmentsV2.Web.UnitTests.Extensions;
Expand All @@ -23,6 +26,7 @@ public class EditDraftApprenticeshipViewModelMapperTests
private EditDraftApprenticeshipViewModel _result;

private Mock<ICommitmentsApiClient> _commitmentsApiClient;
private Mock<IAuthorizationService> _authorizationService;
private GetDraftApprenticeshipResponse _draftApprenticeshipResponse;
private Mock<IEncodingService> _encodingService;
private string _encodedApprenticeshipId;
Expand Down Expand Up @@ -75,9 +79,11 @@ public async Task Arrange()
_commitmentsApiClient.Setup(x => x.GetCohort(It.IsAny<long>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(_cohort);

_authorizationService = new Mock<IAuthorizationService>();

_source = autoFixture.Create<EditDraftApprenticeshipRequest>();
_source.Cohort = _cohort;
_mapper = new EditDraftApprenticeshipViewModelMapper(_commitmentsApiClient.Object, _encodingService.Object);
_mapper = new EditDraftApprenticeshipViewModelMapper(_commitmentsApiClient.Object, _encodingService.Object, _authorizationService.Object);

_result = await _mapper.Map(TestHelper.Clone(_source)) as EditDraftApprenticeshipViewModel;
}
Expand Down Expand Up @@ -124,6 +130,12 @@ public void LastNameIsMappedCorrectly()
Assert.AreEqual(_draftApprenticeshipResponse.LastName, _result.LastName);
}

[Test]
public void EmailIsMappedCorrectly()
{
Assert.AreEqual(_draftApprenticeshipResponse.Email, _result.Email);
}

[Test]
public void DateOfBirthIsMappedCorrectly()
{
Expand Down Expand Up @@ -230,5 +242,16 @@ public async Task ThenIsContinuationIsMappedCorrectly(bool isContinuation)
_result = await _mapper.Map(_source) as EditDraftApprenticeshipViewModel;
Assert.AreEqual(_draftApprenticeshipResponse.IsContinuation, _result.IsContinuation);
}

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

_result = await _mapper.Map(TestHelper.Clone(_source)) as EditDraftApprenticeshipViewModel;
_result.ShowEmail.Should().Be(show);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ public void ThenLastNameIsMappedCorrectly()
Assert.AreEqual(_draftApprenticeship.LastName, _result.LastName);
}

[Test]
public void ThenEmailIsMappedCorrectly()
{
Assert.AreEqual(_draftApprenticeship.Email, _result.Email);
}

[Test]
public void ThenUlnIsMappedCorrectly()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
<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.13.0" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Shared" Version="7.13.0" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Api.Client" Version="7.13.2" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Shared" Version="7.13.2" />
<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 @@ -16,6 +16,7 @@ public Task<AddDraftApprenticeshipRequest> Map(AddDraftApprenticeshipViewModel s
FirstName = source.FirstName,
LastName = source.LastName,
DateOfBirth = source.DateOfBirth.Date,
Email = source.Email,
Uln = source.Uln,
CourseCode = source.CourseCode,
Cost = source.Cost,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
using System.Threading.Tasks;
using SFA.DAS.Authorization.Services;
using SFA.DAS.CommitmentsV2.Shared.Interfaces;
using SFA.DAS.CommitmentsV2.Shared.Models;
using SFA.DAS.CommitmentsV2.Api.Client;
using SFA.DAS.CommitmentsV2.Types;
using SFA.DAS.EmployerCommitmentsV2.Features;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Cohort;

namespace SFA.DAS.EmployerCommitmentsV2.Web.Mappers.Cohort
{
public class ApprenticeViewModelMapper : IMapper<ApprenticeRequest, ApprenticeViewModel>
{
private readonly ICommitmentsApiClient _commitmentsApiClient;
private readonly IAuthorizationService _authorizationService;

public ApprenticeViewModelMapper(ICommitmentsApiClient commitmentsApiClient)
public ApprenticeViewModelMapper(ICommitmentsApiClient commitmentsApiClient, IAuthorizationService authorizationService)
{
_commitmentsApiClient = commitmentsApiClient;
_authorizationService = authorizationService;
}

public async Task<ApprenticeViewModel> Map(ApprenticeRequest source)
Expand Down Expand Up @@ -41,7 +45,8 @@ public async Task<ApprenticeViewModel> Map(ApprenticeRequest source)
Courses = courses,
TransferSenderId = source.TransferSenderId,
Origin = source.Origin,
AutoCreatedReservation = source.AutoCreated
AutoCreatedReservation = source.AutoCreated,
ShowEmail = await _authorizationService.IsAuthorizedAsync(EmployerFeature.ApprenticeEmail)
};

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public Task<CreateCohortRequest> Map(ApprenticeViewModel source)
ReservationId = source.ReservationId,
FirstName = source.FirstName,
LastName = source.LastName,
Email = source.Email,
DateOfBirth = source.DateOfBirth.Date,
Uln = source.Uln,
CourseCode = source.CourseCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public Task<EditDraftApprenticeshipViewModel> Map(EditDraftApprenticeshipDetails
ReservationId = source.ReservationId,
FirstName = source.FirstName,
LastName = source.LastName,
Email = source.Email,
Uln = source.UniqueLearnerNumber,
CourseCode = source.CourseCode,
Cost = source.Cost,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public Task<UpdateDraftApprenticeshipRequest> Map(EditDraftApprenticeshipViewMod
ReservationId = source.ReservationId,
FirstName = source.FirstName,
LastName = source.LastName,
Email = source.Email,
DateOfBirth = source.DateOfBirth.Date,
Uln = source.Uln,
CourseCode = source.CourseCode,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.Threading.Tasks;
using SFA.DAS.Authorization.Services;
using SFA.DAS.CommitmentsV2.Api.Client;
using SFA.DAS.CommitmentsV2.Shared.Interfaces;
using SFA.DAS.CommitmentsV2.Shared.Models;
using SFA.DAS.CommitmentsV2.Types;
using SFA.DAS.EmployerCommitmentsV2.Features;
using SFA.DAS.EmployerCommitmentsV2.Web.Exceptions;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.DraftApprenticeship;
using SFA.DAS.Encoding;
Expand All @@ -13,12 +15,14 @@ public class AddDraftApprenticeshipViewModelMapper : IMapper<AddDraftApprentices
{
private readonly ICommitmentsApiClient _commitmentsApiClient;
private readonly IEncodingService _encodingService;
private readonly IAuthorizationService _authorizationService;

public AddDraftApprenticeshipViewModelMapper(ICommitmentsApiClient commitmentsApiClient,
IEncodingService encodingService)
IEncodingService encodingService, IAuthorizationService authorizationService)
{
_commitmentsApiClient = commitmentsApiClient;
_encodingService = encodingService;
_authorizationService = authorizationService;
}

public async Task<AddDraftApprenticeshipViewModel> Map(AddDraftApprenticeshipRequest source)
Expand All @@ -44,7 +48,8 @@ public async Task<AddDraftApprenticeshipViewModel> Map(AddDraftApprenticeshipReq
? (await _commitmentsApiClient.GetAllTrainingProgrammeStandards()).TrainingProgrammes
: (await _commitmentsApiClient.GetAllTrainingProgrammes()).TrainingProgrammes,
TransferSenderHashedId = cohort.IsFundedByTransfer ? _encodingService.Encode(cohort.TransferSenderId.Value, EncodingType.PublicAccountId) : string.Empty,
AutoCreatedReservation = source.AutoCreated
AutoCreatedReservation = source.AutoCreated,
ShowEmail = await _authorizationService.IsAuthorizedAsync(EmployerFeature.ApprenticeEmail)
};

return result;
Expand Down
Loading

0 comments on commit 45457da

Please sign in to comment.