Browse Source

Cldc 972 submitting lettings log (#279)

* add validation for declaration on log submission

* Only present next incomplete section link if such section exists
pull/281/head
kosiakkatrina 3 years ago committed by GitHub
parent
commit
512c5fdad2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      app/controllers/form_controller.rb
  2. 3
      app/models/bulk_upload.rb
  3. 2
      app/models/case_log.rb
  4. 7
      app/models/form.rb
  5. 2
      app/models/form/question.rb
  6. 10
      app/models/validations/submission_validations.rb
  7. 14
      app/views/case_logs/edit.html.erb
  8. 6
      app/views/form/page.html.erb
  9. 57
      config/forms/2021_2022.json
  10. 3
      config/locales/en.yml
  11. 7
      db/migrate/20220207091117_add_declaration.rb
  12. 15
      db/migrate/20220208101235_remove_gdpr_fields.rb
  13. 6
      db/schema.rb
  14. 4
      spec/factories/case_log.rb
  15. 2
      spec/features/form/check_answers_page_spec.rb
  16. 4
      spec/features/form/tasklist_page_spec.rb
  17. 31
      spec/features/form/validations_spec.rb
  18. 5
      spec/fixtures/complete_case_log.json
  19. 39
      spec/fixtures/forms/2021_2022.json
  20. 39
      spec/fixtures/forms/2022_2023.json
  21. 4
      spec/helpers/tasklist_helper_spec.rb
  22. 12
      spec/models/form/question_spec.rb
  23. 10
      spec/models/form/subsection_spec.rb
  24. 2
      spec/models/form_handler_spec.rb
  25. 16
      spec/models/form_spec.rb
  26. 4
      spec/requests/case_logs_controller_spec.rb

8
app/controllers/form_controller.rb

@ -8,8 +8,12 @@ class FormController < ApplicationController
@page = @case_log.form.get_page(params[:case_log][:page]) @page = @case_log.form.get_page(params[:case_log][:page])
responses_for_page = responses_for_page(@page) responses_for_page = responses_for_page(@page)
if @case_log.update(responses_for_page) && @case_log.has_no_unresolved_soft_errors? if @case_log.update(responses_for_page) && @case_log.has_no_unresolved_soft_errors?
redirect_path = @case_log.form.next_page_redirect_path(@page, @case_log) if @case_log.form.is_last_question?(@page, @case_log.form.subsection_for_page(@page), @case_log)
redirect_to(send(redirect_path, @case_log)) redirect_to(case_logs_path)
else
redirect_path = @case_log.form.next_page_redirect_path(@page, @case_log)
redirect_to(send(redirect_path, @case_log))
end
else else
@subsection = @case_log.form.subsection_for_page(@page) @subsection = @case_log.form.subsection_for_page(@page)
render "form/page", status: :unprocessable_entity render "form/page", status: :unprocessable_entity

3
app/models/bulk_upload.rb

@ -196,8 +196,7 @@ class BulkUpload
intermediate_rent_product_name: row[131], intermediate_rent_product_name: row[131],
# data_protection: row[132], # data_protection: row[132],
sale_or_letting: "letting", sale_or_letting: "letting",
gdpr_acceptance: 1, declaration: 1,
gdpr_declined: 0,
} }
end end

2
app/models/case_log.rb

@ -7,6 +7,7 @@ class CaseLogValidator < ActiveModel::Validator
include Validations::TenancyValidations include Validations::TenancyValidations
include Validations::DateValidations include Validations::DateValidations
include Validations::LocalAuthorityValidations include Validations::LocalAuthorityValidations
include Validations::SubmissionValidations
def validate(record) def validate(record)
validation_methods = public_methods.select { |method| method.starts_with?("validate_") } validation_methods = public_methods.select { |method| method.starts_with?("validate_") }
@ -140,6 +141,7 @@ class CaseLog < ApplicationRecord
enum is_carehome: POLAR, _suffix: true enum is_carehome: POLAR, _suffix: true
enum nocharge: POLAR, _suffix: true enum nocharge: POLAR, _suffix: true
enum referral: REFERRAL, _suffix: true enum referral: REFERRAL, _suffix: true
enum declaration: POLAR, _suffix: true
AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze
OPTIONAL_FIELDS = %w[postcode_known la_known first_time_property_let_as_social_housing].freeze OPTIONAL_FIELDS = %w[postcode_known la_known first_time_property_let_as_social_housing].freeze

