diff --git a/app/models/validations/local_authority_validations.rb b/app/models/validations/local_authority_validations.rb index b5f001e64..ae38d5b25 100644 --- a/app/models/validations/local_authority_validations.rb +++ b/app/models/validations/local_authority_validations.rb @@ -18,7 +18,7 @@ module Validations::LocalAuthorityValidations record.la && !record.owning_organisation.local_authorities.include?(record.la) la_name = record.form.get_question("la", record).label_from_value(record.la) org_name = record.owning_organisation.name - postcode = record.postcode_full + postcode = UKPostcode.parse(record.postcode_full) record.errors.add :la, I18n.t("validations.property.la.la_invalid_for_org", org_name:, la_name:) record.errors.add :postcode_known, I18n.t("validations.property.la.postcode_invalid_for_org", org_name:, postcode:) end diff --git a/spec/models/validations/local_authority_validations_spec.rb b/spec/models/validations/local_authority_validations_spec.rb index 4d9a93dfc..42c816c06 100644 --- a/spec/models/validations/local_authority_validations_spec.rb +++ b/spec/models/validations/local_authority_validations_spec.rb @@ -73,19 +73,15 @@ RSpec.describe Validations::LocalAuthorityValidations do end context "when a postcode is given" do - before do - stub_request(:get, /api.postcodes.io/) - .to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"York\",\"codes\":{\"admin_district\": \"E06000014\"}}}", headers: {}) - end - it "validates that it matches a local authority the organisation operates in" do record.postcode_full = "YO10 3RR" - record.save + record.la = "E06000014" + local_auth_validator.validate_la(record) expect(record.errors["postcode_known"]) .to include(match I18n.t( "validations.property.la.postcode_invalid_for_org", org_name: organisation.name, - postcode: "YO103RR", + postcode: "YO10 3RR", )) end end