diff --git a/Gemfile.lock b/Gemfile.lock index 81349df1b..edfb7530e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -357,7 +357,7 @@ GEM simplecov_json_formatter (0.1.3) stimulus-rails (1.0.2) railties (>= 6.0.0) - thor (1.1.0) + thor (1.2.1) turbo-rails (1.0.0) actionpack (>= 6.0.0) railties (>= 6.0.0) diff --git a/app/models/form/question.rb b/app/models/form/question.rb index 88a840f2b..cc276a5ab 100644 --- a/app/models/form/question.rb +++ b/app/models/form/question.rb @@ -49,6 +49,13 @@ class Form::Question end end + def completed?(case_log) + # Special case as No is a valid answer but doesn't let you progress and use the service + return false if id == "gdpr_acceptance" && case_log[id] == "No" + + case_log[id].present? + end + private def checkbox_answer_label(case_log) diff --git a/app/models/form/subsection.rb b/app/models/form/subsection.rb index 19700d935..5ae163539 100644 --- a/app/models/form/subsection.rb +++ b/app/models/form/subsection.rb @@ -30,7 +30,7 @@ class Form::Subsection qs = applicable_questions(case_log) return :not_started if qs.all? { |question| case_log[question.id].blank? } - return :completed if qs.all? { |question| case_log[question.id].present? } + return :completed if qs.all? { |question| question.completed?(case_log) } :in_progress end diff --git a/spec/factories/case_log.rb b/spec/factories/case_log.rb index 6bb24ab91..72763bdbb 100644 --- a/spec/factories/case_log.rb +++ b/spec/factories/case_log.rb @@ -2,6 +2,15 @@ FactoryBot.define do factory :case_log do owning_organisation { FactoryBot.create(:organisation) } managing_organisation { FactoryBot.create(:organisation) } + trait :about_completed do + gdpr_acceptance { "Yes" } + sale_or_letting { "Letting" } + tenant_same_property_renewal { "No" } + needstype { 1 } + rent_type { 1 } + startdate { Time.zone.local(2022, 1, 1) } + year { 2022 } + end trait :in_progress do status { 1 } tenant_code { "TH356" } diff --git a/spec/fixtures/forms/2022_2023.json b/spec/fixtures/forms/2022_2023.json index bcf82242d..8e1b56807 100644 --- a/spec/fixtures/forms/2022_2023.json +++ b/spec/fixtures/forms/2022_2023.json @@ -1,6 +1,153 @@ { "form_type": "lettings", "sections": { + "about_this_log": { + "label": "About this log", + "subsections": { + "about_this_log": { + "label": "About this log", + "pages": { + "gdpr_acceptance": { + "header": "", + "description": "", + "questions": { + "gdpr_acceptance": { + "check_answer_label": "Privacy notice seen", + "header": "Has the tenant or buyer seen the Department for Levelling Up, Housing and Communities (DLUHC) privacy notice?", + "hint_text": "You must show the privacy notice to the tenant or buyer before you can use this service.", + "type": "radio", + "answer_options": { + "0": "Yes", + "1": "No" + } + } + } + }, + "gdpr_declined": { + "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": { + }, + "depends_on": { "gdpr_acceptance": "No" } + }, + "sale_or_letting": { + "header": "", + "description": "", + "questions": { + "sale_or_letting": { + "check_answer_label": "Sale or letting", + "header": "Is this a sale or a letting?", + "hint_text": "", + "type": "radio", + "answer_options": { + "0": "Sale", + "1": "Letting" + } + } + }, + "depends_on": { "gdpr_acceptance": "Yes" } + }, + "tenant_same_property_renewal": { + "header": "", + "description": "", + "questions": { + "tenant_same_property_renewal": { + "check_answer_label": "Property renewal", + "header": "Is this a renewal to the same tenant in the same property?", + "hint_text": "", + "type": "radio", + "answer_options": { + "0": "No", + "1": "Yes" + } + } + }, + "depends_on": { "gdpr_acceptance": "Yes", "sale_or_letting": "Letting" } + }, + "startdate": { + "header": "", + "description": "", + "questions": { + "startdate": { + "check_answer_label": "Tenancy start date", + "header": "What is the tenancy start date?", + "hint_text": "For example, 27 3 2007", + "type": "date" + } + }, + "depends_on": { "gdpr_acceptance": "Yes", "sale_or_letting": "Letting" } + }, + "about_this_letting": { + "header": "Tell us about this letting", + "description": "", + "questions": { + "rent_type": { + "check_answer_label": "Rent type", + "header": "What is the rent type?", + "hint_text": "", + "type": "radio", + "answer_options": { + "0": "Social rent", + "1": "Affordable rent", + "2": "London Affordable rent", + "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": "Product name", + "header": "What is intermediate rent product name?", + "type": "text" + }, + "needstype": { + "check_answer_label": "Needs type", + "header": "What is the needs type?", + "hint_text": "", + "type": "radio", + "answer_options": { + "0": "Supported housing", + "1": "General needs" + } + } + }, + "depends_on": { "gdpr_acceptance": "Yes", "sale_or_letting": "Letting" } + }, + "sale_completion_date": { + "header": "", + "description": "", + "questions": { + "sale_completion_date": { + "check_answer_label": "Sale completion date", + "header": "What is the sale completion date?", + "hint_text": "For example, 27 3 2007", + "type": "date" + } + }, + "depends_on": { "gdpr_acceptance": "Yes", "sale_or_letting": "Sale" } + }, + "purchaser_code": { + "header": "", + "description": "", + "questions": { + "purchaser_code": { + "check_answer_label": "Purchaser code", + "header": "What is the purchaser code?", + "hint_text": "", + "type": "text", + "width": 10 + } + }, + "depends_on": { "gdpr_acceptance": "Yes", "sale_or_letting": "Sale" } + } + } + } + } + }, "household": { "label": "About the household", "subsections": { diff --git a/spec/models/form/subsection_spec.rb b/spec/models/form/subsection_spec.rb index f64adc73e..2bb177a0c 100644 --- a/spec/models/form/subsection_spec.rb +++ b/spec/models/form/subsection_spec.rb @@ -58,6 +58,16 @@ RSpec.describe Form::Subsection, type: :model do end end + context "the privacy notice has not been shown" do + let(:section_id) { "about_this_log" } + let(:subsection_id) { "about_this_log" } + let(:case_log) { FactoryBot.build(:case_log, :about_completed, gdpr_acceptance: "No") } + + it "does not mark the section as completed" do + expect(subject.status(case_log)).to eq(:in_progress) + end + end + context "for a given completed case log" do let(:case_log) { FactoryBot.build(:case_log, :completed) } diff --git a/spec/requests/form_controller_spec.rb b/spec/requests/form_controller_spec.rb index 5e6160098..e40648d2f 100644 --- a/spec/requests/form_controller_spec.rb +++ b/spec/requests/form_controller_spec.rb @@ -50,7 +50,7 @@ RSpec.describe FormController, type: :request do context "form pages" do context "forms exist for multiple years" do let(:case_log_year_1) { FactoryBot.create(:case_log, startdate: Time.zone.local(2021, 1, 1), owning_organisation: organisation) } - let(:case_log_year_2) { FactoryBot.create(:case_log, startdate: Time.zone.local(2022, 1, 1), owning_organisation: organisation) } + let(:case_log_year_2) { FactoryBot.create(:case_log, :about_completed, startdate: Time.zone.local(2022, 1, 1), owning_organisation: organisation) } it "displays the correct question details for each case log based on form year" do get "/logs/#{case_log_year_1.id}/tenant-code", headers: headers, params: {}