7
app/models/form.rb

@ -79,7 +79,7 @@ class Form
next_subsection_id_index = subsection_ids.index(subsection.id) + 1 next_subsection_id_index = subsection_ids.index(subsection.id) + 1
next_subsection = get_subsection(subsection_ids[next_subsection_id_index]) next_subsection = get_subsection(subsection_ids[next_subsection_id_index])
if next_subsection.id == "declaration" && case_log.status != "completed" if subsection.id == "declaration" && case_log.status != "completed"
next_subsection = get_subsection(subsection_ids[0]) next_subsection = get_subsection(subsection_ids[0])
end end
@ -122,4 +122,9 @@ class Form
def readonly_questions def readonly_questions
questions.select(&:read_only?) questions.select(&:read_only?)
end end
def is_last_question?(page, subsection, case_log)
subsection_ids = subsections.map(&:id)
subsection.id == subsection_ids[subsection_ids.length - 1] && next_page(page, case_log) == :check_answers
end
end end

2
app/models/form/question.rb

@ -79,8 +79,6 @@ class Form::Question
end end
def completed?(case_log) 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"
return answer_options.keys.any? { |key| case_log[key] == "Yes" } if type == "checkbox" return answer_options.keys.any? { |key| case_log[key] == "Yes" } if type == "checkbox"
case_log[id].present? || !case_log.respond_to?(id.to_sym) || has_inferred_display_value?(case_log) case_log[id].present? || !case_log.respond_to?(id.to_sym) || has_inferred_display_value?(case_log)

10
app/models/validations/submission_validations.rb

@ -0,0 +1,10 @@
module Validations::SubmissionValidations
# Validations methods need to be called 'validate_<page_name>' to run on model save
# or 'validate_' to run on submit as well
def validate_declaration(record)
if record.declaration == "No"
record.errors.add :declaration, I18n.t("validations.declaration.missing")
end
end
end

14
app/views/case_logs/edit.html.erb

@ -21,12 +21,14 @@
<% next_incomplete_section = get_next_incomplete_section(@case_log) %> <% next_incomplete_section = get_next_incomplete_section(@case_log) %>
</p> </p>
<p> <p>
<a class="app-section-skip-link" href="#<%= next_incomplete_section.id %>" <% if next_incomplete_section.present? %>
data-controller="tasklist" <a class="app-section-skip-link" href="#<%= next_incomplete_section.id %>"
data-action="tasklist#addHighlight" data-controller="tasklist"
data-info=<%= next_incomplete_section.id %>> data-action="tasklist#addHighlight"
Skip to next incomplete section: <%= next_incomplete_section.label %> data-info=<%= next_incomplete_section.id %>>
</a> Skip to next incomplete section: <%= next_incomplete_section.label %>
</a>
<% end %>
</p> </p>
<%= render "tasklist" %> <%= render "tasklist" %>
</div> </div>

6
app/views/form/page.html.erb

@ -47,7 +47,11 @@
<% end %> <% end %>
<%= f.hidden_field :page, value: @page.id %> <%= f.hidden_field :page, value: @page.id %>
<%= f.govuk_submit "Save and continue" %> <% if @case_log.form.is_last_question?(@page, @subsection, @case_log) %>
<%= f.govuk_submit "Submit lettings log" %>
<%else %>
<%= f.govuk_submit "Save and continue" %>
<%end %>
</div> </div>
</div> </div>
<% end %> <% end %>

57
config/forms/2021_2022.json

