From ca367d612dbef16cce8bba2f72fb6d8f25bf2957 Mon Sep 17 00:00:00 2001 From: magicmilo Date: Wed, 3 Nov 2021 14:43:49 +0000 Subject: [PATCH] switch test form --- app/helpers/check_answers_helper.rb | 18 ++++++++++++-- config/forms/2021_2022.json | 24 ++++++++++--------- ...20_add_about_this_log_readable_columns.rb} | 0 db/schema.rb | 13 +++++++++- spec/fixtures/forms/test_aboutthislog.json | 21 ++++++++-------- 5 files changed, 51 insertions(+), 25 deletions(-) rename db/migrate/{20211102100820_add_about_this_log_readable_columns => 20211102100820_add_about_this_log_readable_columns.rb} (100%) diff --git a/app/helpers/check_answers_helper.rb b/app/helpers/check_answers_helper.rb index ff5312cce..053c19f89 100644 --- a/app/helpers/check_answers_helper.rb +++ b/app/helpers/check_answers_helper.rb @@ -28,12 +28,25 @@ module CheckAnswersHelper def filter_conditional_questions(questions, case_log) applicable_questions = questions + # puts applicable_questions.count questions.each do |k, question| + + # if k == "default_next_page" + # applicable_questions = applicable_questions.reject { |z| z == "default_next_page" } + # else + # question.fetch("conditional_for", []).each do |conditional_question_key, condition| + # if condition_not_met(case_log, k, question, condition) + # applicable_questions = applicable_questions.reject { |z| z == conditional_question_key } + # end + # end + # end + question.fetch("conditional_for", []).each do |conditional_question_key, condition| if condition_not_met(case_log, k, question, condition) applicable_questions = applicable_questions.reject { |z| z == conditional_question_key } end end + end applicable_questions end @@ -56,13 +69,14 @@ module CheckAnswersHelper operator = condition[/[<>=]+/].to_sym operand = condition[/\d+/].to_i case_log[question_key].blank? || !case_log[question_key].send(operator, operand) + when "text" + case_log[question_key].blank? || !condition.include?(case_log[question_key]) when "radio" case_log[question_key].blank? || !condition.include?(case_log[question_key]) when "select" case_log[question_key].blank? || !condition.include?(case_log[question_key]) else - raise "Not implemented yet" - end + raise "Not implemented yet" end end def create_update_answer_link(case_log_answer, case_log_id, page) diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index 662cf9cec..8355b4f93 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -33,6 +33,9 @@ "header": "You cannot use this service", "hint_text": "", "description": "We cannot accept data about a tenant or buyer unless they’ve seen the DLUHC privacy notice.", + "questions": { + + }, "default_next_page" : "check_answers" }, "organisation_details": { @@ -74,13 +77,12 @@ "0": "Sale", "1": "Letting" } - }, - "conditional_route_to": { - "sale_completion_date": { "sale_or_letting": "Sale" }, - "tenant_same_property_renewal": { "sale_or_letting": "Letting" } - }, - "default_next_page" : ["check_answers"] - } + } + }, + "conditional_route_to": { + "tenant_same_property_renewal": { "sale_or_letting": "Letting" } + }, + "default_next_page" : "check_answers" }, "tenant_same_property_renewal": { "header": "About this log", @@ -126,15 +128,15 @@ "3": "Rent To Buy", "4": "London Living Rent", "5": "Other Intermediate Rent Product" + }, + "conditional_for": { + "intermediate_rent_product_name": ["Other Intermediate Rent Product"] } }, "intermediate_rent_product_name": { "check_answer_label": "Enter the product name", "header": "What is intermediate rent product name?", - "type": "text", - "conditional_for": { - "rent_type": ["Other Intermediate Rent Product"] - } + "type": "text" }, "needs_type": { "check_answer_label": "What is the needs type?", diff --git a/db/migrate/20211102100820_add_about_this_log_readable_columns b/db/migrate/20211102100820_add_about_this_log_readable_columns.rb similarity index 100% rename from db/migrate/20211102100820_add_about_this_log_readable_columns rename to db/migrate/20211102100820_add_about_this_log_readable_columns.rb diff --git a/db/schema.rb b/db/schema.rb index 346f047c2..c29297c23 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_10_27_123535) do +ActiveRecord::Schema.define(version: 2021_11_02_100820) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -133,6 +133,17 @@ ActiveRecord::Schema.define(version: 2021_10_27_123535) do t.boolean "reasonable_preference_reason_do_not_know" t.datetime "discarded_at" t.string "other_tenancy_type" + t.string "gdpr_acceptance" + t.string "gdpr_declined" + t.string "property_owner_organisation" + t.string "property_manager_organisation" + t.string "sale_or_letting" + t.string "tenant_same_property_renewal" + t.string "rent_type" + t.string "intermediate_rent_product_name" + t.string "needs_type" + t.string "sale_completion_date" + t.string "purchaser_code" t.index ["discarded_at"], name: "index_case_logs_on_discarded_at" end diff --git a/spec/fixtures/forms/test_aboutthislog.json b/spec/fixtures/forms/test_aboutthislog.json index 5f4313bd0..2cfd8ff26 100644 --- a/spec/fixtures/forms/test_aboutthislog.json +++ b/spec/fixtures/forms/test_aboutthislog.json @@ -75,13 +75,12 @@ "0": "Sale", "1": "Letting" } - }, - "conditional_route_to": { - "sale_completion_date": { "sale_or_letting": "Sale" }, - "tenant_same_property_renewal": { "sale_or_letting": "Letting" } - }, - "default_next_page" : ["check_answers"] - } + } + }, + "conditional_route_to": { + "tenant_same_property_renewal": { "sale_or_letting": "Letting" } + }, + "default_next_page" : "check_answers" }, "tenant_same_property_renewal": { "header": "About this log", @@ -127,15 +126,15 @@ "3": "Rent To Buy", "4": "London Living Rent", "5": "Other Intermediate Rent Product" + }, + "conditional_for": { + "intermediate_rent_product_name": ["Other Intermediate Rent Product"] } }, "intermediate_rent_product_name": { "check_answer_label": "Enter the product name", "header": "What is intermediate rent product name?", - "type": "text", - "conditional_for": { - "rent_type": ["Other Intermediate Rent Product"] - } + "type": "text" }, "needs_type": { "check_answer_label": "What is the needs type?",