From b22c6c961a5f98012edb3c0b00589884434958f7 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Wed, 5 Oct 2022 12:27:13 +0300 Subject: [PATCH 1/2] Cldc 1503 lead nationality (#909) * Add nationality and other nationality questions * Add nationality page * Add national columns * Add hidden_in_check_answers * Update conditional question controller to work with both log types * update tests * lint * Remove console.log * tests and migration * typo * tests * tests * feat: update schema and tests * Add nationality and other nationality questions * Add nationality page * Add national columns * Add hidden_in_check_answers * Update conditional question controller to work with both log types * update tests * lint * Remove console.log * tests and migration * typo * tests * feat: update schema and tests * tests: update tests * feat: update schema.rb Co-authored-by: natdeanlewissoftwire --- .../conditional_question_controller.js | 8 ++- app/helpers/question_attribute_helper.rb | 2 +- app/models/form/sales/pages/nationality1.rb | 16 +++++ .../form/sales/questions/nationality1.rb | 30 +++++++++ .../sales/questions/other_nationality1.rb | 10 +++ .../subsections/household_characteristics.rb | 5 +- .../20220927082602_add_national_column.rb | 8 +++ db/schema.rb | 14 +++-- spec/factories/sales_log.rb | 1 + .../form/conditional_questions_spec.rb | 18 ++++++ .../helpers/question_attribute_helper_spec.rb | 4 +- .../form/sales/pages/nationality1_spec.rb | 33 ++++++++++ .../form/sales/questions/nationality1_spec.rb | 63 +++++++++++++++++++ .../questions/other_nationality1_spec.rb | 37 +++++++++++ .../household_characteristics_spec.rb | 5 +- spec/models/form_handler_spec.rb | 4 +- 16 files changed, 240 insertions(+), 18 deletions(-) create mode 100644 app/models/form/sales/pages/nationality1.rb create mode 100644 app/models/form/sales/questions/nationality1.rb create mode 100644 app/models/form/sales/questions/other_nationality1.rb create mode 100644 db/migrate/20220927082602_add_national_column.rb create mode 100644 spec/models/form/sales/pages/nationality1_spec.rb create mode 100644 spec/models/form/sales/questions/nationality1_spec.rb create mode 100644 spec/models/form/sales/questions/other_nationality1_spec.rb diff --git a/app/frontend/controllers/conditional_question_controller.js b/app/frontend/controllers/conditional_question_controller.js index 974deeb2e..fb52d07c1 100644 --- a/app/frontend/controllers/conditional_question_controller.js +++ b/app/frontend/controllers/conditional_question_controller.js @@ -8,14 +8,16 @@ export default class extends Controller { displayConditional () { if (this.element.checked) { const selectedValue = this.element.value - const conditionalFor = JSON.parse(this.element.dataset.info) + const dataInfo = JSON.parse(this.element.dataset.info) + const conditionalFor = dataInfo.conditional_questions + const logType = dataInfo.log_type Object.entries(conditionalFor).forEach(([targetQuestion, conditions]) => { if (!conditions.map(String).includes(String(selectedValue))) { - const textNumericInput = document.getElementById(`lettings-log-${targetQuestion.replaceAll('_', '-')}-field`) + const textNumericInput = document.getElementById(`${logType}-log-${targetQuestion.replaceAll('_', '-')}-field`) if (textNumericInput == null) { const dateInputs = [1, 2, 3].map((idx) => { - return document.getElementById(`lettings_log_${targetQuestion}_${idx}i`) + return document.getElementById(`${logType}_log_${targetQuestion}_${idx}i`) }) this.clearDateInputs(dateInputs) } else { diff --git a/app/helpers/question_attribute_helper.rb b/app/helpers/question_attribute_helper.rb index f2f148568..857ce5eb1 100644 --- a/app/helpers/question_attribute_helper.rb +++ b/app/helpers/question_attribute_helper.rb @@ -27,7 +27,7 @@ private { "data-controller": "conditional-question", "data-action": "click->conditional-question#displayConditional", - "data-info": question.conditional_for.to_json, + "data-info": { conditional_questions: question.conditional_for, log_type: question.form.type }.to_json, } end end diff --git a/app/models/form/sales/pages/nationality1.rb b/app/models/form/sales/pages/nationality1.rb new file mode 100644 index 000000000..740aa694f --- /dev/null +++ b/app/models/form/sales/pages/nationality1.rb @@ -0,0 +1,16 @@ +class Form::Sales::Pages::Nationality1 < ::Form::Page + def initialize(id, hsh, subsection) + super + @id = "buyer_1_nationality" + @header = "" + @description = "" + @subsection = subsection + end + + def questions + @questions ||= [ + Form::Sales::Questions::Nationality1.new(nil, nil, self), + Form::Sales::Questions::OtherNationality1.new(nil, nil, self), + ] + end +end diff --git a/app/models/form/sales/questions/nationality1.rb b/app/models/form/sales/questions/nationality1.rb new file mode 100644 index 000000000..737bfc01e --- /dev/null +++ b/app/models/form/sales/questions/nationality1.rb @@ -0,0 +1,30 @@ +class Form::Sales::Questions::Nationality1 < ::Form::Question + def initialize(id, hsh, page) + super + @id = "national" + @check_answer_label = "Buyer 1’s nationality" + @header = "What is buyer 1’s nationality?" + @type = "radio" + @hint_text = "Buyer 1 is the person in the household who does the most paid work. If it’s a joint purchase and the buyers do the same amount of paid work, buyer 1 is whoever is the oldest." + @page = page + @answer_options = ANSWER_OPTIONS + @conditional_for = { + "othernational" => [12], + } + @hidden_in_check_answers = { + "depends_on" => [ + { + "national" => 12, + }, + ], + } + end + + ANSWER_OPTIONS = { + "18" => { "value" => "United Kingdom" }, + "17" => { "value" => "Republic of Ireland" }, + "19" => { "value" => "European Economic Area (EEA), excluding ROI" }, + "12" => { "value" => "Other" }, + "13" => { "value" => "Buyer prefers not to say" }, + }.freeze +end diff --git a/app/models/form/sales/questions/other_nationality1.rb b/app/models/form/sales/questions/other_nationality1.rb new file mode 100644 index 000000000..a779d4fc8 --- /dev/null +++ b/app/models/form/sales/questions/other_nationality1.rb @@ -0,0 +1,10 @@ +class Form::Sales::Questions::OtherNationality1 < ::Form::Question + def initialize(id, hsh, page) + super + @id = "othernational" + @check_answer_label = "Buyer 1’s nationality" + @header = "Nationality" + @type = "text" + @page = page + end +end diff --git a/app/models/form/sales/subsections/household_characteristics.rb b/app/models/form/sales/subsections/household_characteristics.rb index 93d084332..e389d5e72 100644 --- a/app/models/form/sales/subsections/household_characteristics.rb +++ b/app/models/form/sales/subsections/household_characteristics.rb @@ -12,14 +12,15 @@ class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection Form::Sales::Pages::BuyerInterview.new(nil, nil, self), Form::Sales::Pages::Age1.new(nil, nil, self), Form::Sales::Pages::GenderIdentity1.new(nil, nil, self), - Form::Sales::Pages::Buyer1LiveInProperty.new(nil, nil, self), - Form::Sales::Pages::Buyer2RelationshipToBuyer1.new(nil, nil, self), Form::Sales::Pages::Buyer1EthnicGroup.new(nil, nil, self), Form::Sales::Pages::Buyer1EthnicBackgroundBlack.new(nil, nil, self), Form::Sales::Pages::Buyer1EthnicBackgroundAsian.new(nil, nil, self), Form::Sales::Pages::Buyer1EthnicBackgroundArab.new(nil, nil, self), Form::Sales::Pages::Buyer1EthnicBackgroundMixed.new(nil, nil, self), Form::Sales::Pages::Buyer1EthnicBackgroundWhite.new(nil, nil, self), + Form::Sales::Pages::Nationality1.new(nil, nil, self), + Form::Sales::Pages::Buyer1LiveInProperty.new(nil, nil, self), + Form::Sales::Pages::Buyer2RelationshipToBuyer1.new(nil, nil, self), Form::Sales::Pages::Age2.new(nil, nil, self), Form::Sales::Pages::GenderIdentity2.new(nil, nil, self), Form::Sales::Pages::Buyer2WorkingSituation.new(nil, nil, self), diff --git a/db/migrate/20220927082602_add_national_column.rb b/db/migrate/20220927082602_add_national_column.rb new file mode 100644 index 000000000..d794bc858 --- /dev/null +++ b/db/migrate/20220927082602_add_national_column.rb @@ -0,0 +1,8 @@ +class AddNationalColumn < ActiveRecord::Migration[7.0] + def change + change_table :sales_logs, bulk: true do |t| + t.column :national, :integer + t.column :othernational, :string + end + end +end diff --git a/db/schema.rb b/db/schema.rb index b30200da0..269091a77 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[7.0].define(version: 2022_10_03_150610) do +ActiveRecord::Schema[7.0].define(version: 2022_10_04_095132) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -329,22 +329,24 @@ ActiveRecord::Schema[7.0].define(version: 2022_10_03_150610) do t.string "purchid" t.integer "type" t.integer "ownershipsch" - t.string "othtype" - t.integer "jointmore" t.integer "jointpur" + t.string "othtype" t.integer "beds" - t.integer "companybuy" + t.integer "jointmore" t.integer "age1" t.integer "age1_known" t.string "sex1" + t.integer "national" + t.string "othernational" t.integer "buy1livein" + t.integer "companybuy" t.integer "buylivein" t.integer "builtype" t.integer "proptype" - t.string "relat2" - t.string "otherrelat2" t.integer "age2" t.integer "age2_known" + t.string "relat2" + t.string "otherrelat2" t.integer "ethnic" t.integer "ethnic_group" t.string "sex2" diff --git a/spec/factories/sales_log.rb b/spec/factories/sales_log.rb index 4f9aa07ed..2936d0d06 100644 --- a/spec/factories/sales_log.rb +++ b/spec/factories/sales_log.rb @@ -24,6 +24,7 @@ FactoryBot.define do age1_known { 0 } age1 { 30 } sex1 { "X" } + national { 18 } buy1livein { 1 } relat2 { "P" } proptype { 1 } diff --git a/spec/features/form/conditional_questions_spec.rb b/spec/features/form/conditional_questions_spec.rb index 4f3f44b5a..33d99955e 100644 --- a/spec/features/form/conditional_questions_spec.rb +++ b/spec/features/form/conditional_questions_spec.rb @@ -12,6 +12,14 @@ RSpec.describe "Form Conditional Questions" do managing_organisation: user.organisation, ) end + let(:sales_log) do + FactoryBot.create( + :sales_log, + :completed, + owning_organisation: user.organisation, + managing_organisation: user.organisation, + ) + end let(:id) { lettings_log.id } let(:fake_2021_2022_form) { Form.new("spec/fixtures/forms/2021_2022.json") } @@ -44,5 +52,15 @@ RSpec.describe "Form Conditional Questions" do visit("/lettings-logs/#{id}/property-postcode") expect(page).to have_field("lettings-log-postcode-full-field", with: "NW1 6RT") end + + it "gets cleared if the conditional question is hidden after editing the answer" do + sales_log.update!(national: 12, othernational: "other") + visit("/sales-logs/#{sales_log.id}/buyer-1-nationality") + expect(page).to have_field("sales-log-othernational-field", with: "other") + + choose("sales-log-national-18-field", allow_label_click: true) + choose("sales-log-national-12-field", allow_label_click: true) + expect(page).to have_field("sales-log-othernational-field", with: "") + end end end diff --git a/spec/helpers/question_attribute_helper_spec.rb b/spec/helpers/question_attribute_helper_spec.rb index 96f2f7ef6..2be903535 100644 --- a/spec/helpers/question_attribute_helper_spec.rb +++ b/spec/helpers/question_attribute_helper_spec.rb @@ -40,7 +40,7 @@ RSpec.describe QuestionAttributeHelper do "conditional_for" => { "next_question": ">1", }, - }, nil) + }, form.get_page("rent")) end let(:expected_attribs) do { @@ -48,7 +48,7 @@ RSpec.describe QuestionAttributeHelper do "data-action": "input->numeric-question#calculateFields click->conditional-question#displayConditional", "data-target": "lettings-log-#{question.result_field.to_s.dasherize}-field", "data-calculated": question.fields_to_add.to_json, - "data-info": question.conditional_for.to_json, + "data-info": { conditional_questions: question.conditional_for, log_type: "lettings" }.to_json, } end diff --git a/spec/models/form/sales/pages/nationality1_spec.rb b/spec/models/form/sales/pages/nationality1_spec.rb new file mode 100644 index 000000000..5d156e041 --- /dev/null +++ b/spec/models/form/sales/pages/nationality1_spec.rb @@ -0,0 +1,33 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Pages::Nationality1, type: :model do + subject(:page) { described_class.new(page_id, page_definition, subsection) } + + let(:page_id) { nil } + let(:page_definition) { nil } + let(:subsection) { instance_double(Form::Subsection) } + + it "has correct subsection" do + expect(page.subsection).to eq(subsection) + end + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[national othernational]) + end + + it "has the correct id" do + expect(page.id).to eq("buyer_1_nationality") + end + + it "has the correct header" do + expect(page.header).to eq("") + end + + it "has the correct description" do + expect(page.description).to eq("") + end + + it "has correct depends_on" do + expect(page.depends_on).to be_nil + end +end diff --git a/spec/models/form/sales/questions/nationality1_spec.rb b/spec/models/form/sales/questions/nationality1_spec.rb new file mode 100644 index 000000000..819d41ae4 --- /dev/null +++ b/spec/models/form/sales/questions/nationality1_spec.rb @@ -0,0 +1,63 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::Nationality1, type: :model do + subject(:question) { described_class.new(question_id, question_definition, page) } + + let(:question_id) { nil } + let(:question_definition) { nil } + let(:page) { instance_double(Form::Page) } + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct id" do + expect(question.id).to eq("national") + end + + it "has the correct header" do + expect(question.header).to eq("What is buyer 1’s nationality?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Buyer 1’s nationality") + end + + it "has the correct type" do + expect(question.type).to eq("radio") + end + + it "is not marked as derived" do + expect(question.derived?).to be false + end + + it "has the correct hint" do + expect(question.hint_text).to eq("Buyer 1 is the person in the household who does the most paid work. If it’s a joint purchase and the buyers do the same amount of paid work, buyer 1 is whoever is the oldest.") + end + + it "has the correct answer_options" do + expect(question.answer_options).to eq({ + "18" => { "value" => "United Kingdom" }, + "17" => { "value" => "Republic of Ireland" }, + "19" => { "value" => "European Economic Area (EEA), excluding ROI" }, + "12" => { "value" => "Other" }, + "13" => { "value" => "Buyer prefers not to say" }, + }) + end + + it "has correct conditional for" do + expect(question.conditional_for).to eq({ + "othernational" => [12], + }) + end + + it "has correct hidden in check answers" do + expect(question.hidden_in_check_answers).to eq({ + "depends_on" => [ + { + "national" => 12, + }, + ], + }) + end +end diff --git a/spec/models/form/sales/questions/other_nationality1_spec.rb b/spec/models/form/sales/questions/other_nationality1_spec.rb new file mode 100644 index 000000000..b01928efc --- /dev/null +++ b/spec/models/form/sales/questions/other_nationality1_spec.rb @@ -0,0 +1,37 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::OtherNationality1, type: :model do + subject(:question) { described_class.new(question_id, question_definition, page) } + + let(:question_id) { nil } + let(:question_definition) { nil } + let(:page) { instance_double(Form::Page) } + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct id" do + expect(question.id).to eq("othernational") + end + + it "has the correct header" do + expect(question.header).to eq("Nationality") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Buyer 1’s nationality") + end + + it "has the correct type" do + expect(question.type).to eq("text") + end + + it "is not marked as derived" do + expect(question.derived?).to be false + end + + it "has the correct hint" do + expect(question.hint_text).to be_nil + end +end diff --git a/spec/models/form/sales/subsections/household_characteristics_spec.rb b/spec/models/form/sales/subsections/household_characteristics_spec.rb index 364895cc8..21e496efd 100644 --- a/spec/models/form/sales/subsections/household_characteristics_spec.rb +++ b/spec/models/form/sales/subsections/household_characteristics_spec.rb @@ -17,14 +17,15 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model buyer_interview buyer_1_age buyer_1_gender_identity - buyer_1_live_in_property - buyer_2_relationship_to_buyer_1 buyer_1_ethnic_group buyer_1_ethnic_background_black buyer_1_ethnic_background_asian buyer_1_ethnic_background_arab buyer_1_ethnic_background_mixed buyer_1_ethnic_background_white + buyer_1_nationality + buyer_1_live_in_property + buyer_2_relationship_to_buyer_1 buyer_2_age buyer_2_gender_identity buyer_2_working_situation diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb index 831502602..32b6fbc7d 100644 --- a/spec/models/form_handler_spec.rb +++ b/spec/models/form_handler_spec.rb @@ -61,14 +61,14 @@ RSpec.describe FormHandler do it "is able to load a current sales form" do form = form_handler.get_form("current_sales") expect(form).to be_a(Form) - expect(form.pages.count).to eq(30) + expect(form.pages.count).to eq(31) expect(form.name).to eq("2022_2023_sales") end it "is able to load a previous sales form" do form = form_handler.get_form("previous_sales") expect(form).to be_a(Form) - expect(form.pages.count).to eq(30) + expect(form.pages.count).to eq(31) expect(form.name).to eq("2021_2022_sales") end end From 9a0629004d306a08038bc5dc1ca20e056722e5a1 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire <94526761+natdeanlewissoftwire@users.noreply.github.com> Date: Wed, 5 Oct 2022 12:02:52 +0100 Subject: [PATCH 2/2] Cldc 1574 privacy notice (#931) * feat: core functionality * feat: update schema.rb * feat: add link for privacy notice, refactor to separate tenant/buyer * feat: make privacy notices open in new tab * test: make previous tests pass * test: add new tests --- app/models/form/sales/pages/privacy_notice.rb | 18 ++++++++ .../form/sales/questions/privacy_notice.rb | 18 ++++++++ .../subsections/household_characteristics.rb | 1 + .../form/guidance/_privacy_notice_buyer.erb | 1 + ..._notice.erb => _privacy_notice_tenant.erb} | 2 +- config/forms/2021_2022.json | 2 +- config/forms/2022_2023.json | 2 +- ...4095132_add_privacy_notice_to_sales_log.rb | 7 +++ db/schema.rb | 11 ++--- .../form/sales/pages/privacy_notice_spec.rb | 33 ++++++++++++++ .../sales/questions/privacy_notice_spec.rb | 43 +++++++++++++++++++ .../household_characteristics_spec.rb | 1 + spec/models/form_handler_spec.rb | 4 +- 13 files changed, 133 insertions(+), 10 deletions(-) create mode 100644 app/models/form/sales/pages/privacy_notice.rb create mode 100644 app/models/form/sales/questions/privacy_notice.rb create mode 100644 app/views/form/guidance/_privacy_notice_buyer.erb rename app/views/form/guidance/{_privacy_notice.erb => _privacy_notice_tenant.erb} (57%) create mode 100644 db/migrate/20221004095132_add_privacy_notice_to_sales_log.rb create mode 100644 spec/models/form/sales/pages/privacy_notice_spec.rb create mode 100644 spec/models/form/sales/questions/privacy_notice_spec.rb diff --git a/app/models/form/sales/pages/privacy_notice.rb b/app/models/form/sales/pages/privacy_notice.rb new file mode 100644 index 000000000..a7e8ca219 --- /dev/null +++ b/app/models/form/sales/pages/privacy_notice.rb @@ -0,0 +1,18 @@ +class Form::Sales::Pages::PrivacyNotice < ::Form::Page + def initialize(id, hsh, subsection) + super + @id = "privacy_notice" + @header = "Department for Levelling Up, Housing and Communities privacy notice" + @description = "" + @subsection = subsection + @depends_on = [{ + "noint" => 1, + }] + end + + def questions + @questions ||= [ + Form::Sales::Questions::PrivacyNotice.new(nil, nil, self), + ] + end +end diff --git a/app/models/form/sales/questions/privacy_notice.rb b/app/models/form/sales/questions/privacy_notice.rb new file mode 100644 index 000000000..e853b38de --- /dev/null +++ b/app/models/form/sales/questions/privacy_notice.rb @@ -0,0 +1,18 @@ +class Form::Sales::Questions::PrivacyNotice < ::Form::Question + def initialize(id, hsh, page) + super + @id = "privacynotice" + @check_answer_label = "Buyer has seen the privacy notice?" + @header = "Declaration" + @type = "checkbox" + @hint_text = "" + @page = page + @answer_options = ANSWER_OPTIONS + @guidance_position = GuidancePosition::TOP + @guidance_partial = "privacy_notice_buyer" + end + + ANSWER_OPTIONS = { + "privacynotice" => { "value" => "The buyer has seen the DLUHC privacy notice" }, + }.freeze +end diff --git a/app/models/form/sales/subsections/household_characteristics.rb b/app/models/form/sales/subsections/household_characteristics.rb index e389d5e72..055aca08b 100644 --- a/app/models/form/sales/subsections/household_characteristics.rb +++ b/app/models/form/sales/subsections/household_characteristics.rb @@ -10,6 +10,7 @@ class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection def pages @pages ||= [ Form::Sales::Pages::BuyerInterview.new(nil, nil, self), + Form::Sales::Pages::PrivacyNotice.new(nil, nil, self), Form::Sales::Pages::Age1.new(nil, nil, self), Form::Sales::Pages::GenderIdentity1.new(nil, nil, self), Form::Sales::Pages::Buyer1EthnicGroup.new(nil, nil, self), diff --git a/app/views/form/guidance/_privacy_notice_buyer.erb b/app/views/form/guidance/_privacy_notice_buyer.erb new file mode 100644 index 000000000..fabe9ced1 --- /dev/null +++ b/app/views/form/guidance/_privacy_notice_buyer.erb @@ -0,0 +1 @@ +

Make sure the buyer has seen <%= govuk_link_to "the Department for Levelling Up, Housing & Communities (DLUHC) privacy notice", privacy_notice_path, target: :_blank %> before completing this log.

diff --git a/app/views/form/guidance/_privacy_notice.erb b/app/views/form/guidance/_privacy_notice_tenant.erb similarity index 57% rename from app/views/form/guidance/_privacy_notice.erb rename to app/views/form/guidance/_privacy_notice_tenant.erb index c6e0b9adc..88b281730 100644 --- a/app/views/form/guidance/_privacy_notice.erb +++ b/app/views/form/guidance/_privacy_notice_tenant.erb @@ -1 +1 @@ -

Make sure the tenant has seen <%= govuk_link_to "the Department for Levelling Up, Housing & Communities (DLUHC) privacy notice", privacy_notice_path %> before completing this log.

+

Make sure the tenant has seen <%= govuk_link_to "the Department for Levelling Up, Housing & Communities (DLUHC) privacy notice", privacy_notice_path, target: :_blank %> before completing this log.

diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index 4292d1d3a..801ab5717 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -1143,7 +1143,7 @@ "questions": { "declaration": { "header": "", - "guidance_partial": "privacy_notice", + "guidance_partial": "privacy_notice_tenant", "check_answer_label": "Tenant has seen the privacy notice", "check_answers_card_number": 0, "type": "checkbox", diff --git a/config/forms/2022_2023.json b/config/forms/2022_2023.json index b30461a84..490d28e12 100644 --- a/config/forms/2022_2023.json +++ b/config/forms/2022_2023.json @@ -1178,7 +1178,7 @@ "questions": { "declaration": { "header": "", - "guidance_partial": "privacy_notice", + "guidance_partial": "privacy_notice_tenant", "check_answer_label": "Tenant has seen the privacy notice", "check_answers_card_number": 0, "type": "checkbox", diff --git a/db/migrate/20221004095132_add_privacy_notice_to_sales_log.rb b/db/migrate/20221004095132_add_privacy_notice_to_sales_log.rb new file mode 100644 index 000000000..f60b00823 --- /dev/null +++ b/db/migrate/20221004095132_add_privacy_notice_to_sales_log.rb @@ -0,0 +1,7 @@ +class AddPrivacyNoticeToSalesLog < ActiveRecord::Migration[7.0] + def change + change_table :sales_logs, bulk: true do |t| + t.column :privacynotice, :int + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 269091a77..368f1a4e8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -329,17 +329,19 @@ ActiveRecord::Schema[7.0].define(version: 2022_10_04_095132) do t.string "purchid" t.integer "type" t.integer "ownershipsch" - t.integer "jointpur" t.string "othtype" - t.integer "beds" t.integer "jointmore" + t.integer "jointpur" + t.integer "beds" + t.integer "companybuy" t.integer "age1" t.integer "age1_known" t.string "sex1" t.integer "national" t.string "othernational" + t.integer "ethnic" + t.integer "ethnic_group" t.integer "buy1livein" - t.integer "companybuy" t.integer "buylivein" t.integer "builtype" t.integer "proptype" @@ -347,12 +349,11 @@ ActiveRecord::Schema[7.0].define(version: 2022_10_04_095132) do t.integer "age2_known" t.string "relat2" t.string "otherrelat2" - t.integer "ethnic" - t.integer "ethnic_group" t.string "sex2" t.integer "noint" t.integer "buy2livein" t.integer "ecstat2" + t.integer "privacynotice" t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id" t.index ["managing_organisation_id"], name: "index_sales_logs_on_managing_organisation_id" t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id" diff --git a/spec/models/form/sales/pages/privacy_notice_spec.rb b/spec/models/form/sales/pages/privacy_notice_spec.rb new file mode 100644 index 000000000..9c957b0b5 --- /dev/null +++ b/spec/models/form/sales/pages/privacy_notice_spec.rb @@ -0,0 +1,33 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Pages::PrivacyNotice, type: :model do + subject(:page) { described_class.new(page_id, page_definition, subsection) } + + let(:page_id) { nil } + let(:page_definition) { nil } + let(:subsection) { instance_double(Form::Subsection) } + + it "has correct subsection" do + expect(page.subsection).to eq(subsection) + end + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[privacynotice]) + end + + it "has the correct id" do + expect(page.id).to eq("privacy_notice") + end + + it "has the correct header" do + expect(page.header).to eq("Department for Levelling Up, Housing and Communities privacy notice") + end + + it "has the correct description" do + expect(page.description).to eq("") + end + + it "has correct depends_on" do + expect(page.depends_on).to eq([{ "noint" => 1 }]) + end +end diff --git a/spec/models/form/sales/questions/privacy_notice_spec.rb b/spec/models/form/sales/questions/privacy_notice_spec.rb new file mode 100644 index 000000000..f90daef1b --- /dev/null +++ b/spec/models/form/sales/questions/privacy_notice_spec.rb @@ -0,0 +1,43 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::PrivacyNotice, type: :model do + subject(:question) { described_class.new(question_id, question_definition, page) } + + let(:question_id) { nil } + let(:question_definition) { nil } + let(:page) { instance_double(Form::Page) } + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct id" do + expect(question.id).to eq("privacynotice") + end + + it "has the correct header" do + expect(question.header).to eq("Declaration") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Buyer has seen the privacy notice?") + end + + it "has the correct type" do + expect(question.type).to eq("checkbox") + end + + it "is not marked as derived" do + expect(question.derived?).to be false + end + + it "has the correct hint" do + expect(question.hint_text).to eq("") + end + + it "has the correct answer_options" do + expect(question.answer_options).to eq({ + "privacynotice" => { "value" => "The buyer has seen the DLUHC privacy notice" }, + }) + end +end diff --git a/spec/models/form/sales/subsections/household_characteristics_spec.rb b/spec/models/form/sales/subsections/household_characteristics_spec.rb index 21e496efd..29874c8e6 100644 --- a/spec/models/form/sales/subsections/household_characteristics_spec.rb +++ b/spec/models/form/sales/subsections/household_characteristics_spec.rb @@ -15,6 +15,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model expect(household_characteristics.pages.map(&:id)).to eq( %w[ buyer_interview + privacy_notice buyer_1_age buyer_1_gender_identity buyer_1_ethnic_group diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb index 32b6fbc7d..c42b021cd 100644 --- a/spec/models/form_handler_spec.rb +++ b/spec/models/form_handler_spec.rb @@ -61,14 +61,14 @@ RSpec.describe FormHandler do it "is able to load a current sales form" do form = form_handler.get_form("current_sales") expect(form).to be_a(Form) - expect(form.pages.count).to eq(31) + expect(form.pages.count).to eq(32) expect(form.name).to eq("2022_2023_sales") end it "is able to load a previous sales form" do form = form_handler.get_form("previous_sales") expect(form).to be_a(Form) - expect(form.pages.count).to eq(31) + expect(form.pages.count).to eq(32) expect(form.name).to eq("2021_2022_sales") end end