@ -9,30 +9,6 @@
"setup": { "setup": {
"label": "Set up your lettings log", "label": "Set up your lettings log",
"pages": { "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": {
"hide_subsection_label": true,
"header": "You cannot use this service",
"hint_text": "",
"description": "We cannot accept data about a tenant or buyer unless they’ve seen the <a class=\"govuk-link\" href=\"/files/privacy-notice.pdf\">DLUHC privacy notice</a>.<br /><br /><a class=\"govuk-link\" href=\"/logs\">Go to your logs</a>",
"questions": {},
"depends_on": [{ "gdpr_acceptance": "No" }]
},
"organisation_details": { "organisation_details": {
"header": "Organisation details", "header": "Organisation details",
"description": "", "description": "",
@ -57,8 +33,7 @@
"1": "B" "1": "B"
} }
} }
}, }
"depends_on": [{ "gdpr_acceptance": "Yes" }]
}, },
"renewal": { "renewal": {
"header": "", "header": "",
@ -74,10 +49,7 @@
"0": "No" "0": "No"
} }
} }
}, }
"depends_on": [{
"gdpr_acceptance": "Yes"
}]
}, },
"startdate": { "startdate": {
"header": "", "header": "",
@ -89,10 +61,7 @@
"hint_text": "For example, 27 3 2021.", "hint_text": "For example, 27 3 2021.",
"type": "date" "type": "date"
} }
}, }
"depends_on": [{
"gdpr_acceptance": "Yes"
}]
}, },
"about_this_letting": { "about_this_letting": {
"header": "Tell us about this letting", "header": "Tell us about this letting",
@ -132,10 +101,7 @@
"0": "Supported housing" "0": "Supported housing"
} }
} }
}, }
"depends_on": [{
"gdpr_acceptance": "Yes"
}]
}, },
"tenant_code": { "tenant_code": {
"header": "", "header": "",
@ -148,10 +114,7 @@
"type": "text", "type": "text",
"width": 10 "width": 10
} }
}, }
"depends_on": [{
"gdpr_acceptance": "Yes"
}]
}, },
"property_reference": { "property_reference": {
"header": "", "header": "",
@ -164,8 +127,7 @@
"type": "text", "type": "text",
"width": 10 "width": 10
} }
}, }
"depends_on": [{ "gdpr_acceptance": "Yes" }]
} }
} }
} }
@ -3226,9 +3188,12 @@
"questions": { "questions": {
"declaration": { "declaration": {
"check_answer_label": "", "check_answer_label": "",
"header": "What is the tenant code?", "header": "Submit your lettings log ",
"hint_text": "", "hint_text": "",
"type": "text" "type": "checkbox",
"answer_options": {
"declaration": "The tenant has seen the Department for Levelling Up, Housing & Communities (DLUHC) privacy notice"
}
} }
} }
} }

3
config/locales/en.yml

@ -115,6 +115,9 @@ en:
referral: referral:
rsnvac_non_temp: "Answer cannot be this source of referral as you already told us this is a re-let to tenant who occupied the same property as temporary accommodation" rsnvac_non_temp: "Answer cannot be this source of referral as you already told us this is a re-let to tenant who occupied the same property as temporary accommodation"
declaration:
missing: "You must show the DLUHC privacy notice to the tenant before you can submit this log."
soft_validations: soft_validations:
net_income: net_income:
hint_text: "This is based on the tenant’s work situation: %{ecstat1}" hint_text: "This is based on the tenant’s work situation: %{ecstat1}"

7
db/migrate/20220207091117_add_declaration.rb

@ -0,0 +1,7 @@
class AddDeclaration < ActiveRecord::Migration[7.0]
def change
change_table :case_logs, bulk: true do |t|
t.column :declaration, :integer
end
end
end

15
db/migrate/20220208101235_remove_gdpr_fields.rb

@ -0,0 +1,15 @@
class RemoveGdprFields < ActiveRecord::Migration[7.0]
def up
change_table :case_logs, bulk: true do |t|
t.remove :gdpr_declined
t.remove :gdpr_acceptance
end
end
def down
change_table :case_logs, bulk: true do |t|
t.column :gdpr_declined, :string
t.column :gdpr_acceptance, :string
end
end
end

6
db/schema.rb

