From 8f0f38b692a2c9c1f7ae1d02db398288584d0885 Mon Sep 17 00:00:00 2001 From: Daniel Ashton Date: Thu, 16 Apr 2020 16:57:27 +0100 Subject: [PATCH] Add new fields to CSV download --- .../Cohort/DetailsViewModelMapperTests.cs | 2 +- .../ApprenticeshipDetailsCsvModelTests.cs | 66 ++++++++++++++++++- .../ApprenticeshipDetailsCsvModel.cs | 22 ++++++- 3 files changed, 87 insertions(+), 3 deletions(-) diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/DetailsViewModelMapperTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/DetailsViewModelMapperTests.cs index bdc80e5a5..503bb54ca 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/DetailsViewModelMapperTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Mappers/Cohort/DetailsViewModelMapperTests.cs @@ -493,7 +493,7 @@ public DetailsViewModelMapperTestsFixture() .ReturnsAsync(Cohort); CommitmentsApiClient.Setup(x => x.GetDraftApprenticeships(It.IsAny(), It.IsAny())) .ReturnsAsync(DraftApprenticeshipsResponse); - CommitmentsApiClient.Setup(x => x.GetLegalEntity(It.IsAny(), It.IsAny())) + CommitmentsApiClient.Setup(x => x.GetAccountLegalEntity(It.IsAny(), It.IsAny())) .ReturnsAsync(AccountLegalEntityResponse); AccountApiClient = new Mock(); diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Models/ApprenticeshipDetailsCsvModelTests.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Models/ApprenticeshipDetailsCsvModelTests.cs index a40b372a1..31e4313cb 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Models/ApprenticeshipDetailsCsvModelTests.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/Models/ApprenticeshipDetailsCsvModelTests.cs @@ -1,4 +1,5 @@ -using AutoFixture.NUnit3; +using System; +using AutoFixture.NUnit3; using FluentAssertions; using NUnit.Framework; using SFA.DAS.CommitmentsV2.Api.Types.Responses; @@ -56,6 +57,33 @@ public void Then_Maps_PlannedStartDate( result.PlannedStartDate.Should().Be(source.StartDate.ToString("MMM yyyy")); } + [Test, AutoData] + public void Then_Maps_PausedDate( + GetApprenticeshipsResponse.ApprenticeshipDetailsResponse source) + { + ApprenticeshipDetailsCsvModel result = source; + + result.PausedDate.Should().Be(source.PauseDate.ToString("MMM yyyy")); + } + + [Test, AutoData] + public void Then_Maps_DateOfBirth(GetApprenticeshipsResponse.ApprenticeshipDetailsResponse source) + { + ApprenticeshipDetailsCsvModel result = source; + + result.DateOfBirth.Should().Be(source.DateOfBirth.ToString("dd MMM yyyy")); + } + + [Test, AutoData] + public void Then_Maps_Empty_If_No_PausedDate( + GetApprenticeshipsResponse.ApprenticeshipDetailsResponse source) + { + source.PauseDate = DateTime.MinValue; + ApprenticeshipDetailsCsvModel result = source; + + result.PausedDate.Should().BeEmpty(); + } + [Test, AutoData] public void Then_Maps_Status( GetApprenticeshipsResponse.ApprenticeshipDetailsResponse source) @@ -64,6 +92,42 @@ public void Then_Maps_Status( result.Status.Should().Be(source.ApprenticeshipStatus.GetDescription()); } + + [Test, AutoData] + public void Then_Maps_Reference( + GetApprenticeshipsResponse.ApprenticeshipDetailsResponse source) + { + ApprenticeshipDetailsCsvModel result = source; + + result.CohortReference.Should().Be(source.CohortReference); + } + + [Test, AutoData] + public void Then_Maps_Your_Reference( + GetApprenticeshipsResponse.ApprenticeshipDetailsResponse source) + { + ApprenticeshipDetailsCsvModel result = source; + + result.EmployerRef.Should().Be(source.EmployerRef); + } + + [Test, AutoData] + public void Then_Maps_Uln( + GetApprenticeshipsResponse.ApprenticeshipDetailsResponse source) + { + ApprenticeshipDetailsCsvModel result = source; + + result.Uln.Should().Be(source.Uln); + } + + [Test, AutoData] + public void Then_Maps_TotalAgreedPrice( + GetApprenticeshipsResponse.ApprenticeshipDetailsResponse source) + { + ApprenticeshipDetailsCsvModel result = source; + + result.TotalAgreedPrice.Should().Be($"{source.TotalAgreedPrice.Value as object:n0}"); + } [Test, MoqAutoData] public void Then_Maps_Alerts( diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Apprentice/ApprenticeshipDetailsCsvModel.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Apprentice/ApprenticeshipDetailsCsvModel.cs index a3d77669d..dbd998566 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Apprentice/ApprenticeshipDetailsCsvModel.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Models/Apprentice/ApprenticeshipDetailsCsvModel.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Globalization; using CsvHelper.Configuration.Attributes; using SFA.DAS.CommitmentsV2.Api.Types.Responses; using SFA.DAS.CommitmentsV2.Shared.Extensions; @@ -16,8 +18,20 @@ public class ApprenticeshipDetailsCsvModel public string PlannedStartDate { get; private set; } [Name("Planned end date")] public string PlannedEndDate { get ; private set ; } + [Name("Paused Date")] + public string PausedDate { get; private set; } [Name("Training provider")] public string Provider { get; private set; } + [Name("Reference")] + public string CohortReference { get; private set; } + [Name("Uln")] + public string Uln { get; private set; } + [Name("Date of Birth")] + public string DateOfBirth { get; private set; } + [Name("Total agreed apprenticeship price")] + public string TotalAgreedPrice { get; private set; } + [Name("Your Reference")] + public string EmployerRef { get; private set; } [Name("Status")] public string Status { get ; private set ; } [Name("Alerts")] @@ -32,6 +46,12 @@ public static implicit operator ApprenticeshipDetailsCsvModel(GetApprenticeships CourseName = model.CourseName, PlannedStartDate = model.StartDate.ToGdsFormatWithoutDay(), PlannedEndDate = model.EndDate.ToGdsFormatWithoutDay(), + PausedDate = model.PauseDate != DateTime.MinValue ? model.PauseDate.ToGdsFormatWithoutDay() : "", + CohortReference = model.CohortReference, + EmployerRef = model.EmployerRef, + Uln = model.Uln, + DateOfBirth = model.DateOfBirth.ToGdsFormat(), + TotalAgreedPrice = $"{model.TotalAgreedPrice.Value as object:n0}", Status = model.ApprenticeshipStatus.GetDescription(), Alerts = GenerateAlerts(model.Alerts) };