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"
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(:form) { case_log.form }
@ -12,91 +12,91 @@ RSpec.describe Form::Subsection, type: :model do
let(:subsection_definition) { section_definition["subsections"][subsection_id] }
it "has an id" do
expect(subject.id).to eq(subsection_id)
expect(sub_section.id).to eq(subsection_id)
end
it "has a label" do
expect(subject.label).to eq("Household characteristics")
expect(sub_section.label).to eq("Household characteristics")
end
it "has pages" do
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
it "has questions" do
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
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) }
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
it "has a completed status for completed subsection" do
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.illness = "No"
case_log.housingneeds_a = "Yes"
case_log.la = "York"
case_log.illness_type_1 = "Yes"
expect(subject.status(case_log)).to eq(:completed)
expect(sub_section.status(case_log)).to eq(:completed)
end
it "has status helpers" do
expect(subject.is_incomplete?(case_log)).to be(true)
expect(subject.is_started?(case_log)).to be(true)
expect(sub_section.is_incomplete?(case_log)).to be(true)
expect(sub_section.is_started?(case_log)).to be(true)
end
it "has question helpers for the number of applicable questions" do
expected_questions = %w[tenant_code age1 sex1 other_hhmemb]
expect(subject.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(case_log).map(&:id)).to eq(expected_questions)
expect(sub_section.applicable_questions_count(case_log)).to eq(4)
end
it "has question helpers for the number of answered questions" do
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]
case_log.armedforces = "No"
case_log.illness = "No"
case_log.housingneeds_a = "Yes"
case_log.la = "York"
case_log.illness_type_1 = "Yes"
expect(subject.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(case_log).map(&:id)).to eq(expected_questions)
expect(sub_section.answered_questions_count(case_log)).to eq(5)
end
it "has a question helpers for the unanswered questions" do
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
context "the privacy notice has not been shown" do
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(subject.status(case_log)).to eq(:in_progress)
expect(sub_section.status(case_log)).to eq(:in_progress)
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) }
it "has a status" do
expect(subject.status(case_log)).to eq(:completed)
expect(sub_section.status(case_log)).to eq(:completed)
end
it "has status helpers" do
expect(subject.is_incomplete?(case_log)).to be(false)
expect(subject.is_started?(case_log)).to be(true)
expect(sub_section.is_incomplete?(case_log)).to be(false)
expect(sub_section.is_started?(case_log)).to be(true)
end
end
end

4
spec/models/form_spec.rb

@ -34,7 +34,7 @@ RSpec.describe Form, type: :model do
end
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] }
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
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] }
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)
end
context "case logs" do
context "with case logs" do
let(:other_organisation) { FactoryBot.create(:organisation) }
let!(:owned_case_log) do
FactoryBot.create(

Loading…
Cancel
Save