@ -10,7 +10,8 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2022_02_07_1123100) do ActiveRecord::Schema.define(version: 202202071123100) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -129,8 +130,6 @@ ActiveRecord::Schema.define(version: 2022_02_07_1123100) do
t.datetime "discarded_at" t.datetime "discarded_at"
t.string "tenancyother" t.string "tenancyother"
t.integer "override_net_income_validation" t.integer "override_net_income_validation"
t.string "gdpr_acceptance"
t.string "gdpr_declined"
t.string "property_owner_organisation" t.string "property_owner_organisation"
t.string "property_manager_organisation" t.string "property_manager_organisation"
t.string "sale_or_letting" t.string "sale_or_letting"
@ -192,6 +191,7 @@ ActiveRecord::Schema.define(version: 2022_02_07_1123100) do
t.decimal "tcharge", precision: 10, scale: 2 t.decimal "tcharge", precision: 10, scale: 2
t.decimal "tshortfall", precision: 10, scale: 2 t.decimal "tshortfall", precision: 10, scale: 2
t.decimal "chcharge", precision: 10, scale: 2 t.decimal "chcharge", precision: 10, scale: 2
t.integer "declaration"
t.index ["discarded_at"], name: "index_case_logs_on_discarded_at" t.index ["discarded_at"], name: "index_case_logs_on_discarded_at"
t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id" t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id"
t.index ["owning_organisation_id"], name: "index_case_logs_on_owning_organisation_id" t.index ["owning_organisation_id"], name: "index_case_logs_on_owning_organisation_id"

4
spec/factories/case_log.rb

@ -3,7 +3,6 @@ FactoryBot.define do
owning_organisation { FactoryBot.create(:organisation) } owning_organisation { FactoryBot.create(:organisation) }
managing_organisation { FactoryBot.create(:organisation) } managing_organisation { FactoryBot.create(:organisation) }
trait :about_completed do trait :about_completed do
gdpr_acceptance { "Yes" }
renewal { "No" } renewal { "No" }
needstype { 1 } needstype { 1 }
rent_type { 1 } rent_type { 1 }
@ -112,8 +111,6 @@ FactoryBot.define do
tenancyother { nil } tenancyother { nil }
override_net_income_validation { nil } override_net_income_validation { nil }
net_income_known { "Weekly" } net_income_known { "Weekly" }
gdpr_acceptance { "Yes" }
gdpr_declined { "No" }
property_owner_organisation { "Test" } property_owner_organisation { "Test" }
property_manager_organisation { "Test" } property_manager_organisation { "Test" }
renewal { 1 } renewal { 1 }
@ -152,6 +149,7 @@ FactoryBot.define do
chcharge { 7 } chcharge { 7 }
letting_in_sheltered_accomodation { "No" } letting_in_sheltered_accomodation { "No" }
la_known { "Yes" } la_known { "Yes" }
declaration { "Yes" }
end end
created_at { Time.zone.now } created_at { Time.zone.now }
updated_at { Time.zone.now } updated_at { Time.zone.now }

2
spec/features/form/check_answers_page_spec.rb

@ -209,7 +209,7 @@ RSpec.describe "Form Check Answers Page" do
end end
it "they can click a button to cycle around to the next incomplete section" do it "they can click a button to cycle around to the next incomplete section" do
visit("/logs/#{cycle_sections_case_log.id}/setup/check-answers") visit("/logs/#{cycle_sections_case_log.id}/declaration/check-answers")
click_link("Save and go to next incomplete section") click_link("Save and go to next incomplete section")
expect(page).to have_current_path("/logs/#{cycle_sections_case_log.id}/tenant-code") expect(page).to have_current_path("/logs/#{cycle_sections_case_log.id}/tenant-code")
end end

4
spec/features/form/tasklist_page_spec.rb

