Browse Source

feat: add tests

pull/1460/head
natdeanlewissoftwire 3 years ago
parent
commit
7676739711
  1. 2
      spec/models/form/lettings/questions/address_line1_spec.rb
  2. 39
      spec/models/form/lettings/questions/scheme_id_spec.rb
  3. 2
      spec/models/form/sales/questions/address_line1_spec.rb
  4. 1
      spec/models/lettings_log_spec.rb

2
spec/models/form/lettings/questions/address_line1_spec.rb

@ -64,7 +64,7 @@ RSpec.describe Form::Lettings::Questions::AddressLine1, type: :model do
end end
end end
context "when la is present but inferred" do context "when la is present and inferred" do
let(:log) { create(:lettings_log, la: "E09000003") } let(:log) { create(:lettings_log, la: "E09000003") }
before do before do

39
spec/models/form/lettings/questions/scheme_id_spec.rb

@ -39,6 +39,45 @@ RSpec.describe Form::Lettings::Questions::SchemeId, type: :model do
expect(question.derived?).to be false expect(question.derived?).to be false
end end
it "has the correct inferred_answers" do
expect(question.inferred_answers).to eq({
"location.name": {
"scheme_has_multiple_locations?": false,
},
})
end
describe "has the correct get_extra_check_answer_value" do
let(:scheme) { create(:scheme) }
context "when locations are present but not inferred" do
let(:lettings_log) { create(:lettings_log) }
before do
allow(lettings_log).to receive(:scheme_has_multiple_locations?).and_return(true)
end
it "returns nil" do
expect(question.get_extra_check_answer_value(lettings_log)).to be_nil
end
end
context "when location is present and inferred" do
let!(:location) { create(:location, scheme:) }
let!(:lettings_log) { create(:lettings_log, scheme:, location:) }
let(:real_2022_2023_form) { Form.new("config/forms/2022_2023.json") }
before do
allow(lettings_log).to receive(:scheme_has_multiple_locations?).and_return(false)
allow(lettings_log).to receive(:form).and_return(real_2022_2023_form)
end
it "returns the postcode" do
expect(question.get_extra_check_answer_value(lettings_log)).to eq(location.postcode)
end
end
end
context "when a user is signed in" do context "when a user is signed in" do
let(:organisation) { FactoryBot.create(:organisation) } let(:organisation) { FactoryBot.create(:organisation) }
let(:organisation_2) { FactoryBot.create(:organisation) } let(:organisation_2) { FactoryBot.create(:organisation) }

2
spec/models/form/sales/questions/address_line1_spec.rb

@ -64,7 +64,7 @@ RSpec.describe Form::Sales::Questions::AddressLine1, type: :model do
end end
end end
context "when la is present but inferred" do context "when la is present and inferred" do
let(:log) { create(:sales_log, la: "E09000003") } let(:log) { create(:sales_log, la: "E09000003") }
before do before do

1
spec/models/lettings_log_spec.rb

@ -7,7 +7,6 @@ RSpec.describe LettingsLog do
let(:created_by_user) { create(:user) } let(:created_by_user) { create(:user) }
let(:owning_organisation) { created_by_user.organisation } let(:owning_organisation) { created_by_user.organisation }
let(:fake_2021_2022_form) { Form.new("spec/fixtures/forms/2021_2022.json") } let(:fake_2021_2022_form) { Form.new("spec/fixtures/forms/2021_2022.json") }
let(:fake_2022_2023_form) { Form.new("spec/fixtures/forms/2022_2023.json") }
around do |example| around do |example|
Timecop.freeze(Time.utc(2022, 1, 1)) do Timecop.freeze(Time.utc(2022, 1, 1)) do

Loading…
Cancel
Save