Browse Source

Add test for inferring startdate, fix other tests

pull/164/head
MadeTech Dushan 4 years ago
parent
commit
ecfe252f37
  1. 3
      app/models/case_log.rb
  2. 3
      spec/factories/case_log.rb
  3. 3
      spec/fixtures/complete_case_log.json
  4. 11
      spec/models/case_log_spec.rb

3
app/models/case_log.rb

@ -183,6 +183,9 @@ private
self.mrcmonth = mrcdate.month
self.mrcyear = mrcdate.year
end
if day.present? && month.present? && year.present?
self.startdate = Time.zone.local(year, month, day)
end
self.incref = 1 if net_income_known == "Prefer not to say"
self.hhmemb = other_hhmemb + 1 if other_hhmemb.present?
self.renttype = RENT_TYPE_MAPPING[rent_type]

3
spec/factories/case_log.rb

@ -134,6 +134,9 @@ FactoryBot.define do
incref { 0 }
sale_completion_date { nil }
startdate { Time.zone.now }
day { Time.zone.now.day }
month { Time.zone.now.month }
year { Time.zone.now.year }
armedforces { 1 }
builtype { 1 }
unitletas { 2 }

3
spec/fixtures/complete_case_log.json vendored

@ -51,6 +51,9 @@
"condition_effects": "dummy",
"tenancy_code": "BZ757",
"startdate": "12/12/2020",
"day": 12,
"month": 12,
"year": 2020,
"startertenancy": "No",
"tenancylength": "5",
"tenancy": "Secure (including flexible)",

11
spec/models/case_log_spec.rb

@ -881,6 +881,9 @@ RSpec.describe Form, type: :model do
owning_organisation: organisation,
property_postcode: "M1 1AE",
previous_postcode: "M2 2AE",
day: 10,
month: 10,
year: 2021,
# rubocop:disable Style/DateTime
mrcdate: DateTime.new(2021, 5, 4),
# rubocop:enable Style/DateTime
@ -948,5 +951,13 @@ RSpec.describe Form, type: :model do
expect(case_log.lettype).to eq("Intermediate Rent General needs PRP")
expect(record_from_db["lettype"]).to eq(9)
end
it "correctly derives and saves startdate" do
case_log.reload
record_from_db = ActiveRecord::Base.connection.execute("select startdate from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.startdate).to eq(Time.zone.local(2021, 10, 10))
expect(record_from_db["startdate"]).to eq(Time.zone.local(2021, 10, 10))
end
end
end

Loading…
Cancel
Save