Browse Source

Time bombing your own specs is a bad time

pull/442/head
baarkerlounger 3 years ago
parent
commit
f1a0931b9f
  1. 20
      spec/factories/case_log.rb
  2. 12
      spec/fixtures/exports/case_logs.xml
  3. 10
      spec/models/form/subsection_spec.rb
  4. 5
      spec/services/exports/case_log_export_service_spec.rb

20
spec/factories/case_log.rb

@ -129,16 +129,16 @@ FactoryBot.define do
ppostc1 { "w3" }
ppostc2 { "w3" }
property_relet { 0 }
mrcdate { Time.zone.now }
mrcday { 5 }
mrcmonth { 5 }
mrcyear { 2020 }
mrcdate { Time.utc(2020, 0o5, 0o5, 10, 36, 49) }
mrcday { mrcdate.day }
mrcmonth { mrcdate.month }
mrcyear { mrcdate.year }
incref { 0 }
sale_completion_date { nil }
startdate { Time.zone.now }
day { Time.zone.now.day }
month { Time.zone.now.month }
year { 2021 }
startdate { Time.utc(2022, 0o2, 0o2, 10, 36, 49) }
day { startdate.day }
month { startdate.month }
year { startdate.year }
armedforces { 0 }
builtype { 1 }
unitletas { 2 }
@ -148,7 +148,7 @@ FactoryBot.define do
la_known { 1 }
declaration { 1 }
end
created_at { Time.zone.now }
updated_at { Time.zone.now }
created_at { Time.utc(2022, 0o2, 8, 16, 52, 15) }
updated_at { Time.utc(2022, 0o2, 8, 16, 52, 15) }
end
end

12
spec/fixtures/exports/case_logs.xml vendored

@ -104,14 +104,14 @@
<ppostc1>SE2</ppostc1>
<ppostc2>6RT</ppostc2>
<property_relet>0</property_relet>
<mrcdate>2022-02-08 16:52:15 UTC</mrcdate>
<mrcday>8</mrcday>
<mrcmonth>2</mrcmonth>
<mrcyear>2022</mrcyear>
<mrcdate>2020-05-05 10:36:49 UTC</mrcdate>
<mrcday>5</mrcday>
<mrcmonth>5</mrcmonth>
<mrcyear>2020</mrcyear>
<other_hhmemb>1</other_hhmemb>
<incref>0</incref>
<sale_completion_date/>
<startdate>2022-02-08 16:52:15 UTC</startdate>
<startdate>2022-02-02 10:36:49 UTC</startdate>
<armedforces>0</armedforces>
<first_time_property_let_as_social_housing/>
<unitletas>2</unitletas>
@ -125,7 +125,7 @@
<postcode_known>1</postcode_known>
<la_known>1</la_known>
<is_la_inferred>false</is_la_inferred>
<day>8</day>
<day>2</day>
<month>2</month>
<year>2022</year>
<totchild>0</totchild>

10
spec/models/form/subsection_spec.rb

@ -85,21 +85,21 @@ RSpec.describe Form::Subsection, type: :model do
end
context "with a completed case log" do
let(:completed_case_log) { FactoryBot.build(:case_log, :completed) }
let(:case_log) { FactoryBot.build(:case_log, :completed) }
it "has a status" do
expect(subsection.status(completed_case_log)).to eq(:completed)
expect(subsection.status(case_log)).to eq(:completed)
end
it "has a status when optional fields are not filled" do
case_log.update!({ propcode: nil })
case_log.reload
expect(subsection.status(completed_case_log)).to eq(:completed)
expect(subsection.status(case_log)).to eq(:completed)
end
it "has status helpers" do
expect(subsection.is_incomplete?(completed_case_log)).to be(false)
expect(subsection.is_started?(completed_case_log)).to be(true)
expect(subsection.is_incomplete?(case_log)).to be(false)
expect(subsection.is_started?(case_log)).to be(true)
end
end
end

5
spec/services/exports/case_log_export_service_spec.rb

@ -5,7 +5,6 @@ RSpec.describe Exports::CaseLogExportService do
let(:export_filepath) { "spec/fixtures/exports/case_logs.xml" }
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!(:case_log) { FactoryBot.create(:case_log, :completed) }
def replace_entity_ids(export_template)
export_template.sub!(/\{id\}/, case_log["id"].to_s)
@ -16,8 +15,10 @@ RSpec.describe Exports::CaseLogExportService do
context "when exporting case logs" do
subject(:export_service) { described_class.new(storage_service) }
let(:case_log) { FactoryBot.create(:case_log, :completed) }
before do
Timecop.freeze(Time.new(2022, 2, 8, 16, 52, 15, "+00:00"))
Timecop.freeze(case_log.updated_at)
end
it "generate an XML export file with the expected filename" do

Loading…
Cancel
Save