Browse Source

Fix intermittent spec failure

pull/442/head
baarkerlounger 3 years ago
parent
commit
fcc7c14efb
  1. 43
      spec/models/form/subsection_spec.rb
  2. 4
      spec/models/organisation_spec.rb
  3. 3
      spec/services/exports/case_log_export_service_spec.rb

43
spec/models/form/subsection_spec.rb

@ -2,7 +2,7 @@ require "rails_helper"
require_relative "../../request_helper" require_relative "../../request_helper"
RSpec.describe Form::Subsection, type: :model do RSpec.describe Form::Subsection, type: :model do
subject(:sub_section) { described_class.new(subsection_id, subsection_definition, section) } subject(:subsection) { 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 }
@ -17,55 +17,55 @@ RSpec.describe Form::Subsection, type: :model do
end end
it "has an id" do it "has an id" do
expect(sub_section.id).to eq(subsection_id) expect(subsection.id).to eq(subsection_id)
end end
it "has a label" do it "has a label" do
expect(sub_section.label).to eq("Household characteristics") expect(subsection.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 person_1_working_situation household_number_of_other_members propcode] expected_pages = %w[tenant_code person_1_age person_1_gender person_1_working_situation household_number_of_other_members propcode]
expect(sub_section.pages.map(&:id)).to eq(expected_pages) expect(subsection.pages.map(&:id)).to eq(expected_pages)
end end
it "has questions" do it "has questions" do
expected_questions = %w[tenant_code age1 sex1 ecstat1 other_hhmemb relat2 age2 sex2 ecstat2 propcode] expected_questions = %w[tenant_code age1 sex1 ecstat1 other_hhmemb relat2 age2 sex2 ecstat2 propcode]
expect(sub_section.questions.map(&:id)).to eq(expected_questions) expect(subsection.questions.map(&:id)).to eq(expected_questions)
end end
context "with an 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(sub_section.status(case_log)).to eq(:in_progress) expect(subsection.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"]
sub_section = described_class.new("household_needs", subsection_definition, section) subsection = described_class.new("household_needs", subsection_definition, section)
case_log.armedforces = 3 case_log.armedforces = 3
case_log.illness = 1 case_log.illness = 1
case_log.housingneeds_a = 1 case_log.housingneeds_a = 1
case_log.la = "E06000014" case_log.la = "E06000014"
case_log.illness_type_1 = 1 case_log.illness_type_1 = 1
expect(sub_section.status(case_log)).to eq(:completed) expect(subsection.status(case_log)).to eq(:completed)
end end
it "has status helpers" do it "has status helpers" do
expect(sub_section.is_incomplete?(case_log)).to be(true) expect(subsection.is_incomplete?(case_log)).to be(true)
expect(sub_section.is_started?(case_log)).to be(true) expect(subsection.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 ecstat1 other_hhmemb propcode] expected_questions = %w[tenant_code age1 sex1 ecstat1 other_hhmemb propcode]
expect(sub_section.applicable_questions(case_log).map(&:id)).to eq(expected_questions) expect(subsection.applicable_questions(case_log).map(&:id)).to eq(expected_questions)
expect(sub_section.applicable_questions_count(case_log)).to eq(6) expect(subsection.applicable_questions_count(case_log)).to eq(6)
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"]
sub_section = described_class.new("household_needs", subsection_definition, section) subsection = 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 = 3 case_log.armedforces = 3
case_log.illness = 1 case_log.illness = 1
@ -74,33 +74,32 @@ RSpec.describe Form::Subsection, type: :model do
case_log.is_la_inferred = false case_log.is_la_inferred = false
case_log.la = "E06000014" case_log.la = "E06000014"
case_log.illness_type_1 = 1 case_log.illness_type_1 = 1
expect(sub_section.answered_questions(case_log).map(&:id)).to eq(expected_questions) expect(subsection.answered_questions(case_log).map(&:id)).to eq(expected_questions)
expect(sub_section.answered_questions_count(case_log)).to eq(5) expect(subsection.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 ecstat1 other_hhmemb propcode] expected_questions = %w[sex1 ecstat1 other_hhmemb propcode]
expect(sub_section.unanswered_questions(case_log).map(&:id)).to eq(expected_questions) expect(subsection.unanswered_questions(case_log).map(&:id)).to eq(expected_questions)
end end
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(:completed_case_log) { FactoryBot.build(:case_log, :completed) }
let(:case_log_too) { FactoryBot.build(:case_log, :in_progress) }
it "has a status" do it "has a status" do
expect(sub_section.status(case_log)).to eq(:completed) expect(subsection.status(completed_case_log)).to eq(:completed)
end end
it "has a status when optional fields are not filled" do it "has a status when optional fields are not filled" do
case_log.update!({ propcode: nil }) case_log.update!({ propcode: nil })
case_log.reload case_log.reload
expect(sub_section.status(case_log)).to eq(:completed) expect(subsection.status(completed_case_log)).to eq(:completed)
end end
it "has status helpers" do it "has status helpers" do
expect(sub_section.is_incomplete?(case_log)).to be(false) expect(subsection.is_incomplete?(completed_case_log)).to be(false)
expect(sub_section.is_started?(case_log)).to be(true) expect(subsection.is_started?(completed_case_log)).to be(true)
end end
end end
end end

4
spec/models/organisation_spec.rb

@ -20,8 +20,8 @@ RSpec.describe Organisation, type: :model do
context "with data protection confirmations" do context "with data protection confirmations" do
before do before do
FactoryBot.create(:data_protection_confirmation, organisation:, confirmed: false) FactoryBot.create(:data_protection_confirmation, organisation:, confirmed: false, created_at: Time.utc(2018, 0o6, 0o5, 10, 36, 49))
FactoryBot.create(:data_protection_confirmation, organisation:) FactoryBot.create(:data_protection_confirmation, organisation:, created_at: Time.utc(2019, 0o6, 0o5, 10, 36, 49))
end end
it "takes the most recently created" do it "takes the most recently created" do

3
spec/services/exports/case_log_export_service_spec.rb

@ -5,7 +5,7 @@ RSpec.describe Exports::CaseLogExportService do
let(:export_filepath) { "spec/fixtures/exports/case_logs.xml" } let(:export_filepath) { "spec/fixtures/exports/case_logs.xml" }
let(:export_file) { File.open(export_filepath, "r:UTF-8") } let(:export_file) { File.open(export_filepath, "r:UTF-8") }
let(:expected_filename) { "core_2022_02_08/dat_core_2022_02_08_0001.xml" } let(:expected_filename) { "core_2022_02_08/dat_core_2022_02_08_0001.xml" }
let(:case_log) { FactoryBot.create(:case_log, :completed) } let!(:case_log) { FactoryBot.create(:case_log, :completed) }
def replace_entity_ids(export_template) def replace_entity_ids(export_template)
export_template.sub!(/\{id\}/, case_log["id"].to_s) export_template.sub!(/\{id\}/, case_log["id"].to_s)
@ -18,7 +18,6 @@ RSpec.describe Exports::CaseLogExportService do
before do before do
Timecop.freeze(Time.new(2022, 2, 8, 16, 52, 15, "+00:00")) Timecop.freeze(Time.new(2022, 2, 8, 16, 52, 15, "+00:00"))
case_log
end end
it "generate an XML export file with the expected filename" do it "generate an XML export file with the expected filename" do

Loading…
Cancel
Save