@ -33,12 +33,12 @@ RSpec.describe "Task List" do
it "shows the number of completed sections if no sections are completed" do it "shows the number of completed sections if no sections are completed" do
visit("/logs/#{empty_case_log.id}") visit("/logs/#{empty_case_log.id}")
expect(page).to have_content("You have completed 0 of 10 sections.") expect(page).to have_content("You have completed 0 of 9 sections.")
end end
it "shows the number of completed sections if one section is completed" do it "shows the number of completed sections if one section is completed" do
answer_all_questions_in_income_subsection(empty_case_log) answer_all_questions_in_income_subsection(empty_case_log)
visit("/logs/#{empty_case_log.id}") visit("/logs/#{empty_case_log.id}")
expect(page).to have_content("You have completed 1 of 10 sections.") expect(page).to have_content("You have completed 1 of 9 sections.")
end end
end end

31
spec/features/form/validations_spec.rb

@ -25,6 +25,16 @@ RSpec.describe "validations" do
managing_organisation: user.organisation, managing_organisation: user.organisation,
) )
end end
let(:completed_without_declaration) do
FactoryBot.create(
:case_log,
:completed,
owning_organisation: user.organisation,
managing_organisation: user.organisation,
status: 1,
declaration: nil,
)
end
let(:id) { case_log.id } let(:id) { case_log.id }
describe "Question validation" do describe "Question validation" do
@ -162,4 +172,25 @@ RSpec.describe "validations" do
end end
end end
end end
describe "Submission validation" do
context "when tenant has not seen the privacy notice" do
it "shows a warning" do
visit("/logs/#{completed_without_declaration.id}/declaration")
expect(page).to have_current_path("/logs/#{completed_without_declaration.id}/declaration")
click_button("Submit lettings log")
expect(page).to have_content("You must show the DLUHC privacy notice to the tenant")
end
end
context "when tenant has seen the privacy notice" do
it "lets submit the log" do
completed_without_declaration.update!({ declaration: "Yes" })
visit("/logs/#{completed_without_declaration.id}/declaration")
expect(page).to have_current_path("/logs/#{completed_without_declaration.id}/declaration")
click_button("Submit lettings log")
expect(page).to have_current_path("/logs")
end
end
end
end end

5
spec/fixtures/complete_case_log.json vendored

@ -122,8 +122,6 @@
"rp_dontknow": "No", "rp_dontknow": "No",
"discarded_at": "05/05/2020", "discarded_at": "05/05/2020",
"override_net_income_validation": "", "override_net_income_validation": "",
"gdpr_acceptance": "",
"gdpr_declined": "",
"property_owner_organisation": "", "property_owner_organisation": "",
"property_manager_organisation": "", "property_manager_organisation": "",
"rent_type": "Social Rent", "rent_type": "Social Rent",
@ -147,6 +145,7 @@
"household_charge": "Yes", "household_charge": "Yes",
"is_carehome": "Yes", "is_carehome": "Yes",
"chcharge": "6", "chcharge": "6",
"letting_in_sheltered_accomodation": "No" "letting_in_sheltered_accomodation": "No",
"declaration": "Yes"
} }
} }

39
spec/fixtures/forms/2021_2022.json vendored

