Browse Source

Push fixes #9

pull/264/head
Stéphane Meny 3 years ago
parent
commit
4d1f0868e6
No known key found for this signature in database
GPG Key ID: 9D0AFEA988527923
  1. 46
      spec/models/form/subsection_spec.rb
  2. 4
      spec/models/form_spec.rb
  3. 2
      spec/models/organisation_spec.rb

46
spec/models/form/subsection_spec.rb

@ -1,7 +1,7 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Subsection, type: :model do RSpec.describe Form::Subsection, type: :model do
subject { described_class.new(subsection_id, subsection_definition, section) } subject(:sub_section) { described_class.new(subsection_id, subsection_definition, section) }
let(:case_log) { FactoryBot.build(:case_log) } let(:case_log) { FactoryBot.build(:case_log) }
let(:form) { case_log.form } let(:form) { case_log.form }
@ -12,91 +12,91 @@ RSpec.describe Form::Subsection, type: :model do
let(:subsection_definition) { section_definition["subsections"][subsection_id] } let(:subsection_definition) { section_definition["subsections"][subsection_id] }
it "has an id" do it "has an id" do
expect(subject.id).to eq(subsection_id) expect(sub_section.id).to eq(subsection_id)
end end
it "has a label" do it "has a label" do
expect(subject.label).to eq("Household characteristics") expect(sub_section.label).to eq("Household characteristics")
end end
it "has pages" do it "has pages" do
expected_pages = %w[tenant_code person_1_age person_1_gender household_number_of_other_members] expected_pages = %w[tenant_code person_1_age person_1_gender household_number_of_other_members]
expect(subject.pages.map(&:id)).to eq(expected_pages) expect(sub_section.pages.map(&:id)).to eq(expected_pages)
end end
it "has questions" do it "has questions" do
expected_questions = %w[tenant_code age1 sex1 other_hhmemb relat2 age2 sex2 ecstat2] expected_questions = %w[tenant_code age1 sex1 other_hhmemb relat2 age2 sex2 ecstat2]
expect(subject.questions.map(&:id)).to eq(expected_questions) expect(sub_section.questions.map(&:id)).to eq(expected_questions)
end end
context "for a given in progress case log" do context "with an in progress case log" do
let(:case_log) { FactoryBot.build(:case_log, :in_progress) } let(:case_log) { FactoryBot.build(:case_log, :in_progress) }
it "has a status" do it "has a status" do
expect(subject.status(case_log)).to eq(:in_progress) expect(sub_section.status(case_log)).to eq(:in_progress)
end end
it "has a completed status for completed subsection" do it "has a completed status for completed subsection" do
subsection_definition = section_definition["subsections"]["household_needs"] subsection_definition = section_definition["subsections"]["household_needs"]
subject = described_class.new("household_needs", subsection_definition, section) sub_section = described_class.new("household_needs", subsection_definition, section)
case_log.armedforces = "No" case_log.armedforces = "No"
case_log.illness = "No" case_log.illness = "No"
case_log.housingneeds_a = "Yes" case_log.housingneeds_a = "Yes"
case_log.la = "York" case_log.la = "York"
case_log.illness_type_1 = "Yes" case_log.illness_type_1 = "Yes"
expect(subject.status(case_log)).to eq(:completed) expect(sub_section.status(case_log)).to eq(:completed)
end end
it "has status helpers" do it "has status helpers" do
expect(subject.is_incomplete?(case_log)).to be(true) expect(sub_section.is_incomplete?(case_log)).to be(true)
expect(subject.is_started?(case_log)).to be(true) expect(sub_section.is_started?(case_log)).to be(true)
end end
it "has question helpers for the number of applicable questions" do it "has question helpers for the number of applicable questions" do
expected_questions = %w[tenant_code age1 sex1 other_hhmemb] expected_questions = %w[tenant_code age1 sex1 other_hhmemb]
expect(subject.applicable_questions(case_log).map(&:id)).to eq(expected_questions) expect(sub_section.applicable_questions(case_log).map(&:id)).to eq(expected_questions)
expect(subject.applicable_questions_count(case_log)).to eq(4) expect(sub_section.applicable_questions_count(case_log)).to eq(4)
end end
it "has question helpers for the number of answered questions" do it "has question helpers for the number of answered questions" do
subsection_definition = section_definition["subsections"]["household_needs"] subsection_definition = section_definition["subsections"]["household_needs"]
subject = described_class.new("household_needs", subsection_definition, section) sub_section = described_class.new("household_needs", subsection_definition, section)
expected_questions = %w[armedforces illness accessibility_requirements la condition_effects] expected_questions = %w[armedforces illness accessibility_requirements la condition_effects]
case_log.armedforces = "No" case_log.armedforces = "No"
case_log.illness = "No" case_log.illness = "No"
case_log.housingneeds_a = "Yes" case_log.housingneeds_a = "Yes"
case_log.la = "York" case_log.la = "York"
case_log.illness_type_1 = "Yes" case_log.illness_type_1 = "Yes"
expect(subject.answered_questions(case_log).map(&:id)).to eq(expected_questions) expect(sub_section.answered_questions(case_log).map(&:id)).to eq(expected_questions)
expect(subject.answered_questions_count(case_log)).to eq(5) expect(sub_section.answered_questions_count(case_log)).to eq(5)
end end
it "has a question helpers for the unanswered questions" do it "has a question helpers for the unanswered questions" do
expected_questions = %w[sex1 other_hhmemb] expected_questions = %w[sex1 other_hhmemb]
expect(subject.unanswered_questions(case_log).map(&:id)).to eq(expected_questions) expect(sub_section.unanswered_questions(case_log).map(&:id)).to eq(expected_questions)
end end
end end
context "the privacy notice has not been shown" do context "when the privacy notice has not been shown" do
let(:section_id) { "setup" } let(:section_id) { "setup" }
let(:subsection_id) { "setup" } let(:subsection_id) { "setup" }
let(:case_log) { FactoryBot.build(:case_log, :about_completed, gdpr_acceptance: "No") } let(:case_log) { FactoryBot.build(:case_log, :about_completed, gdpr_acceptance: "No") }
it "does not mark the section as completed" do it "does not mark the section as completed" do
expect(subject.status(case_log)).to eq(:in_progress) expect(sub_section.status(case_log)).to eq(:in_progress)
end end
end end
context "for a given 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) }
it "has a status" do it "has a status" do
expect(subject.status(case_log)).to eq(:completed) expect(sub_section.status(case_log)).to eq(:completed)
end end
it "has status helpers" do it "has status helpers" do
expect(subject.is_incomplete?(case_log)).to be(false) expect(sub_section.is_incomplete?(case_log)).to be(false)
expect(subject.is_started?(case_log)).to be(true) expect(sub_section.is_started?(case_log)).to be(true)
end end
end end
end end

