Browse Source

CLDC-1998 Correctly infer 22/23 las if a NEW one is returned by postcodes.io (#1397)

* feat: correctly infer las for 22/23 logs

* feat: copy changes to sales log

* feat: don't reset las when clash with postcode to make tests pass

* feat: align with similar PR for 23/24

* feat: tidying and add test

* refactor: lint

* refactor: use unless
pull/1411/head
natdeanlewissoftwire 2 years ago committed by GitHub
parent
commit
5e340f2b41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/models/log.rb
  2. 8
      db/schema.rb
  3. 31
      spec/models/sales_log_spec.rb

2
app/models/log.rb

@ -160,7 +160,7 @@ private
location_code = result[:location_code] if result
if LA_CHANGES.key?(location_code) && form.start_date.year >= 2023
LA_CHANGES[location_code]
else
elsif !(LA_CHANGES.value?(location_code) && form.start_date.year < 2023)
location_code
end
end

8
db/schema.rb

@ -501,6 +501,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_08_101826) do
t.integer "prevten"
t.integer "mortgageused"
t.integer "wchair"
t.integer "income2_value_check"
t.integer "armedforcesspouse"
t.datetime "hodate", precision: nil
t.integer "hoday"
@ -525,14 +526,13 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_08_101826) do
t.integer "retirement_value_check"
t.integer "hodate_check"
t.integer "extrabor_value_check"
t.integer "grant_value_check"
t.integer "staircase_bought_value_check"
t.integer "deposit_and_mortgage_value_check"
t.integer "shared_ownership_deposit_value_check"
t.integer "grant_value_check"
t.integer "value_value_check"
t.integer "old_persons_shared_ownership_value_check"
t.integer "income2_value_check"
t.integer "staircase_bought_value_check"
t.integer "monthly_charges_value_check"
t.integer "value_value_check"
t.integer "details_known_5"
t.integer "details_known_6"
t.integer "saledate_check"

31
spec/models/sales_log_spec.rb

@ -226,6 +226,37 @@ RSpec.describe SalesLog, type: :model do
expect(record_from_db["la"]).to eq("E08000003")
end
context "with 22/23 logs" do
let(:address_sales_log_22_23) do
described_class.create({
owning_organisation:,
created_by: created_by_user,
ppcodenk: 1,
postcode_full: "CA10 1AA",
saledate: Time.zone.local(2022, 5, 2),
})
end
before do
WebMock.stub_request(:get, /api.postcodes.io\/postcodes\/CA101AA/)
.to_return(status: 200, body: '{"status":200,"result":{"admin_district":"Cumberland","codes":{"admin_district":"E06000063"}}}', headers: {})
Timecop.freeze(2023, 5, 1)
Singleton.__init__(FormHandler)
end
after do
Timecop.unfreeze
Singleton.__init__(FormHandler)
end
it "correctly sets la as nil" do
record_from_db = ActiveRecord::Base.connection.execute("select la from sales_logs where id=#{address_sales_log_22_23.id}").to_a[0]
expect(address_sales_log_22_23.la).to eq(nil)
expect(record_from_db["la"]).to eq(nil)
end
end
context "with 23/24 logs" do
let(:address_sales_log_23_24) do
described_class.create({

Loading…
Cancel
Save