@ -626,32 +626,6 @@
} }
} }
}, },
"setup": {
"label": "Before you start",
"subsections": {
"setup": {
"label": "Set up your lettings 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"
}
}
}
}
}
}
}
},
"submission": { "submission": {
"label": "Submission", "label": "Submission",
"subsections": { "subsections": {
@ -661,19 +635,18 @@
"household_characteristics": "completed", "household_characteristics": "completed",
"household_needs": "completed", "household_needs": "completed",
"tenancy_information": "completed", "tenancy_information": "completed",
"property_information": "completed", "property_information": "completed"
"income_and_benefits": "completed",
"rent_and_charges": "completed",
"local_authority": "completed"
}], }],
"pages": { "pages": {
"declaration": { "declaration": {
"questions": { "questions": {
"declaration": { "declaration": {
"check_answer_label": "", "check_answer_label": "",
"header": "What is the tenant code?", "header": "Submit your lettings log ",
"type": "text", "type": "checkbox",
"width": 10 "answer_options": {
"declaration": "The tenant has seen the Department for Levelling Up, Housing & Communities (DLUHC) privacy notice"
}
} }
} }
} }

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

@ -7,30 +7,6 @@
"setup": { "setup": {
"label": "Set up your lettings log", "label": "Set up your lettings log",
"pages": { "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" }]
},
"renewal": { "renewal": {
"header": "", "header": "",
"description": "", "description": "",
@ -45,10 +21,7 @@
"0": "No" "0": "No"
} }
} }
}, }
"depends_on": [{
"gdpr_acceptance": "Yes"
}]
}, },
"startdate": { "startdate": {
"header": "", "header": "",
@ -60,10 +33,7 @@
"hint_text": "For example, 27 3 2007", "hint_text": "For example, 27 3 2007",
"type": "date" "type": "date"
} }
}, }
"depends_on": [{
"gdpr_acceptance": "Yes"
}]
}, },
"about_this_letting": { "about_this_letting": {
"header": "Tell us about this letting", "header": "Tell us about this letting",
@ -101,10 +71,7 @@
"1": "General needs" "1": "General needs"
} }
} }
}, }
"depends_on": [{
"gdpr_acceptance": "Yes"
}]
} }
} }
} }

4
spec/helpers/tasklist_helper_spec.rb

@ -22,7 +22,7 @@ RSpec.describe TasklistHelper do
describe "get sections count" do describe "get sections count" do
it "returns the total of sections if no status is given" do it "returns the total of sections if no status is given" do
expect(get_subsections_count(empty_case_log)).to eq(10) expect(get_subsections_count(empty_case_log)).to eq(9)
end end
it "returns 0 sections for completed sections if no sections are completed" do it "returns 0 sections for completed sections if no sections are completed" do
@ -30,7 +30,7 @@ RSpec.describe TasklistHelper do
end end
it "returns the number of not started sections" do it "returns the number of not started sections" do
expect(get_subsections_count(empty_case_log, :not_started)).to eq(9) expect(get_subsections_count(empty_case_log, :not_started)).to eq(8)
end end
it "returns the number of sections in progress" do it "returns the number of sections in progress" do

12
spec/models/form/question_spec.rb

@ -169,17 +169,5 @@ RSpec.describe Form::Question, type: :model do
expect(question.completed?(case_log)).to be(true) expect(question.completed?(case_log)).to be(true)
end end
end end
context "when the gdpr acceptance is No" do
let(:section_id) { "setup" }
let(:subsection_id) { "setup" }
let(:page_id) { "gdpr_acceptance" }
let(:question_id) { "gdpr_acceptance" }
it "returns false" do
case_log["gdpr_acceptance"] = "No"
expect(question.completed?(case_log)).to be(false)
end
end
end end
end end

10
spec/models/form/subsection_spec.rb

@ -77,16 +77,6 @@ RSpec.describe Form::Subsection, type: :model do
end end
end end
context "when the privacy notice has not been shown" do
let(:section_id) { "setup" }
let(:subsection_id) { "setup" }
let(:case_log) { FactoryBot.build(:case_log, :about_completed, gdpr_acceptance: "No") }
it "does not mark the section as completed" do
expect(sub_section.status(case_log)).to eq(:in_progress)
end
end
context "with a completed case log" do context "with a completed case log" do
let(:case_log) { FactoryBot.build(:case_log, :completed) } let(:case_log) { FactoryBot.build(:case_log, :completed) }

2
spec/models/form_handler_spec.rb

@ -17,7 +17,7 @@ RSpec.describe FormHandler do
form_handler = described_class.instance form_handler = described_class.instance
form = form_handler.get_form(test_form_name) form = form_handler.get_form(test_form_name)
expect(form).to be_a(Form) expect(form).to be_a(Form)
expect(form.pages.count).to eq(29) expect(form.pages.count).to eq(28)
end end
end end

16
spec/models/form_spec.rb

