From 400bffdc94a1765bd54fd0d5c2e1e57fccedec2c Mon Sep 17 00:00:00 2001 From: Liam Crossley Date: Thu, 27 May 2021 16:29:23 +0100 Subject: [PATCH 1/2] CON-3569 Added fix to model mapper --- .../ReviewApprenticeshipUpdatesRequestToViewModelMapper.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Apprentice/ReviewApprenticeshipUpdatesRequestToViewModelMapper.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Apprentice/ReviewApprenticeshipUpdatesRequestToViewModelMapper.cs index 1287ac3b6..8711ea398 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Apprentice/ReviewApprenticeshipUpdatesRequestToViewModelMapper.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Mappers/Apprentice/ReviewApprenticeshipUpdatesRequestToViewModelMapper.cs @@ -34,6 +34,12 @@ public async Task Map(ReviewApprent { var update = updates.ApprenticeshipUpdates.First(); + if (!string.IsNullOrWhiteSpace(update.FirstName + update.LastName)) + { + update.FirstName = string.IsNullOrWhiteSpace(update.FirstName) ? apprenticeship.FirstName : update.FirstName; + update.LastName = string.IsNullOrWhiteSpace(update.LastName) ? apprenticeship.LastName : update.LastName; + } + var vm = new ReviewApprenticeshipUpdatesRequestViewModel { AccountHashedId = source.AccountHashedId, From 6b41576ff91e8899f6a992e100580db934c08492 Mon Sep 17 00:00:00 2001 From: Corey Date: Fri, 28 May 2021 10:11:00 +0100 Subject: [PATCH 2/2] [CON-3569] Unit test for single name updates on apprenticeship --- ...hipUpdatesRequestToViewModelMapperTests.cs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/ReviewApprenticeshipUpdatesRequestToViewModelMapperTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/ReviewApprenticeshipUpdatesRequestToViewModelMapperTests.cs index 2d20ac866..88d362b0c 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/ReviewApprenticeshipUpdatesRequestToViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Apprentice/ReviewApprenticeshipUpdatesRequestToViewModelMapperTests.cs @@ -179,6 +179,38 @@ public async Task OriginalApprenticeship_TrainingName_IsMapped() Assert.AreEqual(fixture.ApprenticeshipUpdate.TrainingName, viewModel.ApprenticeshipUpdates.CourseName); } + [Test] + public async Task If_FirstName_Only_Updated_Map_FirstName_From_OriginalApprenticeship() + { + fixture.GetApprenticeshipUpdatesResponses.ApprenticeshipUpdates.First().LastName = null; + + var viewModel = await fixture.Map(); + + Assert.AreEqual(fixture.ApprenticeshipUpdate.FirstName, viewModel.ApprenticeshipUpdates.FirstName); + Assert.AreEqual(fixture.GetApprenticeshipResponse.LastName, viewModel.ApprenticeshipUpdates.LastName); + } + + [Test] + public async Task If_LastName_Only_Updated_Map_FirstName_From_OriginalApprenticeship() + { + fixture.GetApprenticeshipUpdatesResponses.ApprenticeshipUpdates.First().FirstName = null; + + var viewModel = await fixture.Map(); + + Assert.AreEqual(fixture.ApprenticeshipUpdate.LastName, viewModel.ApprenticeshipUpdates.LastName); + Assert.AreEqual(fixture.GetApprenticeshipResponse.FirstName, viewModel.ApprenticeshipUpdates.FirstName); + } + + [Test] + public async Task If_BothNames_Updated_Map_BothNames_From_Update() + { + var viewModel = await fixture.Map(); + + Assert.AreEqual(fixture.ApprenticeshipUpdate.FirstName, viewModel.ApprenticeshipUpdates.FirstName); + Assert.AreEqual(fixture.ApprenticeshipUpdate.LastName, viewModel.ApprenticeshipUpdates.LastName); + } + + public class ReviewApprenticeshipUpdatesRequestToViewModelMapperTestsFixture { public ReviewApprenticeshipUpdatesRequestToViewModelMapper Mapper;