4
spec/models/form_spec.rb

@ -34,7 +34,7 @@ RSpec.describe Form, type: :model do
end end
describe "invalidated_page_questions" do describe "invalidated_page_questions" do
context "dependencies not met" do context "when dependencies are not met" do
let(:expected_invalid) { %w[la_known cbl conditional_question_no_second_question dependent_question declaration] } let(:expected_invalid) { %w[la_known cbl conditional_question_no_second_question dependent_question declaration] }
it "returns an array of question keys whose pages conditions are not met" do it "returns an array of question keys whose pages conditions are not met" do
@ -42,7 +42,7 @@ RSpec.describe Form, type: :model do
end end
end end
context "two pages with the same question, only one has dependencies met" do context "with two pages having the same question and only one has dependencies met" do
let(:expected_invalid) { %w[la_known conditional_question_no_second_question dependent_question declaration] } let(:expected_invalid) { %w[la_known conditional_question_no_second_question dependent_question declaration] }
it "returns an array of question keys whose pages conditions are not met" do it "returns an array of question keys whose pages conditions are not met" do

2
spec/models/organisation_spec.rb

@ -18,7 +18,7 @@ RSpec.describe Organisation, type: :model do
expect(organisation.users.first).to eq(user) expect(organisation.users.first).to eq(user)
end end
context "case logs" do context "with case logs" do
let(:other_organisation) { FactoryBot.create(:organisation) } let(:other_organisation) { FactoryBot.create(:organisation) }
let!(:owned_case_log) do let!(:owned_case_log) do
FactoryBot.create( FactoryBot.create(

Loading…
Cancel
Save