@ -36,7 +36,7 @@ RSpec.describe Form, type: :model do
describe "next_incomplete_section_redirect_path" do describe "next_incomplete_section_redirect_path" do
let(:case_log) { FactoryBot.build(:case_log, :in_progress) } let(:case_log) { FactoryBot.build(:case_log, :in_progress) }
let(:subsection) { form.get_subsection("household_characteristics") } let(:subsection) { form.get_subsection("household_characteristics") }
let(:later_subsection) { form.get_subsection("setup") } let(:later_subsection) { form.get_subsection("declaration") }
context "when a user is on the check answers page for a subsection" do context "when a user is on the check answers page for a subsection" do
def answer_household_needs(case_log) def answer_household_needs(case_log)
@ -85,10 +85,6 @@ RSpec.describe Form, type: :model do
case_log.mrcdate = Time.zone.parse("03/11/2019") case_log.mrcdate = Time.zone.parse("03/11/2019")
end end
def answer_local_gdpr_acceptance(case_log)
case_log.gdpr_acceptance = "Yes"
end
before do before do
case_log.tenant_code = "123" case_log.tenant_code = "123"
case_log.age1 = 35 case_log.age1 = 35
@ -111,15 +107,14 @@ RSpec.describe Form, type: :model do
expect(form.next_incomplete_section_redirect_path(subsection, case_log)).to eq("tenancy-code") expect(form.next_incomplete_section_redirect_path(subsection, case_log)).to eq("tenancy-code")
end end
it "returns the next incomplete section by cycling back around if next subsections are completed" do
answer_local_gdpr_acceptance(case_log)
expect(form.next_incomplete_section_redirect_path(later_subsection, case_log)).to eq("armed-forces")
end
it "returns the declaration section for a completed case log" do it "returns the declaration section for a completed case log" do
expect(form.next_incomplete_section_redirect_path(subsection, completed_case_log)).to eq("declaration") expect(form.next_incomplete_section_redirect_path(subsection, completed_case_log)).to eq("declaration")
end end
it "returns the next incomplete section by cycling back around if next subsections are completed" do
expect(form.next_incomplete_section_redirect_path(later_subsection, case_log)).to eq("armed-forces")
end
it "returns the declaration section if all sections are complete but the case log is in progress" do it "returns the declaration section if all sections are complete but the case log is in progress" do
answer_household_needs(case_log) answer_household_needs(case_log)
answer_tenancy_information(case_log) answer_tenancy_information(case_log)
@ -128,7 +123,6 @@ RSpec.describe Form, type: :model do
answer_income_and_benefits(case_log) answer_income_and_benefits(case_log)
answer_rent_and_charges(case_log) answer_rent_and_charges(case_log)
answer_local_authority(case_log) answer_local_authority(case_log)
answer_local_gdpr_acceptance(case_log)
expect(form.next_incomplete_section_redirect_path(subsection, case_log)).to eq("declaration") expect(form.next_incomplete_section_redirect_path(subsection, case_log)).to eq("declaration")
end end

4
spec/requests/case_logs_controller_spec.rb

@ -200,7 +200,7 @@ RSpec.describe CaseLogsController, type: :request do
end end
it "displays a section status for a case log" do it "displays a section status for a case log" do
assert_select ".govuk-tag", text: /Not started/, count: 9 assert_select ".govuk-tag", text: /Not started/, count: 8
assert_select ".govuk-tag", text: /Completed/, count: 0 assert_select ".govuk-tag", text: /Completed/, count: 0
assert_select ".govuk-tag", text: /Cannot start yet/, count: 1 assert_select ".govuk-tag", text: /Cannot start yet/, count: 1
end end
@ -222,7 +222,7 @@ RSpec.describe CaseLogsController, type: :request do
end end
it "displays a section status for a case log" do it "displays a section status for a case log" do
assert_select ".govuk-tag", text: /Not started/, count: 8 assert_select ".govuk-tag", text: /Not started/, count: 7
assert_select ".govuk-tag", text: /Completed/, count: 1 assert_select ".govuk-tag", text: /Completed/, count: 1
assert_select ".govuk-tag", text: /Cannot start yet/, count: 1 assert_select ".govuk-tag", text: /Cannot start yet/, count: 1
end end

Loading…
Cancel
Save