From 405fe582437e4c4a3c9b112246b5e6343702a85a Mon Sep 17 00:00:00 2001 From: Andy Mantell <134642+andymantell@users.noreply.github.com> Date: Thu, 19 Dec 2024 09:59:23 +0000 Subject: [PATCH] Add missing data-sharing-api mapping for Multiline and GroupedSingleChoice field types --- .../CustomFormQuestionTypeResolverTests.cs | 13 +++++++++++++ .../AutoMapper/DataSharingProfile.cs | 15 ++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Services/CO.CDP.DataSharing.WebApi.Tests/AutoMapper/CustomFormQuestionTypeResolverTests.cs b/Services/CO.CDP.DataSharing.WebApi.Tests/AutoMapper/CustomFormQuestionTypeResolverTests.cs index 41fbba443..0bf748985 100644 --- a/Services/CO.CDP.DataSharing.WebApi.Tests/AutoMapper/CustomFormQuestionTypeResolverTests.cs +++ b/Services/CO.CDP.DataSharing.WebApi.Tests/AutoMapper/CustomFormQuestionTypeResolverTests.cs @@ -17,10 +17,12 @@ public CustomFormQuestionTypeResolverTests() [InlineData(OrganisationInformation.Persistence.Forms.FormQuestionType.YesOrNo, FormQuestionType.Boolean)] [InlineData(OrganisationInformation.Persistence.Forms.FormQuestionType.CheckBox, FormQuestionType.Boolean)] [InlineData(OrganisationInformation.Persistence.Forms.FormQuestionType.Text, FormQuestionType.Text)] + [InlineData(OrganisationInformation.Persistence.Forms.FormQuestionType.MultiLine, FormQuestionType.Text)] [InlineData(OrganisationInformation.Persistence.Forms.FormQuestionType.FileUpload, FormQuestionType.FileUpload)] [InlineData(OrganisationInformation.Persistence.Forms.FormQuestionType.Address, FormQuestionType.Text)] [InlineData(OrganisationInformation.Persistence.Forms.FormQuestionType.SingleChoice, FormQuestionType.Option)] [InlineData(OrganisationInformation.Persistence.Forms.FormQuestionType.MultipleChoice, FormQuestionType.Option)] + [InlineData(OrganisationInformation.Persistence.Forms.FormQuestionType.GroupedSingleChoice, FormQuestionType.Option)] [InlineData(OrganisationInformation.Persistence.Forms.FormQuestionType.Date, FormQuestionType.Date)] [InlineData(OrganisationInformation.Persistence.Forms.FormQuestionType.Url, FormQuestionType.Url)] [InlineData(OrganisationInformation.Persistence.Forms.FormQuestionType.NoInput, FormQuestionType.None)] @@ -36,6 +38,17 @@ public void Resolve_ReturnsExpectedFormQuestionType( result.Should().Be(expectedType); } + [Fact] + public void Resolve_ShouldHandleAllFormQuestionTypesWithoutException() + { + foreach (OrganisationInformation.Persistence.Forms.FormQuestionType formQuestionType in Enum.GetValues(typeof(OrganisationInformation.Persistence.Forms.FormQuestionType))) + { + OrganisationInformation.Persistence.Forms.FormQuestion sourceQuestion = GivenQuestion(formQuestionType); + Action act = () => _resolver.Resolve(sourceQuestion, null!, default, null!); + act.Should().NotThrow(); + } + } + private static OrganisationInformation.Persistence.Forms.FormQuestion GivenQuestion(OrganisationInformation.Persistence.Forms.FormQuestionType type) { return new OrganisationInformation.Persistence.Forms.FormQuestion { diff --git a/Services/CO.CDP.DataSharing.WebApi/AutoMapper/DataSharingProfile.cs b/Services/CO.CDP.DataSharing.WebApi/AutoMapper/DataSharingProfile.cs index 1bdddb6fd..23bf59332 100644 --- a/Services/CO.CDP.DataSharing.WebApi/AutoMapper/DataSharingProfile.cs +++ b/Services/CO.CDP.DataSharing.WebApi/AutoMapper/DataSharingProfile.cs @@ -140,23 +140,32 @@ public FormQuestionType Resolve(Persistence.FormQuestion source, case Persistence.FormQuestionType.YesOrNo: case Persistence.FormQuestionType.CheckBox: return FormQuestionType.Boolean; + case Persistence.FormQuestionType.Text: case Persistence.FormQuestionType.Address: + case Persistence.FormQuestionType.MultiLine: return FormQuestionType.Text; + case Persistence.FormQuestionType.SingleChoice: + case Persistence.FormQuestionType.GroupedSingleChoice: case Persistence.FormQuestionType.MultipleChoice: return FormQuestionType.Option; + case Persistence.FormQuestionType.Date: return FormQuestionType.Date; + case Persistence.FormQuestionType.Url: return FormQuestionType.Url; + + case Persistence.FormQuestionType.FileUpload: + return FormQuestionType.FileUpload; + case Persistence.FormQuestionType.NoInput: case Persistence.FormQuestionType.CheckYourAnswers: return FormQuestionType.None; - case Persistence.FormQuestionType.FileUpload: - return FormQuestionType.FileUpload; + default: - return FormQuestionType.None; + throw new InvalidOperationException($"Unhandled FormQuestionType: {source.Type}"); } } }