Skip to content

Commit

Permalink
Merge pull request #1091 from cabinetoffice/feature/dp-1025-fix-data-…
Browse files Browse the repository at this point in the history
…sharing-answer-types

DP-1025 - Add missing data-sharing-api mapping for Multiline and GroupedSingleChoice field types
  • Loading branch information
andymantell authored Dec 20, 2024
2 parents add8bd5 + 405fe58 commit 03e9101
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
}
}
Expand Down

0 comments on commit 03e9101

Please sign in to comment.