From cd9bfbd8028b1aa44b3c22e830369040c165601c Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Tue, 4 Jan 2022 16:16:15 +0000 Subject: [PATCH] Add failing spec --- spec/factories/case_log.rb | 9 ++ spec/fixtures/forms/2022_2023.json | 147 ++++++++++++++++++++++++++ spec/models/form/subsection_spec.rb | 10 ++ spec/requests/form_controller_spec.rb | 2 +- 4 files changed, 167 insertions(+), 1 deletion(-) 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: {}