Browse Source

Test timeout rescue

pull/378/head
baarkerlounger 3 years ago
parent
commit
0e3ef19903
  1. 1
      app/models/case_log.rb
  2. 11
      spec/models/case_log_spec.rb

1
app/models/case_log.rb

@ -388,6 +388,7 @@ private
begin
Timeout.timeout(5) { postcode_lookup = PIO.lookup(postcode) }
rescue Timeout::Error
Rails.logger.warn("Postcodes.io lookup timed out")
end
if postcode_lookup && postcode_lookup.info.present?
postcode_lookup.codes["admin_district"]

11
spec/models/case_log_spec.rb

@ -412,6 +412,17 @@ RSpec.describe CaseLog do
.to raise_error(ActiveRecord::RecordInvalid, /#{I18n.t("validations.postcode")}/)
end
context "when the local authority lookup times out" do
before do
allow(Timeout).to receive(:timeout).and_raise(Timeout::Error)
end
it "logs a warning" do
expect(Rails.logger).to receive(:warn).with("Postcodes.io lookup timed out")
address_case_log.update!({ postcode_known: 1, property_postcode: "M1 1AD" })
end
end
it "correctly resets all fields if property postcode not known" do
address_case_log.update!({ postcode_known: 0 })

Loading…
Cancel
Save