From 181ef886136737c1f5fd3fb5b21fa287f7316e29 Mon Sep 17 00:00:00 2001 From: Dharm Date: Fri, 27 Sep 2024 21:18:00 +0100 Subject: [PATCH 1/6] Exclusions - Adding an exclusion - authority website --- .../Models/DynamicForms.cs | 3 +- .../Pages/Forms/FormElementFileUploadModel.cs | 5 - .../Pages/Forms/FormElementTextInputModel.cs | 5 - .../Pages/Forms/FormElementUrlInputModel.cs | 67 + .../Forms/FormsAnswerSetSummary.cshtml.cs | 5 +- .../Pages/Forms/FormsQuestionPage.cshtml | 9 +- .../Pages/Forms/FormsQuestionPage.cshtml.cs | 33 +- .../Pages/Forms/_FormElementUrlInput.cshtml | 88 + .../CO.CDP.Forms.WebApi/Model/FormQuestion.cs | 3 +- .../Forms/FormQuestion.cs | 3 +- ...91342_ExclusionWebsiteQuestion.Designer.cs | 1732 +++++++++++++++++ ...20240927191342_ExclusionWebsiteQuestion.cs | 59 + 12 files changed, 1980 insertions(+), 32 deletions(-) create mode 100644 Frontend/CO.CDP.OrganisationApp/Pages/Forms/FormElementUrlInputModel.cs create mode 100644 Frontend/CO.CDP.OrganisationApp/Pages/Forms/_FormElementUrlInput.cshtml create mode 100644 Services/CO.CDP.OrganisationInformation.Persistence/Migrations/20240927191342_ExclusionWebsiteQuestion.Designer.cs create mode 100644 Services/CO.CDP.OrganisationInformation.Persistence/Migrations/20240927191342_ExclusionWebsiteQuestion.cs diff --git a/Frontend/CO.CDP.OrganisationApp/Models/DynamicForms.cs b/Frontend/CO.CDP.OrganisationApp/Models/DynamicForms.cs index 0785731fe..27a6ed227 100644 --- a/Frontend/CO.CDP.OrganisationApp/Models/DynamicForms.cs +++ b/Frontend/CO.CDP.OrganisationApp/Models/DynamicForms.cs @@ -78,5 +78,6 @@ public enum FormQuestionType Date, CheckBox, Address, - MultiLine + MultiLine, + Url } \ No newline at end of file diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Forms/FormElementFileUploadModel.cs b/Frontend/CO.CDP.OrganisationApp/Pages/Forms/FormElementFileUploadModel.cs index 2222eb765..56a9e3409 100644 --- a/Frontend/CO.CDP.OrganisationApp/Pages/Forms/FormElementFileUploadModel.cs +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Forms/FormElementFileUploadModel.cs @@ -59,11 +59,6 @@ public override void SetAnswer(FormAnswer? answer) public IEnumerable Validate(ValidationContext validationContext) { - if (CurrentFormQuestionType != FormQuestionType.FileUpload) - { - yield break; - } - var validateField = IsRequired; if (IsRequired == false) diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Forms/FormElementTextInputModel.cs b/Frontend/CO.CDP.OrganisationApp/Pages/Forms/FormElementTextInputModel.cs index 56ccf9b42..6bbd08e76 100644 --- a/Frontend/CO.CDP.OrganisationApp/Pages/Forms/FormElementTextInputModel.cs +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Forms/FormElementTextInputModel.cs @@ -39,11 +39,6 @@ public override void SetAnswer(FormAnswer? answer) public IEnumerable Validate(ValidationContext validationContext) { - if (CurrentFormQuestionType != FormQuestionType.Text) - { - yield break; - } - var validateTextField = IsRequired; if (IsRequired == false) diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Forms/FormElementUrlInputModel.cs b/Frontend/CO.CDP.OrganisationApp/Pages/Forms/FormElementUrlInputModel.cs new file mode 100644 index 000000000..7c8e8d580 --- /dev/null +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Forms/FormElementUrlInputModel.cs @@ -0,0 +1,67 @@ +using CO.CDP.OrganisationApp.Models; +using Microsoft.AspNetCore.Mvc; +using System.ComponentModel.DataAnnotations; + +namespace CO.CDP.OrganisationApp.Pages.Forms; + +public class FormElementUrlInputModel : FormElementModel, IValidatableObject +{ + [BindProperty] + public string? TextInput { get; set; } + + [BindProperty] + public bool? HasValue { get; set; } + + + public override FormAnswer? GetAnswer() + { + if (IsRequired == false && HasValue == false) + { + return null; + } + + return string.IsNullOrWhiteSpace(TextInput) ? null : new FormAnswer { TextValue = TextInput }; + } + + public override void SetAnswer(FormAnswer? answer) + { + if (answer?.TextValue != null) + { + TextInput = answer.TextValue; + HasValue = true; + } + else if (RedirectFromCheckYourAnswerPage && IsRequired == false) + { + HasValue = false; + } + } + + public IEnumerable Validate(ValidationContext validationContext) + { + var validateTextField = IsRequired; + + if (IsRequired == false) + { + if (HasValue == null) + { + yield return new ValidationResult("Select an option", [nameof(HasValue)]); + } + else if (HasValue == true) + { + validateTextField = true; + } + } + + if (validateTextField) + { + if (string.IsNullOrWhiteSpace(TextInput)) + { + yield return new ValidationResult("Enter a website address", [nameof(TextInput)]); + } + else if (Uri.TryCreate(TextInput, UriKind.Absolute, out var _) == false) + { + yield return new ValidationResult("Enter a valid website address in the correct format", [nameof(TextInput)]); + } + } + } +} \ No newline at end of file diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Forms/FormsAnswerSetSummary.cshtml.cs b/Frontend/CO.CDP.OrganisationApp/Pages/Forms/FormsAnswerSetSummary.cshtml.cs index 378992c78..e94168885 100644 --- a/Frontend/CO.CDP.OrganisationApp/Pages/Forms/FormsAnswerSetSummary.cshtml.cs +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Forms/FormsAnswerSetSummary.cshtml.cs @@ -181,12 +181,13 @@ private async Task InitAndVerifyPage() { FormQuestionType.Text => answer.TextValue ?? "", FormQuestionType.FileUpload => answer.TextValue ?? "", - FormQuestionType.YesOrNo => answer.BoolValue.HasValue ? (answer.BoolValue == true ? "yes" : "no") : "", + FormQuestionType.YesOrNo => answer.BoolValue.HasValue ? (answer.BoolValue == true ? "Yes" : "No") : "", + FormQuestionType.SingleChoice => answer.OptionValue ?? "", FormQuestionType.Date => answer.DateValue.HasValue ? answer.DateValue.Value.ToString("dd/MM/yyyy") : "", FormQuestionType.CheckBox => answer.BoolValue.HasValue ? question.Options.Choices?.FirstOrDefault()?.Title ?? "" : "", FormQuestionType.Address => answer.AddressValue != null ? $"{answer.AddressValue.StreetAddress}, {answer.AddressValue.Locality}, {answer.AddressValue.PostalCode}, {answer.AddressValue.CountryName}" : "", - FormQuestionType.SingleChoice => answer.OptionValue ?? "", FormQuestionType.MultiLine => answer.TextValue ?? "", + FormQuestionType.Url => answer.TextValue ?? "", _ => "" }; diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Forms/FormsQuestionPage.cshtml b/Frontend/CO.CDP.OrganisationApp/Pages/Forms/FormsQuestionPage.cshtml index fc135b5ad..58627224d 100644 --- a/Frontend/CO.CDP.OrganisationApp/Pages/Forms/FormsQuestionPage.cshtml +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Forms/FormsQuestionPage.cshtml @@ -3,6 +3,7 @@ @model FormsQuestionPageModel @{ + var isCheckYourAnswersPage = Model.CurrentFormQuestionType == Models.FormQuestionType.CheckYourAnswers; var backUrl = $"/organisation/{Model.OrganisationId}/supplier-information"; var fromCheckAnswerPage = Model.RedirectFromCheckYourAnswerPage == true; @@ -28,7 +29,7 @@
-
+
@@ -38,7 +39,7 @@ @await Html.PartialAsync(Model.PartialViewName, Model.PartialViewModel) } - @if (Model.CurrentFormQuestionType == Models.FormQuestionType.CheckYourAnswers) + @if (isCheckYourAnswersPage) { var answers = await Model.GetAnswers(); @@ -65,7 +66,9 @@ } - @if (Model.CurrentFormQuestionType == Models.FormQuestionType.CheckYourAnswers) + + + @if (isCheckYourAnswersPage) { if (Model.FormSectionType == Models.FormSectionType.Declaration) { diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Forms/FormsQuestionPage.cshtml.cs b/Frontend/CO.CDP.OrganisationApp/Pages/Forms/FormsQuestionPage.cshtml.cs index 49112d6c2..eadc6b360 100644 --- a/Frontend/CO.CDP.OrganisationApp/Pages/Forms/FormsQuestionPage.cshtml.cs +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Forms/FormsQuestionPage.cshtml.cs @@ -29,24 +29,26 @@ public class FormsQuestionPageModel( [BindProperty(SupportsGet = true, Name = "frm-chk-answer")] public bool? RedirectFromCheckYourAnswerPage { get; set; } - [BindProperty] - public FormElementDateInputModel? DateInputModel { get; set; } - [BindProperty] - public FormElementFileUploadModel? FileUploadModel { get; set; } [BindProperty] public FormElementNoInputModel? NoInputModel { get; set; } [BindProperty] public FormElementTextInputModel? TextInputModel { get; set; } [BindProperty] - public FormElementMultiLineInputModel? MultiLineInputModel { get; set; } + public FormElementFileUploadModel? FileUploadModel { get; set; } [BindProperty] public FormElementYesNoInputModel? YesNoInputModel { get; set; } [BindProperty] - public FormElementAddressModel? AddressModel { get; set; } - [BindProperty] public FormElementSingleChoiceModel? SingleChoiceModel { get; set; } [BindProperty] + public FormElementDateInputModel? DateInputModel { get; set; } + [BindProperty] public FormElementCheckBoxInputModel? CheckBoxModel { get; set; } + [BindProperty] + public FormElementAddressModel? AddressModel { get; set; } + [BindProperty] + public FormElementMultiLineInputModel? MultiLineInputModel { get; set; } + [BindProperty] + public FormElementUrlInputModel? UrlInputModel { get; set; } [BindProperty(SupportsGet = true)] public string? UkOrNonUk { get; set; } @@ -154,13 +156,14 @@ public async Task> GetAnswers() string answerString = question.Type switch { FormQuestionType.Text => answer.Answer?.TextValue ?? "", - FormQuestionType.MultiLine => answer.Answer?.TextValue ?? "", - FormQuestionType.CheckBox => answer.Answer?.BoolValue == true ? question.Options.Choices?.FirstOrDefault() ?? "" : "", FormQuestionType.FileUpload => answer.Answer?.TextValue ?? "", - FormQuestionType.YesOrNo => answer.Answer?.BoolValue.HasValue == true ? (answer.Answer.BoolValue == true ? "yes" : "no") : "", + FormQuestionType.YesOrNo => answer.Answer?.BoolValue.HasValue == true ? (answer.Answer.BoolValue == true ? "Yes" : "No") : "", + FormQuestionType.SingleChoice => answer.Answer?.OptionValue ?? "", FormQuestionType.Date => answer.Answer?.DateValue.HasValue == true ? answer.Answer.DateValue.Value.ToString("dd/MM/yyyy") : "", + FormQuestionType.CheckBox => answer.Answer?.BoolValue == true ? question.Options.Choices?.FirstOrDefault() ?? "" : "", FormQuestionType.Address => answer.Answer?.AddressValue != null ? answer.Answer.AddressValue.ToHtmlString() : "", - FormQuestionType.SingleChoice => answer.Answer?.OptionValue ?? "", + FormQuestionType.MultiLine => answer.Answer?.TextValue ?? "", + FormQuestionType.Url => answer.Answer?.TextValue ?? "", _ => "" }; @@ -223,14 +226,15 @@ public bool PreviousQuestionHasNonUKAddressAnswer() Dictionary formQuestionPartials = new(){ { FormQuestionType.NoInput, "_FormElementNoInput" }, - { FormQuestionType.YesOrNo, "_FormElementYesNoInput" }, + { FormQuestionType.Text, "_FormElementTextInput" }, { FormQuestionType.FileUpload, "_FormElementFileUpload" }, + { FormQuestionType.YesOrNo, "_FormElementYesNoInput" }, + { FormQuestionType.SingleChoice, "_FormElementSingleChoice" }, { FormQuestionType.Date, "_FormElementDateInput" }, - { FormQuestionType.Text, "_FormElementTextInput" }, { FormQuestionType.CheckBox, "_FormElementCheckBoxInput" }, { FormQuestionType.Address, "_FormElementAddress" }, { FormQuestionType.MultiLine, "_FormElementMultiLineInput" }, - { FormQuestionType.SingleChoice, "_FormElementSingleChoice" }, + { FormQuestionType.Url, "_FormElementUrlInput" }, }; if (formQuestionPartials.TryGetValue(question.Type, out var partialView)) @@ -257,6 +261,7 @@ public bool PreviousQuestionHasNonUKAddressAnswer() FormQuestionType.Address => AddressModel ?? new FormElementAddressModel(), FormQuestionType.SingleChoice => SingleChoiceModel ?? new FormElementSingleChoiceModel(), FormQuestionType.MultiLine => MultiLineInputModel ?? new FormElementMultiLineInputModel(), + FormQuestionType.Url => UrlInputModel ?? new FormElementUrlInputModel(), _ => throw new NotImplementedException($"Forms question: {question.Type} is not supported"), }; diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Forms/_FormElementUrlInput.cshtml b/Frontend/CO.CDP.OrganisationApp/Pages/Forms/_FormElementUrlInput.cshtml new file mode 100644 index 000000000..5e802fd0f --- /dev/null +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Forms/_FormElementUrlInput.cshtml @@ -0,0 +1,88 @@ +@model FormElementUrlInputModel + +@{ + var textInputHasError = ((TagBuilder)Html.ValidationMessageFor(m => m.TextInput)).HasInnerHtml; + var selectOptionHasError = ((TagBuilder)Html.ValidationMessageFor(m => m.HasValue)).HasInnerHtml; + string textInputAriaDescribedby = ""; + + void RenderField() + { + if (textInputHasError) + { + textInputAriaDescribedby += " TextInput-error"; + +

+ Error: + @Html.ValidationMessageFor(m => m.TextInput) +

+ } + + + } +} + +
+ + @if (!string.IsNullOrWhiteSpace(Model.Heading)) + { +

+ + + @if (!string.IsNullOrWhiteSpace(Model.Caption)) + { + @Model.Caption + } +

+ } + + @if (!string.IsNullOrWhiteSpace(Model.Description)) + { + textInputAriaDescribedby += "TextInput-description"; + +
+ @Html.Raw(Model.Description) +
+ } + + @if (selectOptionHasError) + { +

+ Error: + @Html.ValidationMessageFor(m => m.HasValue) +

+ } + + @if (Model.IsRequired) + { + RenderField(); + } + else + { +
+
+ +
+ + +
+ +
+
+ @{ + RenderField(); + } +
+
+ +
+ + +
+
+
+
+ } +
\ No newline at end of file diff --git a/Services/CO.CDP.Forms.WebApi/Model/FormQuestion.cs b/Services/CO.CDP.Forms.WebApi/Model/FormQuestion.cs index 2295cdbaf..dd6e2f853 100644 --- a/Services/CO.CDP.Forms.WebApi/Model/FormQuestion.cs +++ b/Services/CO.CDP.Forms.WebApi/Model/FormQuestion.cs @@ -30,5 +30,6 @@ public enum FormQuestionType Date, CheckBox, Address, - MultiLine + MultiLine, + Url } \ No newline at end of file diff --git a/Services/CO.CDP.OrganisationInformation.Persistence/Forms/FormQuestion.cs b/Services/CO.CDP.OrganisationInformation.Persistence/Forms/FormQuestion.cs index f516f6656..52517fe97 100644 --- a/Services/CO.CDP.OrganisationInformation.Persistence/Forms/FormQuestion.cs +++ b/Services/CO.CDP.OrganisationInformation.Persistence/Forms/FormQuestion.cs @@ -35,7 +35,8 @@ public enum FormQuestionType Date, CheckBox, Address, - MultiLine + MultiLine, + Url } public record FormQuestionOptions diff --git a/Services/CO.CDP.OrganisationInformation.Persistence/Migrations/20240927191342_ExclusionWebsiteQuestion.Designer.cs b/Services/CO.CDP.OrganisationInformation.Persistence/Migrations/20240927191342_ExclusionWebsiteQuestion.Designer.cs new file mode 100644 index 000000000..37e9eb95c --- /dev/null +++ b/Services/CO.CDP.OrganisationInformation.Persistence/Migrations/20240927191342_ExclusionWebsiteQuestion.Designer.cs @@ -0,0 +1,1732 @@ +// +using System; +using System.Collections.Generic; +using CO.CDP.OrganisationInformation.Persistence; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace CO.CDP.OrganisationInformation.Persistence.Migrations +{ + [DbContext(typeof(OrganisationInformationContext))] + [Migration("20240927191342_ExclusionWebsiteQuestion")] + partial class ExclusionWebsiteQuestion + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "connected_entity_type", new[] { "organisation", "individual", "trust_or_trustee" }); + NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "connected_organisation_category", new[] { "registered_company", "director_or_the_same_responsibilities", "parent_or_subsidiary_company", "a_company_your_organisation_has_taken_over", "any_other_organisation_with_significant_influence_or_control" }); + NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "connected_person_category", new[] { "person_with_significant_control", "director_or_individual_with_the_same_responsibilities", "any_other_individual_with_significant_influence_or_control" }); + NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "connected_person_type", new[] { "individual", "trust_or_trustee" }); + NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "control_condition", new[] { "none", "owns_shares", "has_voting_rights", "can_appoint_or_remove_directors", "has_other_significant_influence_or_control" }); + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("CO.CDP.OrganisationInformation.Persistence.Address", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Country") + .IsRequired() + .HasColumnType("text") + .HasColumnName("country"); + + b.Property("CountryName") + .IsRequired() + .HasColumnType("text") + .HasColumnName("country_name"); + + b.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("created_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("Locality") + .IsRequired() + .HasColumnType("text") + .HasColumnName("locality"); + + b.Property("PostalCode") + .IsRequired() + .HasColumnType("text") + .HasColumnName("postal_code"); + + b.Property("Region") + .HasColumnType("text") + .HasColumnName("region"); + + b.Property("StreetAddress") + .IsRequired() + .HasColumnType("text") + .HasColumnName("street_address"); + + b.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("updated_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.HasKey("Id") + .HasName("pk_addresses"); + + b.ToTable("addresses", (string)null); + }); + + modelBuilder.Entity("CO.CDP.OrganisationInformation.Persistence.AuthenticationKey", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("created_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("Key") + .IsRequired() + .HasColumnType("text") + .HasColumnName("key"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text") + .HasColumnName("name"); + + b.Property("OrganisationId") + .HasColumnType("integer") + .HasColumnName("organisation_id"); + + b.Property("Revoked") + .HasColumnType("boolean") + .HasColumnName("revoked"); + + b.Property("RevokedOn") + .HasColumnType("timestamp with time zone") + .HasColumnName("revoked_on"); + + b.Property("Scopes") + .IsRequired() + .HasColumnType("jsonb") + .HasColumnName("scopes"); + + b.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("updated_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.HasKey("Id") + .HasName("pk_authentication_keys"); + + b.HasIndex("OrganisationId") + .HasDatabaseName("ix_authentication_keys_organisation_id"); + + b.HasIndex("Name", "OrganisationId") + .IsUnique() + .HasDatabaseName("ix_authentication_keys_name_organisation_id"); + + NpgsqlIndexBuilderExtensions.AreNullsDistinct(b.HasIndex("Name", "OrganisationId"), false); + + b.ToTable("authentication_keys", (string)null); + }); + + modelBuilder.Entity("CO.CDP.OrganisationInformation.Persistence.ConnectedEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CompanyHouseNumber") + .HasColumnType("text") + .HasColumnName("company_house_number"); + + b.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("created_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("EndDate") + .HasColumnType("timestamp with time zone") + .HasColumnName("end_date"); + + b.Property("EntityType") + .HasColumnType("integer") + .HasColumnName("entity_type"); + + b.Property("Guid") + .HasColumnType("uuid") + .HasColumnName("guid"); + + b.Property("HasCompnayHouseNumber") + .HasColumnType("boolean") + .HasColumnName("has_compnay_house_number"); + + b.Property("OverseasCompanyNumber") + .HasColumnType("text") + .HasColumnName("overseas_company_number"); + + b.Property("RegisterName") + .HasColumnType("text") + .HasColumnName("register_name"); + + b.Property("RegisteredDate") + .HasColumnType("timestamp with time zone") + .HasColumnName("registered_date"); + + b.Property("StartDate") + .HasColumnType("timestamp with time zone") + .HasColumnName("start_date"); + + b.Property("SupplierOrganisationId") + .HasColumnType("integer") + .HasColumnName("supplier_organisation_id"); + + b.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("updated_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.HasKey("Id") + .HasName("pk_connected_entities"); + + b.HasIndex("Guid") + .IsUnique() + .HasDatabaseName("ix_connected_entities_guid"); + + b.HasIndex("SupplierOrganisationId") + .HasDatabaseName("ix_connected_entities_supplier_organisation_id"); + + b.ToTable("connected_entities", (string)null); + }); + + modelBuilder.Entity("CO.CDP.OrganisationInformation.Persistence.Forms.Form", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("created_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("Guid") + .HasColumnType("uuid") + .HasColumnName("guid"); + + b.Property("IsRequired") + .HasColumnType("boolean") + .HasColumnName("is_required"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text") + .HasColumnName("name"); + + b.Property("Scope") + .HasColumnType("integer") + .HasColumnName("scope"); + + b.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("updated_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("Version") + .IsRequired() + .HasColumnType("text") + .HasColumnName("version"); + + b.HasKey("Id") + .HasName("pk_forms"); + + b.ToTable("forms", (string)null); + }); + + modelBuilder.Entity("CO.CDP.OrganisationInformation.Persistence.Forms.FormAnswer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AddressValue") + .HasColumnType("jsonb") + .HasColumnName("address_value"); + + b.Property("BoolValue") + .HasColumnType("boolean") + .HasColumnName("bool_value"); + + b.Property("CreatedFrom") + .HasColumnType("uuid") + .HasColumnName("created_from"); + + b.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("created_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("DateValue") + .HasColumnType("timestamp with time zone") + .HasColumnName("date_value"); + + b.Property("EndValue") + .HasColumnType("timestamp with time zone") + .HasColumnName("end_value"); + + b.Property("FormAnswerSetId") + .HasColumnType("integer") + .HasColumnName("form_answer_set_id"); + + b.Property("Guid") + .HasColumnType("uuid") + .HasColumnName("guid"); + + b.Property("NumericValue") + .HasColumnType("double precision") + .HasColumnName("numeric_value"); + + b.Property("OptionValue") + .HasColumnType("text") + .HasColumnName("option_value"); + + b.Property("QuestionId") + .HasColumnType("integer") + .HasColumnName("question_id"); + + b.Property("StartValue") + .HasColumnType("timestamp with time zone") + .HasColumnName("start_value"); + + b.Property("TextValue") + .HasColumnType("text") + .HasColumnName("text_value"); + + b.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("updated_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.HasKey("Id") + .HasName("pk_form_answers"); + + b.HasIndex("FormAnswerSetId") + .HasDatabaseName("ix_form_answers_form_answer_set_id"); + + b.HasIndex("QuestionId") + .HasDatabaseName("ix_form_answers_question_id"); + + b.ToTable("form_answers", (string)null); + }); + + modelBuilder.Entity("CO.CDP.OrganisationInformation.Persistence.Forms.FormAnswerSet", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedFrom") + .HasColumnType("uuid") + .HasColumnName("created_from"); + + b.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("created_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("Deleted") + .ValueGeneratedOnAdd() + .HasColumnType("boolean") + .HasDefaultValue(false) + .HasColumnName("deleted"); + + b.Property("FurtherQuestionsExempted") + .HasColumnType("boolean") + .HasColumnName("further_questions_exempted"); + + b.Property("Guid") + .HasColumnType("uuid") + .HasColumnName("guid"); + + b.Property("SectionId") + .HasColumnType("integer") + .HasColumnName("section_id"); + + b.Property("SharedConsentId") + .HasColumnType("integer") + .HasColumnName("shared_consent_id"); + + b.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("updated_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.HasKey("Id") + .HasName("pk_form_answer_sets"); + + b.HasIndex("SectionId") + .HasDatabaseName("ix_form_answer_sets_section_id"); + + b.HasIndex("SharedConsentId") + .HasDatabaseName("ix_form_answer_sets_shared_consent_id"); + + b.ToTable("form_answer_sets", (string)null); + }); + + modelBuilder.Entity("CO.CDP.OrganisationInformation.Persistence.Forms.FormQuestion", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Caption") + .HasColumnType("text") + .HasColumnName("caption"); + + b.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("created_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("Description") + .HasColumnType("text") + .HasColumnName("description"); + + b.Property("Guid") + .HasColumnType("uuid") + .HasColumnName("guid"); + + b.Property("IsRequired") + .HasColumnType("boolean") + .HasColumnName("is_required"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text") + .HasColumnName("name"); + + b.Property("NextQuestionAlternativeId") + .HasColumnType("integer") + .HasColumnName("next_question_alternative_id"); + + b.Property("NextQuestionId") + .HasColumnType("integer") + .HasColumnName("next_question_id"); + + b.Property("Options") + .IsRequired() + .HasColumnType("jsonb") + .HasColumnName("options"); + + b.Property("SectionId") + .HasColumnType("integer") + .HasColumnName("section_id"); + + b.Property("SummaryTitle") + .HasColumnType("text") + .HasColumnName("summary_title"); + + b.Property("Title") + .IsRequired() + .HasColumnType("text") + .HasColumnName("title"); + + b.Property("Type") + .HasColumnType("integer") + .HasColumnName("type"); + + b.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("updated_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.HasKey("Id") + .HasName("pk_form_questions"); + + b.HasIndex("Name") + .IsUnique() + .HasDatabaseName("ix_form_questions_name"); + + b.HasIndex("NextQuestionAlternativeId") + .HasDatabaseName("ix_form_questions_next_question_alternative_id"); + + b.HasIndex("NextQuestionId") + .HasDatabaseName("ix_form_questions_next_question_id"); + + b.HasIndex("SectionId") + .HasDatabaseName("ix_form_questions_section_id"); + + b.ToTable("form_questions", (string)null); + }); + + modelBuilder.Entity("CO.CDP.OrganisationInformation.Persistence.Forms.FormSection", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AllowsMultipleAnswerSets") + .HasColumnType("boolean") + .HasColumnName("allows_multiple_answer_sets"); + + b.Property("CheckFurtherQuestionsExempted") + .HasColumnType("boolean") + .HasColumnName("check_further_questions_exempted"); + + b.Property("Configuration") + .IsRequired() + .HasColumnType("jsonb") + .HasColumnName("configuration"); + + b.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("created_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("DisplayOrder") + .HasColumnType("integer") + .HasColumnName("display_order"); + + b.Property("FormId") + .HasColumnType("integer") + .HasColumnName("form_id"); + + b.Property("Guid") + .HasColumnType("uuid") + .HasColumnName("guid"); + + b.Property("Title") + .IsRequired() + .HasColumnType("text") + .HasColumnName("title"); + + b.Property("Type") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasDefaultValue(0) + .HasColumnName("type"); + + b.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("updated_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.HasKey("Id") + .HasName("pk_form_sections"); + + b.HasIndex("FormId") + .HasDatabaseName("ix_form_sections_form_id"); + + b.ToTable("form_sections", (string)null); + }); + + modelBuilder.Entity("CO.CDP.OrganisationInformation.Persistence.Forms.SharedConsent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedFrom") + .HasColumnType("uuid") + .HasColumnName("created_from"); + + b.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("created_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("FormId") + .HasColumnType("integer") + .HasColumnName("form_id"); + + b.Property("FormVersionId") + .IsRequired() + .HasColumnType("text") + .HasColumnName("form_version_id"); + + b.Property("Guid") + .HasColumnType("uuid") + .HasColumnName("guid"); + + b.Property("OrganisationId") + .HasColumnType("integer") + .HasColumnName("organisation_id"); + + b.Property("ShareCode") + .HasColumnType("text") + .HasColumnName("share_code"); + + b.Property("SubmissionState") + .HasColumnType("integer") + .HasColumnName("submission_state"); + + b.Property("SubmittedAt") + .HasColumnType("timestamp with time zone") + .HasColumnName("submitted_at"); + + b.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("updated_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.HasKey("Id") + .HasName("pk_shared_consents"); + + b.HasIndex("FormId") + .HasDatabaseName("ix_shared_consents_form_id"); + + b.HasIndex("OrganisationId") + .HasDatabaseName("ix_shared_consents_organisation_id"); + + b.ToTable("shared_consents", (string)null); + }); + + modelBuilder.Entity("CO.CDP.OrganisationInformation.Persistence.Organisation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ApprovedOn") + .HasColumnType("timestamp with time zone") + .HasColumnName("approved_on"); + + b.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("created_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("Guid") + .HasColumnType("uuid") + .HasColumnName("guid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text") + .HasColumnName("name"); + + b.Property("ReviewComment") + .HasMaxLength(10000) + .HasColumnType("character varying(10000)") + .HasColumnName("review_comment"); + + b.Property("ReviewedById") + .HasColumnType("integer") + .HasColumnName("reviewed_by_id"); + + b.Property("Roles") + .IsRequired() + .HasColumnType("integer[]") + .HasColumnName("roles"); + + b.Property("TenantId") + .HasColumnType("integer") + .HasColumnName("tenant_id"); + + b.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("updated_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.HasKey("Id") + .HasName("pk_organisations"); + + b.HasIndex("Guid") + .IsUnique() + .HasDatabaseName("ix_organisations_guid"); + + b.HasIndex("Name") + .IsUnique() + .HasDatabaseName("ix_organisations_name"); + + b.HasIndex("ReviewedById") + .HasDatabaseName("ix_organisations_reviewed_by_id"); + + b.HasIndex("TenantId") + .HasDatabaseName("ix_organisations_tenant_id"); + + b.ToTable("organisations", (string)null); + }); + + modelBuilder.Entity("CO.CDP.OrganisationInformation.Persistence.OrganisationPerson", b => + { + b.Property("OrganisationId") + .HasColumnType("integer") + .HasColumnName("organisation_id"); + + b.Property("PersonId") + .HasColumnType("integer") + .HasColumnName("person_id"); + + b.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("created_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("Scopes") + .IsRequired() + .HasColumnType("jsonb") + .HasColumnName("scopes"); + + b.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("updated_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.HasKey("OrganisationId", "PersonId") + .HasName("pk_organisation_person"); + + b.HasIndex("PersonId") + .HasDatabaseName("ix_organisation_person_person_id"); + + b.ToTable("organisation_person", (string)null); + }); + + modelBuilder.Entity("CO.CDP.OrganisationInformation.Persistence.Person", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("created_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text") + .HasColumnName("email"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text") + .HasColumnName("first_name"); + + b.Property("Guid") + .HasColumnType("uuid") + .HasColumnName("guid"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("text") + .HasColumnName("last_name"); + + b.Property("Phone") + .HasColumnType("text") + .HasColumnName("phone"); + + b.Property>("Scopes") + .IsRequired() + .HasColumnType("text[]") + .HasColumnName("scopes"); + + b.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("updated_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("UserUrn") + .HasColumnType("text") + .HasColumnName("user_urn"); + + b.HasKey("Id") + .HasName("pk_persons"); + + b.HasIndex("Email") + .IsUnique() + .HasDatabaseName("ix_persons_email"); + + b.HasIndex("Guid") + .IsUnique() + .HasDatabaseName("ix_persons_guid"); + + b.ToTable("persons", (string)null); + }); + + modelBuilder.Entity("CO.CDP.OrganisationInformation.Persistence.PersonInvite", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("created_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text") + .HasColumnName("email"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text") + .HasColumnName("first_name"); + + b.Property("Guid") + .HasColumnType("uuid") + .HasColumnName("guid"); + + b.Property("InviteSentOn") + .HasColumnType("timestamp with time zone") + .HasColumnName("invite_sent_on"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("text") + .HasColumnName("last_name"); + + b.Property("OrganisationId") + .HasColumnType("integer") + .HasColumnName("organisation_id"); + + b.Property("PersonId") + .HasColumnType("integer") + .HasColumnName("person_id"); + + b.Property>("Scopes") + .IsRequired() + .HasColumnType("text[]") + .HasColumnName("scopes"); + + b.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("updated_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.HasKey("Id") + .HasName("pk_person_invites"); + + b.HasIndex("Guid") + .IsUnique() + .HasDatabaseName("ix_person_invites_guid"); + + b.HasIndex("OrganisationId") + .HasDatabaseName("ix_person_invites_organisation_id"); + + b.HasIndex("PersonId") + .HasDatabaseName("ix_person_invites_person_id"); + + b.ToTable("person_invites", (string)null); + }); + + modelBuilder.Entity("CO.CDP.OrganisationInformation.Persistence.RefreshToken", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("created_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("ExpiryDate") + .HasColumnType("timestamp with time zone") + .HasColumnName("expiry_date"); + + b.Property("Revoked") + .HasColumnType("boolean") + .HasColumnName("revoked"); + + b.Property("TokenHash") + .IsRequired() + .HasColumnType("text") + .HasColumnName("token_hash"); + + b.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("updated_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.HasKey("Id") + .HasName("pk_refresh_tokens"); + + b.HasIndex("TokenHash") + .IsUnique() + .HasDatabaseName("ix_refresh_tokens_token_hash"); + + b.ToTable("refresh_tokens", (string)null); + }); + + modelBuilder.Entity("CO.CDP.OrganisationInformation.Persistence.Tenant", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("created_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("Guid") + .HasColumnType("uuid") + .HasColumnName("guid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text") + .HasColumnName("name"); + + b.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("updated_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.HasKey("Id") + .HasName("pk_tenants"); + + b.HasIndex("Guid") + .IsUnique() + .HasDatabaseName("ix_tenants_guid"); + + b.HasIndex("Name") + .IsUnique() + .HasDatabaseName("ix_tenants_name"); + + b.ToTable("tenants", (string)null); + }); + + modelBuilder.Entity("CO.CDP.OrganisationInformation.Persistence.TenantPerson", b => + { + b.Property("PersonId") + .HasColumnType("integer") + .HasColumnName("person_id"); + + b.Property("TenantId") + .HasColumnType("integer") + .HasColumnName("tenant_id"); + + b.HasKey("PersonId", "TenantId") + .HasName("pk_tenant_person"); + + b.HasIndex("TenantId") + .HasDatabaseName("ix_tenant_person_tenant_id"); + + b.ToTable("tenant_person", (string)null); + }); + + modelBuilder.Entity("CO.CDP.OrganisationInformation.Persistence.AuthenticationKey", b => + { + b.HasOne("CO.CDP.OrganisationInformation.Persistence.Organisation", "Organisation") + .WithMany() + .HasForeignKey("OrganisationId") + .HasConstraintName("fk_authentication_keys_organisations_organisation_id"); + + b.Navigation("Organisation"); + }); + + modelBuilder.Entity("CO.CDP.OrganisationInformation.Persistence.ConnectedEntity", b => + { + b.HasOne("CO.CDP.OrganisationInformation.Persistence.Organisation", "SupplierOrganisation") + .WithMany() + .HasForeignKey("SupplierOrganisationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("fk_connected_entities_organisations_supplier_organisation_id"); + + b.OwnsMany("CO.CDP.OrganisationInformation.Persistence.ConnectedEntity+ConnectedEntityAddress", "Addresses", b1 => + { + b1.Property("ConnectedEntityId") + .HasColumnType("integer") + .HasColumnName("connected_entity_id"); + + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b1.Property("Id")); + + b1.Property("AddressId") + .HasColumnType("integer") + .HasColumnName("address_id"); + + b1.Property("Type") + .HasColumnType("integer") + .HasColumnName("type"); + + b1.HasKey("ConnectedEntityId", "Id") + .HasName("pk_connected_entity_address"); + + b1.HasIndex("AddressId") + .HasDatabaseName("ix_connected_entity_address_address_id"); + + b1.ToTable("connected_entity_address", (string)null); + + b1.HasOne("CO.CDP.OrganisationInformation.Persistence.Address", "Address") + .WithMany() + .HasForeignKey("AddressId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("fk_connected_entity_address_address_address_id"); + + b1.WithOwner() + .HasForeignKey("ConnectedEntityId") + .HasConstraintName("fk_connected_entity_address_connected_entities_connected_entit"); + + b1.Navigation("Address"); + }); + + b.OwnsOne("CO.CDP.OrganisationInformation.Persistence.ConnectedEntity+ConnectedIndividualTrust", "IndividualOrTrust", b1 => + { + b1.Property("Id") + .HasColumnType("integer") + .HasColumnName("connected_individual_trust_id"); + + b1.Property("Category") + .HasColumnType("integer") + .HasColumnName("category"); + + b1.Property("ConnectedType") + .HasColumnType("integer") + .HasColumnName("connected_type"); + + b1.Property("ControlCondition") + .IsRequired() + .HasColumnType("integer[]") + .HasColumnName("control_condition"); + + b1.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("created_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b1.Property("DateOfBirth") + .HasColumnType("timestamp with time zone") + .HasColumnName("date_of_birth"); + + b1.Property("FirstName") + .IsRequired() + .HasColumnType("text") + .HasColumnName("first_name"); + + b1.Property("LastName") + .IsRequired() + .HasColumnType("text") + .HasColumnName("last_name"); + + b1.Property("Nationality") + .HasColumnType("text") + .HasColumnName("nationality"); + + b1.Property("PersonId") + .HasColumnType("uuid") + .HasColumnName("person_id"); + + b1.Property("ResidentCountry") + .HasColumnType("text") + .HasColumnName("resident_country"); + + b1.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("updated_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b1.HasKey("Id") + .HasName("pk_connected_individual_trust"); + + b1.ToTable("connected_individual_trust", (string)null); + + b1.WithOwner() + .HasForeignKey("Id") + .HasConstraintName("fk_connected_individual_trust_connected_entities_connected_ind"); + }); + + b.OwnsOne("CO.CDP.OrganisationInformation.Persistence.ConnectedEntity+ConnectedOrganisation", "Organisation", b1 => + { + b1.Property("Id") + .HasColumnType("integer") + .HasColumnName("connected_organisation_id"); + + b1.Property("Category") + .HasColumnType("integer") + .HasColumnName("category"); + + b1.Property("ControlCondition") + .IsRequired() + .HasColumnType("integer[]") + .HasColumnName("control_condition"); + + b1.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("created_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b1.Property("InsolvencyDate") + .HasColumnType("timestamp with time zone") + .HasColumnName("insolvency_date"); + + b1.Property("LawRegistered") + .HasColumnType("text") + .HasColumnName("law_registered"); + + b1.Property("Name") + .IsRequired() + .HasColumnType("text") + .HasColumnName("name"); + + b1.Property("OrganisationId") + .HasColumnType("uuid") + .HasColumnName("organisation_id"); + + b1.Property("RegisteredLegalForm") + .HasColumnType("text") + .HasColumnName("registered_legal_form"); + + b1.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("updated_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b1.HasKey("Id") + .HasName("pk_connected_organisation"); + + b1.ToTable("connected_organisation", (string)null); + + b1.WithOwner() + .HasForeignKey("Id") + .HasConstraintName("fk_connected_organisation_connected_entities_connected_organis"); + }); + + b.Navigation("Addresses"); + + b.Navigation("IndividualOrTrust"); + + b.Navigation("Organisation"); + + b.Navigation("SupplierOrganisation"); + }); + + modelBuilder.Entity("CO.CDP.OrganisationInformation.Persistence.Forms.FormAnswer", b => + { + b.HasOne("CO.CDP.OrganisationInformation.Persistence.Forms.FormAnswerSet", "FormAnswerSet") + .WithMany("Answers") + .HasForeignKey("FormAnswerSetId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("fk_form_answers_form_answer_sets_form_answer_set_id"); + + b.HasOne("CO.CDP.OrganisationInformation.Persistence.Forms.FormQuestion", "Question") + .WithMany() + .HasForeignKey("QuestionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("fk_form_answers_form_questions_question_id"); + + b.Navigation("FormAnswerSet"); + + b.Navigation("Question"); + }); + + modelBuilder.Entity("CO.CDP.OrganisationInformation.Persistence.Forms.FormAnswerSet", b => + { + b.HasOne("CO.CDP.OrganisationInformation.Persistence.Forms.FormSection", "Section") + .WithMany() + .HasForeignKey("SectionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("fk_form_answer_sets_form_section_section_id"); + + b.HasOne("CO.CDP.OrganisationInformation.Persistence.Forms.SharedConsent", "SharedConsent") + .WithMany("AnswerSets") + .HasForeignKey("SharedConsentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("fk_form_answer_sets_shared_consents_shared_consent_id"); + + b.Navigation("Section"); + + b.Navigation("SharedConsent"); + }); + + modelBuilder.Entity("CO.CDP.OrganisationInformation.Persistence.Forms.FormQuestion", b => + { + b.HasOne("CO.CDP.OrganisationInformation.Persistence.Forms.FormQuestion", "NextQuestionAlternative") + .WithMany() + .HasForeignKey("NextQuestionAlternativeId") + .HasConstraintName("fk_form_questions_form_questions_next_question_alternative_id"); + + b.HasOne("CO.CDP.OrganisationInformation.Persistence.Forms.FormQuestion", "NextQuestion") + .WithMany() + .HasForeignKey("NextQuestionId") + .HasConstraintName("fk_form_questions_form_questions_next_question_id"); + + b.HasOne("CO.CDP.OrganisationInformation.Persistence.Forms.FormSection", "Section") + .WithMany("Questions") + .HasForeignKey("SectionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("fk_form_questions_form_sections_section_id"); + + b.Navigation("NextQuestion"); + + b.Navigation("NextQuestionAlternative"); + + b.Navigation("Section"); + }); + + modelBuilder.Entity("CO.CDP.OrganisationInformation.Persistence.Forms.FormSection", b => + { + b.HasOne("CO.CDP.OrganisationInformation.Persistence.Forms.Form", "Form") + .WithMany("Sections") + .HasForeignKey("FormId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("fk_form_sections_forms_form_id"); + + b.Navigation("Form"); + }); + + modelBuilder.Entity("CO.CDP.OrganisationInformation.Persistence.Forms.SharedConsent", b => + { + b.HasOne("CO.CDP.OrganisationInformation.Persistence.Forms.Form", "Form") + .WithMany() + .HasForeignKey("FormId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("fk_shared_consents_forms_form_id"); + + b.HasOne("CO.CDP.OrganisationInformation.Persistence.Organisation", "Organisation") + .WithMany() + .HasForeignKey("OrganisationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("fk_shared_consents_organisations_organisation_id"); + + b.Navigation("Form"); + + b.Navigation("Organisation"); + }); + + modelBuilder.Entity("CO.CDP.OrganisationInformation.Persistence.Organisation", b => + { + b.HasOne("CO.CDP.OrganisationInformation.Persistence.Person", "ReviewedBy") + .WithMany() + .HasForeignKey("ReviewedById") + .HasConstraintName("fk_organisations_persons_reviewed_by_id"); + + b.HasOne("CO.CDP.OrganisationInformation.Persistence.Tenant", "Tenant") + .WithMany("Organisations") + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("fk_organisations_tenants_tenant_id"); + + b.OwnsOne("CO.CDP.OrganisationInformation.Persistence.Organisation+BuyerInformation", "BuyerInfo", b1 => + { + b1.Property("OrganisationId") + .HasColumnType("integer") + .HasColumnName("id"); + + b1.Property("BuyerType") + .HasColumnType("text") + .HasColumnName("buyer_type"); + + b1.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("created_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b1.Property("DevolvedRegulations") + .IsRequired() + .HasColumnType("integer[]") + .HasColumnName("devolved_regulations"); + + b1.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("updated_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b1.HasKey("OrganisationId") + .HasName("pk_buyer_information"); + + b1.ToTable("buyer_information", (string)null); + + b1.WithOwner() + .HasForeignKey("OrganisationId") + .HasConstraintName("fk_buyer_information_organisations_id"); + }); + + b.OwnsMany("CO.CDP.OrganisationInformation.Persistence.Organisation+ContactPoint", "ContactPoints", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b1.Property("Id")); + + b1.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("created_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b1.Property("Email") + .HasColumnType("text") + .HasColumnName("email"); + + b1.Property("Name") + .HasColumnType("text") + .HasColumnName("name"); + + b1.Property("OrganisationId") + .HasColumnType("integer") + .HasColumnName("organisation_id"); + + b1.Property("Telephone") + .HasColumnType("text") + .HasColumnName("telephone"); + + b1.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("updated_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b1.Property("Url") + .HasColumnType("text") + .HasColumnName("url"); + + b1.HasKey("Id") + .HasName("pk_contact_points"); + + b1.HasIndex("OrganisationId") + .HasDatabaseName("ix_contact_points_organisation_id"); + + b1.ToTable("contact_points", (string)null); + + b1.WithOwner() + .HasForeignKey("OrganisationId") + .HasConstraintName("fk_contact_points_organisations_organisation_id"); + }); + + b.OwnsMany("CO.CDP.OrganisationInformation.Persistence.Organisation+Identifier", "Identifiers", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b1.Property("Id")); + + b1.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("created_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b1.Property("IdentifierId") + .HasColumnType("text") + .HasColumnName("identifier_id"); + + b1.Property("LegalName") + .IsRequired() + .HasColumnType("text") + .HasColumnName("legal_name"); + + b1.Property("OrganisationId") + .HasColumnType("integer") + .HasColumnName("organisation_id"); + + b1.Property("Primary") + .HasColumnType("boolean") + .HasColumnName("primary"); + + b1.Property("Scheme") + .IsRequired() + .HasColumnType("text") + .HasColumnName("scheme"); + + b1.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("updated_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b1.Property("Uri") + .HasColumnType("text") + .HasColumnName("uri"); + + b1.HasKey("Id") + .HasName("pk_identifiers"); + + b1.HasIndex("OrganisationId") + .HasDatabaseName("ix_identifiers_organisation_id"); + + b1.HasIndex("IdentifierId", "Scheme") + .IsUnique() + .HasDatabaseName("ix_identifiers_identifier_id_scheme"); + + b1.ToTable("identifiers", (string)null); + + b1.WithOwner() + .HasForeignKey("OrganisationId") + .HasConstraintName("fk_identifiers_organisations_organisation_id"); + }); + + b.OwnsMany("CO.CDP.OrganisationInformation.Persistence.Organisation+OrganisationAddress", "Addresses", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b1.Property("Id")); + + b1.Property("AddressId") + .HasColumnType("integer") + .HasColumnName("address_id"); + + b1.Property("OrganisationId") + .HasColumnType("integer") + .HasColumnName("organisation_id"); + + b1.Property("Type") + .HasColumnType("integer") + .HasColumnName("type"); + + b1.HasKey("Id") + .HasName("pk_organisation_address"); + + b1.HasIndex("AddressId") + .HasDatabaseName("ix_organisation_address_address_id"); + + b1.HasIndex("OrganisationId") + .HasDatabaseName("ix_organisation_address_organisation_id"); + + b1.ToTable("organisation_address", (string)null); + + b1.HasOne("CO.CDP.OrganisationInformation.Persistence.Address", "Address") + .WithMany() + .HasForeignKey("AddressId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("fk_organisation_address_address_address_id"); + + b1.WithOwner() + .HasForeignKey("OrganisationId") + .HasConstraintName("fk_organisation_address_organisations_organisation_id"); + + b1.Navigation("Address"); + }); + + b.OwnsOne("CO.CDP.OrganisationInformation.Persistence.Organisation+SupplierInformation", "SupplierInfo", b1 => + { + b1.Property("OrganisationId") + .HasColumnType("integer") + .HasColumnName("id"); + + b1.Property("CompletedConnectedPerson") + .HasColumnType("boolean") + .HasColumnName("completed_connected_person"); + + b1.Property("CompletedEmailAddress") + .HasColumnType("boolean") + .HasColumnName("completed_email_address"); + + b1.Property("CompletedLegalForm") + .HasColumnType("boolean") + .HasColumnName("completed_legal_form"); + + b1.Property("CompletedOperationType") + .HasColumnType("boolean") + .HasColumnName("completed_operation_type"); + + b1.Property("CompletedPostalAddress") + .HasColumnType("boolean") + .HasColumnName("completed_postal_address"); + + b1.Property("CompletedRegAddress") + .HasColumnType("boolean") + .HasColumnName("completed_reg_address"); + + b1.Property("CompletedVat") + .HasColumnType("boolean") + .HasColumnName("completed_vat"); + + b1.Property("CompletedWebsiteAddress") + .HasColumnType("boolean") + .HasColumnName("completed_website_address"); + + b1.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("created_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b1.Property("OperationTypes") + .IsRequired() + .HasColumnType("integer[]") + .HasColumnName("operation_types"); + + b1.Property("SupplierType") + .HasColumnType("integer") + .HasColumnName("supplier_type"); + + b1.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("updated_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b1.HasKey("OrganisationId") + .HasName("pk_supplier_information"); + + b1.ToTable("supplier_information", (string)null); + + b1.WithOwner() + .HasForeignKey("OrganisationId") + .HasConstraintName("fk_supplier_information_organisations_id"); + + b1.OwnsOne("CO.CDP.OrganisationInformation.Persistence.Organisation+LegalForm", "LegalForm", b2 => + { + b2.Property("SupplierInformationOrganisationId") + .HasColumnType("integer") + .HasColumnName("id"); + + b2.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("created_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b2.Property("LawRegistered") + .IsRequired() + .HasColumnType("text") + .HasColumnName("law_registered"); + + b2.Property("RegisteredLegalForm") + .IsRequired() + .HasColumnType("text") + .HasColumnName("registered_legal_form"); + + b2.Property("RegisteredUnderAct2006") + .HasColumnType("boolean") + .HasColumnName("registered_under_act2006"); + + b2.Property("RegistrationDate") + .HasColumnType("timestamp with time zone") + .HasColumnName("registration_date"); + + b2.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasColumnName("updated_on") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b2.HasKey("SupplierInformationOrganisationId") + .HasName("pk_legal_forms"); + + b2.ToTable("legal_forms", (string)null); + + b2.WithOwner() + .HasForeignKey("SupplierInformationOrganisationId") + .HasConstraintName("fk_legal_forms_supplier_information_id"); + }); + + b1.Navigation("LegalForm"); + }); + + b.Navigation("Addresses"); + + b.Navigation("BuyerInfo"); + + b.Navigation("ContactPoints"); + + b.Navigation("Identifiers"); + + b.Navigation("ReviewedBy"); + + b.Navigation("SupplierInfo"); + + b.Navigation("Tenant"); + }); + + modelBuilder.Entity("CO.CDP.OrganisationInformation.Persistence.OrganisationPerson", b => + { + b.HasOne("CO.CDP.OrganisationInformation.Persistence.Organisation", "Organisation") + .WithMany("OrganisationPersons") + .HasForeignKey("OrganisationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("fk_organisation_person_organisations_organisation_id"); + + b.HasOne("CO.CDP.OrganisationInformation.Persistence.Person", "Person") + .WithMany("PersonOrganisations") + .HasForeignKey("PersonId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("fk_organisation_person_persons_person_id"); + + b.Navigation("Organisation"); + + b.Navigation("Person"); + }); + + modelBuilder.Entity("CO.CDP.OrganisationInformation.Persistence.PersonInvite", b => + { + b.HasOne("CO.CDP.OrganisationInformation.Persistence.Organisation", "Organisation") + .WithMany() + .HasForeignKey("OrganisationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("fk_person_invites_organisations_organisation_id"); + + b.HasOne("CO.CDP.OrganisationInformation.Persistence.Person", "Person") + .WithMany() + .HasForeignKey("PersonId") + .HasConstraintName("fk_person_invites_persons_person_id"); + + b.Navigation("Organisation"); + + b.Navigation("Person"); + }); + + modelBuilder.Entity("CO.CDP.OrganisationInformation.Persistence.TenantPerson", b => + { + b.HasOne("CO.CDP.OrganisationInformation.Persistence.Person", null) + .WithMany() + .HasForeignKey("PersonId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("fk_tenant_person_persons_person_id"); + + b.HasOne("CO.CDP.OrganisationInformation.Persistence.Tenant", null) + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("fk_tenant_person_tenants_tenant_id"); + }); + + modelBuilder.Entity("CO.CDP.OrganisationInformation.Persistence.Forms.Form", b => + { + b.Navigation("Sections"); + }); + + modelBuilder.Entity("CO.CDP.OrganisationInformation.Persistence.Forms.FormAnswerSet", b => + { + b.Navigation("Answers"); + }); + + modelBuilder.Entity("CO.CDP.OrganisationInformation.Persistence.Forms.FormSection", b => + { + b.Navigation("Questions"); + }); + + modelBuilder.Entity("CO.CDP.OrganisationInformation.Persistence.Forms.SharedConsent", b => + { + b.Navigation("AnswerSets"); + }); + + modelBuilder.Entity("CO.CDP.OrganisationInformation.Persistence.Organisation", b => + { + b.Navigation("OrganisationPersons"); + }); + + modelBuilder.Entity("CO.CDP.OrganisationInformation.Persistence.Person", b => + { + b.Navigation("PersonOrganisations"); + }); + + modelBuilder.Entity("CO.CDP.OrganisationInformation.Persistence.Tenant", b => + { + b.Navigation("Organisations"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Services/CO.CDP.OrganisationInformation.Persistence/Migrations/20240927191342_ExclusionWebsiteQuestion.cs b/Services/CO.CDP.OrganisationInformation.Persistence/Migrations/20240927191342_ExclusionWebsiteQuestion.cs new file mode 100644 index 000000000..3aa38bc73 --- /dev/null +++ b/Services/CO.CDP.OrganisationInformation.Persistence/Migrations/20240927191342_ExclusionWebsiteQuestion.cs @@ -0,0 +1,59 @@ +using CO.CDP.OrganisationInformation.Persistence.Forms; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace CO.CDP.OrganisationInformation.Persistence.Migrations +{ + /// + public partial class ExclusionWebsiteQuestion : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.Sql($@" + DO $$ + DECLARE + sectionId INT; + questionId INT; + BEGIN + SELECT id INTO sectionId FROM form_sections WHERE guid = '8a75cb04-fe29-45ae-90f9-168832dbea48'; + + SELECT id INTO questionId FROM form_questions WHERE name = '_Exclusion02'; + + INSERT INTO form_questions (guid, section_id, next_question_id, type, is_required, title, description, options, name, summary_title) + VALUES ('{Guid.NewGuid()}', + sectionId, + questionId, + {(int)FormQuestionType.Url}, + FALSE, + 'Was the decision recorded on a public authority website?', + '
For example, the outcome of a court decision for a conviction or other event
', + '{{}}', + '_Exclusion10', + 'Recorded on a website') + RETURNING id INTO questionId; + + UPDATE form_questions SET next_question_id = questionId WHERE name = '_Exclusion03'; + END $$; + "); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.Sql($@" + DO $$ + DECLARE + questionId INT; + BEGIN + SELECT id INTO questionId FROM form_questions WHERE name = '_Exclusion02'; + + UPDATE form_questions SET next_question_id = questionId WHERE name = '_Exclusion03'; + + DELETE FROM form_questions WHERE name = '_Exclusion10'; + END $$; + "); + } + } +} From 9e57a7e0081de0be609a0f9066158a93207480ff Mon Sep 17 00:00:00 2001 From: Dharm Date: Mon, 30 Sep 2024 18:08:55 +0100 Subject: [PATCH 2/6] Added unit test --- .../Forms/FormElementUrlInputModelTests.cs | 133 ++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 Frontend/CO.CDP.OrganisationApp.Tests/Pages/Forms/FormElementUrlInputModelTests.cs diff --git a/Frontend/CO.CDP.OrganisationApp.Tests/Pages/Forms/FormElementUrlInputModelTests.cs b/Frontend/CO.CDP.OrganisationApp.Tests/Pages/Forms/FormElementUrlInputModelTests.cs new file mode 100644 index 000000000..69954dc5e --- /dev/null +++ b/Frontend/CO.CDP.OrganisationApp.Tests/Pages/Forms/FormElementUrlInputModelTests.cs @@ -0,0 +1,133 @@ +using CO.CDP.OrganisationApp.Models; +using CO.CDP.OrganisationApp.Pages.Forms; +using FluentAssertions; +using System.ComponentModel.DataAnnotations; + +namespace CO.CDP.OrganisationApp.Tests.Pages.Forms; + +public class FormElementUrlInputModelTests +{ + [Fact] + public void GetAnswer_ShouldReturnNull_WhenIsNotRequiredAndHasNoValue() + { + var model = new FormElementUrlInputModel + { + IsRequired = false, + HasValue = false + }; + + var result = model.GetAnswer(); + + result.Should().BeNull(); + } + + [Fact] + public void GetAnswer_ShouldReturnAnswer_WhenTextInputIsProvided() + { + var model = new FormElementUrlInputModel + { + IsRequired = true, + TextInput = "https://example.com", + HasValue = true + }; + + var result = model.GetAnswer(); + + result.Should().NotBeNull(); + result?.TextValue.Should().Be("https://example.com"); + } + + [Fact] + public void SetAnswer_ShouldSetTextInputAndHasValue_WhenAnswerIsProvided() + { + var model = new FormElementUrlInputModel(); + var answer = new FormAnswer { TextValue = "https://example.com" }; + + model.SetAnswer(answer); + + model.TextInput.Should().Be("https://example.com"); + model.HasValue.Should().BeTrue(); + } + + [Fact] + public void SetAnswer_ShouldSetHasValueToFalse_WhenAnswerIsNullAndRedirectFromCheckYourAnswerPage() + { + var model = new FormElementUrlInputModel(); + model.Initialize(new FormQuestion { IsRequired = false }, true); + + model.SetAnswer(null); + + model.HasValue.Should().BeFalse(); + } + + [Fact] + public void Validate_ShouldReturnError_WhenHasValueIsNullAndIsNotRequired() + { + var model = new FormElementUrlInputModel + { + IsRequired = false, + HasValue = null + }; + + var validationResults = new List(); + var context = new ValidationContext(model); + Validator.TryValidateObject(model, context, validationResults, true); + + validationResults.Should().ContainSingle(); + validationResults[0].ErrorMessage.Should().Be("Select an option"); + } + + [Fact] + public void Validate_ShouldReturnError_WhenTextInputIsMissingAndIsRequired() + { + var model = new FormElementUrlInputModel + { + IsRequired = true, + HasValue = true, + TextInput = null + }; + + var validationResults = new List(); + var context = new ValidationContext(model); + Validator.TryValidateObject(model, context, validationResults, true); + + validationResults.Should().ContainSingle(); + validationResults[0].ErrorMessage.Should().Be("Enter a website address"); + } + + [Fact] + public void Validate_ShouldReturnError_WhenTextInputIsInvalidUrl() + { + var model = new FormElementUrlInputModel + { + IsRequired = true, + HasValue = true, + TextInput = "invalid-url" + }; + + var validationResults = new List(); + var context = new ValidationContext(model); + Validator.TryValidateObject(model, context, validationResults, true); + + validationResults.Should().ContainSingle(); + validationResults[0].ErrorMessage.Should().Be("Enter a valid website address in the correct format"); + } + + [Fact] + public void Validate_ShouldPass_WhenValidUrlIsProvidedAndIsRequired() + { + var model = new FormElementUrlInputModel + { + IsRequired = true, + HasValue = true, + TextInput = "https://example.com" + }; + + var validationResults = new List(); + var context = new ValidationContext(model); + var isValid = Validator.TryValidateObject(model, context, validationResults, true); + + isValid.Should().BeTrue(); + validationResults.Should().BeEmpty(); + } +} \ No newline at end of file From 2ba6567abfbf19ce6ce90c91de85d64c21d18a1c Mon Sep 17 00:00:00 2001 From: Dharm Date: Tue, 1 Oct 2024 13:54:53 +0100 Subject: [PATCH 3/6] PR comment fix --- .../Pages/Forms/_FormElementDateInput.cshtml | 38 +++++------ .../Pages/Forms/_FormElementFileUpload.cshtml | 45 +++++++----- .../Pages/Forms/_FormElementTextInput.cshtml | 68 +++++++++++-------- .../Pages/Forms/_FormElementUrlInput.cshtml | 67 ++++++++++-------- 4 files changed, 122 insertions(+), 96 deletions(-) diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Forms/_FormElementDateInput.cshtml b/Frontend/CO.CDP.OrganisationApp/Pages/Forms/_FormElementDateInput.cshtml index 32b8a58b2..8c8047afd 100644 --- a/Frontend/CO.CDP.OrganisationApp/Pages/Forms/_FormElementDateInput.cshtml +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Forms/_FormElementDateInput.cshtml @@ -107,31 +107,29 @@ } else { -
-
+
-
- - -
+
+ + +
-
-
- @{ - RenderField(); - } -
+
+
+ @{ + RenderField(); + }
+
-
- - -
-
+
+ + +
-
+
}
\ No newline at end of file diff --git a/Frontend/CO.CDP.OrganisationApp/Pages/Forms/_FormElementFileUpload.cshtml b/Frontend/CO.CDP.OrganisationApp/Pages/Forms/_FormElementFileUpload.cshtml index 0cbb0f13f..a7d3bf208 100644 --- a/Frontend/CO.CDP.OrganisationApp/Pages/Forms/_FormElementFileUpload.cshtml +++ b/Frontend/CO.CDP.OrganisationApp/Pages/Forms/_FormElementFileUpload.cshtml @@ -4,6 +4,27 @@ var uploadFileHasError = ((TagBuilder)Html.ValidationMessageFor(m => m.UploadedFile)).HasInnerHtml; var selectOptionHasError = ((TagBuilder)Html.ValidationMessageFor(m => m.HasValue)).HasInnerHtml; + void RenderHeading() + { + @if (!string.IsNullOrWhiteSpace(Model.Heading)) + { +

@Model.Heading

+ } + + @if (!string.IsNullOrWhiteSpace(Model.Description)) + { + @Html.Raw(Model.Description) + } + + @if (selectOptionHasError) + { +

+ Error: + @Html.ValidationMessageFor(m => m.HasValue) +

+ } + } + void RenderField() {