Browse Source

More tests

pull/337/head
baarkerlounger 3 years ago
parent
commit
fbad7d837f
  1. 19
      app/models/case_log.rb
  2. 110
      spec/models/case_log_spec.rb
  3. 12
      spec/models/form/question_spec.rb

19
app/models/case_log.rb

@ -123,6 +123,10 @@ class CaseLog < ApplicationRecord
needstype == 1
end
def is_supported_housing?
!!(needstype && needstype.zero?)
end
def has_hbrentshortfall?
!!(hbrentshortfall && hbrentshortfall.zero?)
end
@ -378,24 +382,21 @@ private
case RENT_TYPE_MAPPING_LABELS[renttype]
when "Social Rent"
case needstype
when 0
if is_supported_housing?
owning_organisation[:provider_type] == "PRP" ? 2 : 4
when 1
elsif is_general_needs?
owning_organisation[:provider_type] == "PRP" ? 1 : 3
end
when "Affordable Rent"
case needstype
when 0
if is_supported_housing?
owning_organisation[:provider_type] == "PRP" ? 6 : 8
when 1
elsif is_general_needs?
owning_organisation[:provider_type] == "PRP" ? 5 : 7
end
when "Intermediate Rent"
case needstype
when 0
if is_supported_housing?
owning_organisation[:provider_type] == "PRP" ? 10 : 12
when 1
elsif is_general_needs?
owning_organisation[:provider_type] == "PRP" ? 9 : 11
end
end

110
spec/models/case_log_spec.rb

@ -273,11 +273,121 @@ RSpec.describe CaseLog do
expect(record_from_db["renttype"]).to eq(3)
end
context "when deriving lettype" do
context "when the owning organisation is a PRP" do
context "when the rent type is intermediate rent and supported housing" do
it "correctly derives and saves lettype" do
case_log.update!(rent_type: 4, needstype: 0)
record_from_db = ActiveRecord::Base.connection.execute("select lettype from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.lettype).to eq(10)
expect(record_from_db["lettype"]).to eq(10)
end
end
context "when the rent type is intermediate rent and general needs housing" do
it "correctly derives and saves lettype" do
case_log.update!(rent_type: 4, needstype: 1)
record_from_db = ActiveRecord::Base.connection.execute("select lettype from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.lettype).to eq(9)
expect(record_from_db["lettype"]).to eq(9)
end
end
context "when the rent type is affordable rent and supported housing" do
it "correctly derives and saves lettype" do
case_log.update!(rent_type: 2, needstype: 0)
record_from_db = ActiveRecord::Base.connection.execute("select lettype from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.lettype).to eq(6)
expect(record_from_db["lettype"]).to eq(6)
end
end
context "when the rent type is affordable rent and general needs housing" do
it "correctly derives and saves lettype" do
case_log.update!(rent_type: 2, needstype: 1)
record_from_db = ActiveRecord::Base.connection.execute("select lettype from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.lettype).to eq(5)
expect(record_from_db["lettype"]).to eq(5)
end
end
context "when the rent type is social rent and supported housing" do
it "correctly derives and saves lettype" do
case_log.update!(rent_type: 0, needstype: 0)
record_from_db = ActiveRecord::Base.connection.execute("select lettype from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.lettype).to eq(2)
expect(record_from_db["lettype"]).to eq(2)
end
end
context "when the rent type is social rent and general needs housing" do
it "correctly derives and saves lettype" do
case_log.update!(rent_type: 0, needstype: 1)
record_from_db = ActiveRecord::Base.connection.execute("select lettype from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.lettype).to eq(1)
expect(record_from_db["lettype"]).to eq(1)
end
end
end
context "when the owning organisation is an LA" do
let(:organisation) { FactoryBot.create(:organisation, provider_type: "LA") }
context "when the rent type is intermediate rent and supported housing" do
it "correctly derives and saves lettype" do
case_log.update!(rent_type: 4, needstype: 0)
record_from_db = ActiveRecord::Base.connection.execute("select lettype from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.lettype).to eq(12)
expect(record_from_db["lettype"]).to eq(12)
end
end
context "when the rent type is intermediate rent and general needs housing" do
it "correctly derives and saves lettype" do
case_log.update!(rent_type: 4, needstype: 1)
record_from_db = ActiveRecord::Base.connection.execute("select lettype from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.lettype).to eq(11)
expect(record_from_db["lettype"]).to eq(11)
end
end
context "when the rent type is affordable rent and supported housing" do
it "correctly derives and saves lettype" do
case_log.update!(rent_type: 2, needstype: 0)
record_from_db = ActiveRecord::Base.connection.execute("select lettype from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.lettype).to eq(8)
expect(record_from_db["lettype"]).to eq(8)
end
end
context "when the rent type is affordable rent and general needs housing" do
it "correctly derives and saves lettype" do
case_log.update!(rent_type: 2, needstype: 1)
record_from_db = ActiveRecord::Base.connection.execute("select lettype from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.lettype).to eq(7)
expect(record_from_db["lettype"]).to eq(7)
end
end
context "when the rent type is social rent and supported housing" do
it "correctly derives and saves lettype" do
case_log.update!(rent_type: 0, needstype: 0)
record_from_db = ActiveRecord::Base.connection.execute("select lettype from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.lettype).to eq(4)
expect(record_from_db["lettype"]).to eq(4)
end
end
context "when the rent type is social rent and general needs housing" do
it "correctly derives and saves lettype" do
case_log.update!(rent_type: 0, needstype: 1)
record_from_db = ActiveRecord::Base.connection.execute("select lettype from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.lettype).to eq(3)
expect(record_from_db["lettype"]).to eq(3)
end
end
end
end
it "correctly derives and saves day, month, year from start date" do
record_from_db = ActiveRecord::Base.connection.execute("select day, month, year, startdate from case_logs where id=#{case_log.id}").to_a[0]

12
spec/models/form/question_spec.rb

@ -238,6 +238,18 @@ RSpec.describe Form::Question, type: :model do
case_log.hb = "Housing benefit"
expect(question.enabled?(case_log)).to be true
end
context "when the condition type hasn't been implemented yet" do
let(:unimplemented_question) { OpenStruct.new(id: "hb", type: "unkown") }
before do
allow(page).to receive(:questions).and_return([unimplemented_question])
end
it "raises an exception" do
expect { question.enabled?(case_log) }.to raise_error("Not implemented yet")
end
end
end
context "when answers have a suffix dependent on another answer" do

Loading…
Cancel
Save