Browse Source

Tenant's MUST be shown the privacy notice otherwise you can't complete the rest of the form (#187)

* Add failing spec

* About this log is only completed when privacy notice has been marked as shown

* Refactor special case into question
pull/191/head
baarkerlounger 3 years ago committed by GitHub
parent
commit
ed7679fdf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      Gemfile.lock
  2. 7
      app/models/form/question.rb
  3. 2
      app/models/form/subsection.rb
  4. 9
      spec/factories/case_log.rb
  5. 147
      spec/fixtures/forms/2022_2023.json
  6. 10
      spec/models/form/subsection_spec.rb
  7. 2
      spec/requests/form_controller_spec.rb

2
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)

7
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)

2
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

9
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" }

147
spec/fixtures/forms/2022_2023.json vendored

@ -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 <a class=\"govuk-link\" href=\"/files/privacy-notice.pdf\">show the privacy notice</a> 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": {

10
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) }

2
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: {}

Loading…
Cancel
Save