Browse Source

Merge branch 'main' into CLDC-3788-export-sales-logs

CLDC-3788-export-sales-logs
kosiakkatrina 2 months ago committed by GitHub
parent
commit
5a494c3319
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 20
      app/services/bulk_upload/lettings/year2024/row_parser.rb
  2. 20
      app/services/bulk_upload/sales/year2024/row_parser.rb
  3. 2
      config/locales/validations/lettings/2024/bulk_upload.en.yml
  4. 2
      config/locales/validations/sales/2024/bulk_upload.en.yml
  5. 2
      spec/requests/lettings_logs_controller_spec.rb
  6. 8
      spec/requests/organisation_relationships_controller_spec.rb
  7. 6
      spec/requests/organisations_controller_spec.rb
  8. 2
      spec/requests/sales_logs_controller_spec.rb
  9. 16
      spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb
  10. 18
      spec/services/bulk_upload/sales/year2024/row_parser_spec.rb

20
app/services/bulk_upload/lettings/year2024/row_parser.rb

@ -607,14 +607,22 @@ private
def validate_uprn_exists_if_any_key_address_fields_are_blank def validate_uprn_exists_if_any_key_address_fields_are_blank
if field_16.blank? && !key_address_fields_provided? if field_16.blank? && !key_address_fields_provided?
errors.add(:field_16, I18n.t("#{ERROR_BASE_KEY}.not_answered", question: "UPRN.")) %i[field_17 field_19 field_21 field_22].each do |field|
errors.add(field, I18n.t("#{ERROR_BASE_KEY}.address.not_answered")) if send(field).blank?
end
errors.add(:field_16, I18n.t("#{ERROR_BASE_KEY}.address.not_answered", question: "UPRN."))
end end
end end
def validate_address_option_found def validate_address_option_found
if log.uprn.nil? && field_16.blank? && key_address_fields_provided? if log.uprn.nil? && field_16.blank? && key_address_fields_provided?
error_message = if log.address_options_present?
I18n.t("#{ERROR_BASE_KEY}.address.not_determined")
else
I18n.t("#{ERROR_BASE_KEY}.address.not_found")
end
%i[field_17 field_18 field_19 field_20 field_21 field_22].each do |field| %i[field_17 field_18 field_19 field_20 field_21 field_22].each do |field|
errors.add(field, I18n.t("#{ERROR_BASE_KEY}.address.not_found")) errors.add(field, error_message) if errors[field].blank?
end end
end end
end end
@ -625,19 +633,19 @@ private
def validate_address_fields def validate_address_fields
if field_16.blank? || log.errors.attribute_names.include?(:uprn) if field_16.blank? || log.errors.attribute_names.include?(:uprn)
if field_17.blank? if field_17.blank? && errors[:field_17].blank?
errors.add(:field_17, I18n.t("#{ERROR_BASE_KEY}.not_answered", question: "address line 1.")) errors.add(:field_17, I18n.t("#{ERROR_BASE_KEY}.not_answered", question: "address line 1."))
end end
if field_19.blank? if field_19.blank? && errors[:field_19].blank?
errors.add(:field_19, I18n.t("#{ERROR_BASE_KEY}.not_answered", question: "town or city.")) errors.add(:field_19, I18n.t("#{ERROR_BASE_KEY}.not_answered", question: "town or city."))
end end
if field_21.blank? if field_21.blank? && errors[:field_21].blank?
errors.add(:field_21, I18n.t("#{ERROR_BASE_KEY}.not_answered", question: "part 1 of postcode.")) errors.add(:field_21, I18n.t("#{ERROR_BASE_KEY}.not_answered", question: "part 1 of postcode."))
end end
if field_22.blank? if field_22.blank? && errors[:field_22].blank?
errors.add(:field_22, I18n.t("#{ERROR_BASE_KEY}.not_answered", question: "part 2 of postcode.")) errors.add(:field_22, I18n.t("#{ERROR_BASE_KEY}.not_answered", question: "part 2 of postcode."))
end end
end end

20
app/services/bulk_upload/sales/year2024/row_parser.rb

@ -605,14 +605,22 @@ private
def validate_uprn_exists_if_any_key_address_fields_are_blank def validate_uprn_exists_if_any_key_address_fields_are_blank
if field_22.blank? && !key_address_fields_provided? if field_22.blank? && !key_address_fields_provided?
errors.add(:field_22, I18n.t("#{ERROR_BASE_KEY}.not_answered", question: "UPRN.")) %i[field_23 field_25 field_27 field_28].each do |field|
errors.add(field, I18n.t("#{ERROR_BASE_KEY}.address.not_answered")) if send(field).blank?
end
errors.add(:field_22, I18n.t("#{ERROR_BASE_KEY}.address.not_answered", question: "UPRN."))
end end
end end
def validate_address_option_found def validate_address_option_found
if log.uprn.nil? && field_22.blank? && key_address_fields_provided? if log.uprn.nil? && field_22.blank? && key_address_fields_provided?
error_message = if log.address_options_present?
I18n.t("#{ERROR_BASE_KEY}.address.not_determined")
else
I18n.t("#{ERROR_BASE_KEY}.address.not_found")
end
%i[field_23 field_24 field_25 field_26 field_27 field_28].each do |field| %i[field_23 field_24 field_25 field_26 field_27 field_28].each do |field|
errors.add(field, I18n.t("#{ERROR_BASE_KEY}.address.not_found")) errors.add(field, error_message) if errors[field].blank?
end end
end end
end end
@ -623,19 +631,19 @@ private
def validate_address_fields def validate_address_fields
if field_22.blank? || log.errors.attribute_names.include?(:uprn) if field_22.blank? || log.errors.attribute_names.include?(:uprn)
if field_23.blank? if field_23.blank? && errors[:field_23].blank?
errors.add(:field_23, I18n.t("#{ERROR_BASE_KEY}.not_answered", question: "address line 1.")) errors.add(:field_23, I18n.t("#{ERROR_BASE_KEY}.not_answered", question: "address line 1."))
end end
if field_25.blank? if field_25.blank? && errors[:field_25].blank?
errors.add(:field_25, I18n.t("#{ERROR_BASE_KEY}.not_answered", question: "town or city.")) errors.add(:field_25, I18n.t("#{ERROR_BASE_KEY}.not_answered", question: "town or city."))
end end
if field_27.blank? if field_27.blank? && errors[:field_27].blank?
errors.add(:field_27, I18n.t("#{ERROR_BASE_KEY}.not_answered", question: "part 1 of postcode.")) errors.add(:field_27, I18n.t("#{ERROR_BASE_KEY}.not_answered", question: "part 1 of postcode."))
end end
if field_28.blank? if field_28.blank? && errors[:field_28].blank?
errors.add(:field_28, I18n.t("#{ERROR_BASE_KEY}.not_answered", question: "part 2 of postcode.")) errors.add(:field_28, I18n.t("#{ERROR_BASE_KEY}.not_answered", question: "part 2 of postcode."))
end end
end end

2
config/locales/validations/lettings/2024/bulk_upload.en.yml

@ -50,6 +50,8 @@ en:
invalid: "Age of person %{person_num} must be a number or the letter R" invalid: "Age of person %{person_num} must be a number or the letter R"
address: address:
not_found: "We could not find this address. Check the address data in your CSV file is correct and complete, or select the correct address using the CORE site." not_found: "We could not find this address. Check the address data in your CSV file is correct and complete, or select the correct address using the CORE site."
not_determined: "There are multiple matches for this address. Either select the correct address manually or correct the UPRN in the CSV file."
not_answered: "Enter either the UPRN or the full address."
nationality: nationality:
invalid: "Select a valid nationality." invalid: "Select a valid nationality."
charges: charges:

2
config/locales/validations/sales/2024/bulk_upload.en.yml

@ -40,5 +40,7 @@ en:
buyer_cannot_be_over_16_and_child: "Buyer 2's age cannot be 16 or over if their working situation is child under 16." buyer_cannot_be_over_16_and_child: "Buyer 2's age cannot be 16 or over if their working situation is child under 16."
address: address:
not_found: "We could not find this address. Check the address data in your CSV file is correct and complete, or select the correct address using the CORE site." not_found: "We could not find this address. Check the address data in your CSV file is correct and complete, or select the correct address using the CORE site."
not_determined: "There are multiple matches for this address. Either select the correct address manually or correct the UPRN in the CSV file."
not_answered: "Enter either the UPRN or the full address."
nationality: nationality:
invalid: "Select a valid nationality." invalid: "Select a valid nationality."

2
spec/requests/lettings_logs_controller_spec.rb

@ -1483,7 +1483,7 @@ RSpec.describe LettingsLogsController, type: :request do
end end
context "when viewing a collection of logs affected by deactivated location" do context "when viewing a collection of logs affected by deactivated location" do
let!(:affected_lettings_logs) { FactoryBot.create_list(:lettings_log, 3, unresolved: true, assigned_to: user) } let!(:affected_lettings_logs) { FactoryBot.create_list(:lettings_log, 3, unresolved: true, assigned_to: user, tenancycode: "affected tenancycode", propcode: "affected propcode") }
let!(:other_user_affected_lettings_log) { FactoryBot.create(:lettings_log, unresolved: true) } let!(:other_user_affected_lettings_log) { FactoryBot.create(:lettings_log, unresolved: true) }
let!(:non_affected_lettings_logs) { FactoryBot.create_list(:lettings_log, 4, assigned_to: user) } let!(:non_affected_lettings_logs) { FactoryBot.create_list(:lettings_log, 4, assigned_to: user) }
let(:other_user) { FactoryBot.create(:user, organisation: user.organisation) } let(:other_user) { FactoryBot.create(:user, organisation: user.organisation) }

8
spec/requests/organisation_relationships_controller_spec.rb

@ -40,7 +40,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
it "shows a table of stock owners" do it "shows a table of stock owners" do
expected_html = "<table class=\"govuk-table\"" expected_html = "<table class=\"govuk-table\""
expect(response.body).to include(expected_html) expect(response.body).to include(expected_html)
expect(response.body).to include(stock_owner.name) expect(CGI.unescapeHTML(response.body)).to include(stock_owner.name)
end end
it "shows only stock owners for the current user's organisation" do it "shows only stock owners for the current user's organisation" do
@ -136,7 +136,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
it "shows a table of managing-agents" do it "shows a table of managing-agents" do
expected_html = "<table class=\"govuk-table\"" expected_html = "<table class=\"govuk-table\""
expect(response.body).to include(expected_html) expect(response.body).to include(expected_html)
expect(response.body).to include(managing_agent.name) expect(CGI.unescapeHTML(response.body)).to include(managing_agent.name)
end end
it "shows only managing-agents for the current user's organisation" do it "shows only managing-agents for the current user's organisation" do
@ -336,7 +336,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
it "shows a table of stock owners" do it "shows a table of stock owners" do
expected_html = "<table class=\"govuk-table\"" expected_html = "<table class=\"govuk-table\""
expect(response.body).to include(expected_html) expect(response.body).to include(expected_html)
expect(response.body).to include(stock_owner.name) expect(CGI.unescapeHTML(response.body)).to include(stock_owner.name)
end end
it "shows only stock owners for the current user's organisation" do it "shows only stock owners for the current user's organisation" do
@ -472,7 +472,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
it "shows a table of managing agents" do it "shows a table of managing agents" do
expected_html = "<table class=\"govuk-table\"" expected_html = "<table class=\"govuk-table\""
expect(response.body).to include(expected_html) expect(response.body).to include(expected_html)
expect(response.body).to include(managing_agent.name) expect(CGI.unescapeHTML(response.body)).to include(managing_agent.name)
end end
it "shows only managing agents for the current user's organisation" do it "shows only managing agents for the current user's organisation" do

6
spec/requests/organisations_controller_spec.rb

@ -487,7 +487,7 @@ RSpec.describe OrganisationsController, type: :request do
it "shows a summary list of org details" do it "shows a summary list of org details" do
expected_html = "<dl class=\"govuk-summary-list\"" expected_html = "<dl class=\"govuk-summary-list\""
expect(response.body).to include(expected_html) expect(response.body).to include(expected_html)
expect(response.body).to include(organisation.name) expect(CGI.unescapeHTML(response.body)).to include(organisation.name)
end end
it "does not include a change details link" do it "does not include a change details link" do
@ -663,7 +663,7 @@ RSpec.describe OrganisationsController, type: :request do
end end
it "shows an edit form without name field" do it "shows an edit form without name field" do
expect(response.body).to include("Change #{organisation.name}’s details") expect(CGI.unescapeHTML(response.body)).to include("Change #{organisation.name}’s details")
expect(page).not_to have_field("organisation-name-field") expect(page).not_to have_field("organisation-name-field")
expect(page).to have_field("organisation-phone-field") expect(page).to have_field("organisation-phone-field")
end end
@ -945,7 +945,7 @@ RSpec.describe OrganisationsController, type: :request do
it "shows a summary list of org details" do it "shows a summary list of org details" do
expected_html = "<dl class=\"govuk-summary-list\"" expected_html = "<dl class=\"govuk-summary-list\""
expect(response.body).to include(expected_html) expect(response.body).to include(expected_html)
expect(response.body).to include(organisation.name) expect(CGI.unescapeHTML(response.body)).to include(organisation.name)
end end
it "does not have a change details link" do it "does not have a change details link" do

2
spec/requests/sales_logs_controller_spec.rb

@ -299,7 +299,7 @@ RSpec.describe SalesLogsController, type: :request do
it "does not render pending logs" do it "does not render pending logs" do
get "/sales-logs", headers: headers, params: {} get "/sales-logs", headers: headers, params: {}
expect(page).not_to have_link(invisible_log.id, href: "sales-logs/#{invisible_log.id}") expect(page).not_to have_link(invisible_log.id.to_s, href: "sales-logs/#{invisible_log.id}")
end end
end end

16
spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb

@ -1658,11 +1658,11 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
it "adds appropriate errors to UPRN and key address fields" do it "adds appropriate errors to UPRN and key address fields" do
parser.valid? parser.valid?
expect(parser.errors[:field_16]).to eql([I18n.t("validations.lettings.2024.bulk_upload.not_answered", question: "UPRN.")]) expect(parser.errors[:field_16]).to eql([I18n.t("validations.lettings.2024.bulk_upload.address.not_answered")])
expect(parser.errors[:field_17]).to eql([I18n.t("validations.lettings.2024.bulk_upload.not_answered", question: "address line 1.")]) expect(parser.errors[:field_17]).to eql([I18n.t("validations.lettings.2024.bulk_upload.address.not_answered")])
expect(parser.errors[:field_19]).to eql([I18n.t("validations.lettings.2024.bulk_upload.not_answered", question: "town or city.")]) expect(parser.errors[:field_19]).to eql([I18n.t("validations.lettings.2024.bulk_upload.address.not_answered")])
expect(parser.errors[:field_21]).to eql([I18n.t("validations.lettings.2024.bulk_upload.not_answered", question: "part 1 of postcode.")]) expect(parser.errors[:field_21]).to eql([I18n.t("validations.lettings.2024.bulk_upload.address.not_answered")])
expect(parser.errors[:field_22]).to eql([I18n.t("validations.lettings.2024.bulk_upload.not_answered", question: "part 2 of postcode.")]) expect(parser.errors[:field_22]).to eql([I18n.t("validations.lettings.2024.bulk_upload.address.not_answered")])
end end
end end
@ -1671,8 +1671,8 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
it "adds errors to UPRN and the missing key address field" do it "adds errors to UPRN and the missing key address field" do
parser.valid? parser.valid?
expect(parser.errors[:field_16]).to eql([I18n.t("validations.lettings.2024.bulk_upload.not_answered", question: "UPRN.")]) expect(parser.errors[:field_16]).to eql([I18n.t("validations.lettings.2024.bulk_upload.address.not_answered")])
expect(parser.errors[:field_17]).to eql([I18n.t("validations.lettings.2024.bulk_upload.not_answered", question: "address line 1.")]) expect(parser.errors[:field_17]).to eql([I18n.t("validations.lettings.2024.bulk_upload.address.not_answered")])
expect(parser.errors[:field_19]).to be_empty expect(parser.errors[:field_19]).to be_empty
expect(parser.errors[:field_21]).to be_empty expect(parser.errors[:field_21]).to be_empty
expect(parser.errors[:field_22]).to be_empty expect(parser.errors[:field_22]).to be_empty
@ -1721,7 +1721,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
parser.valid? parser.valid?
expect(parser.errors[:field_16]).to be_empty expect(parser.errors[:field_16]).to be_empty
%i[field_17 field_18 field_19 field_20 field_21 field_22].each do |field| %i[field_17 field_18 field_19 field_20 field_21 field_22].each do |field|
expect(parser.errors[field]).to eql([I18n.t("validations.lettings.2024.bulk_upload.address.not_found")]) expect(parser.errors[field]).to eql([I18n.t("validations.lettings.2024.bulk_upload.address.not_determined")])
end end
end end
end end

18
spec/services/bulk_upload/sales/year2024/row_parser_spec.rb

@ -310,7 +310,7 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do
it "only has one error added to the field" do it "only has one error added to the field" do
parser.valid? parser.valid?
expect(parser.errors[:field_23]).to eql([I18n.t("validations.sales.2024.bulk_upload.not_answered", question: "address line 1.")]) expect(parser.errors[:field_23]).to eql([I18n.t("validations.sales.2024.bulk_upload.address.not_answered")])
end end
end end
@ -1042,11 +1042,11 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do
it "adds appropriate errors to UPRN and key address fields" do it "adds appropriate errors to UPRN and key address fields" do
parser.valid? parser.valid?
expect(parser.errors[:field_22]).to eql([I18n.t("validations.sales.2024.bulk_upload.not_answered", question: "UPRN.")]) expect(parser.errors[:field_22]).to eql([I18n.t("validations.sales.2024.bulk_upload.address.not_answered")])
expect(parser.errors[:field_23]).to eql([I18n.t("validations.sales.2024.bulk_upload.not_answered", question: "address line 1.")]) expect(parser.errors[:field_23]).to eql([I18n.t("validations.sales.2024.bulk_upload.address.not_answered")])
expect(parser.errors[:field_25]).to eql([I18n.t("validations.sales.2024.bulk_upload.not_answered", question: "town or city.")]) expect(parser.errors[:field_25]).to eql([I18n.t("validations.sales.2024.bulk_upload.address.not_answered")])
expect(parser.errors[:field_27]).to eql([I18n.t("validations.sales.2024.bulk_upload.not_answered", question: "part 1 of postcode.")]) expect(parser.errors[:field_27]).to eql([I18n.t("validations.sales.2024.bulk_upload.address.not_answered")])
expect(parser.errors[:field_28]).to eql([I18n.t("validations.sales.2024.bulk_upload.not_answered", question: "part 2 of postcode.")]) expect(parser.errors[:field_28]).to eql([I18n.t("validations.sales.2024.bulk_upload.address.not_answered")])
end end
end end
@ -1055,8 +1055,8 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do
it "adds errors to UPRN and the missing key address field" do it "adds errors to UPRN and the missing key address field" do
parser.valid? parser.valid?
expect(parser.errors[:field_22]).to eql([I18n.t("validations.sales.2024.bulk_upload.not_answered", question: "UPRN.")]) expect(parser.errors[:field_22]).to eql([I18n.t("validations.sales.2024.bulk_upload.address.not_answered")])
expect(parser.errors[:field_23]).to eql([I18n.t("validations.sales.2024.bulk_upload.not_answered", question: "address line 1.")]) expect(parser.errors[:field_23]).to eql([I18n.t("validations.sales.2024.bulk_upload.address.not_answered")])
expect(parser.errors[:field_25]).to be_empty expect(parser.errors[:field_25]).to be_empty
expect(parser.errors[:field_27]).to be_empty expect(parser.errors[:field_27]).to be_empty
expect(parser.errors[:field_28]).to be_empty expect(parser.errors[:field_28]).to be_empty
@ -1105,7 +1105,7 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do
parser.valid? parser.valid?
expect(parser.errors[:field_22]).to be_empty expect(parser.errors[:field_22]).to be_empty
%i[field_23 field_24 field_25 field_26 field_27 field_28].each do |field| %i[field_23 field_24 field_25 field_26 field_27 field_28].each do |field|
expect(parser.errors[field]).to eql([I18n.t("validations.sales.2024.bulk_upload.address.not_found")]) expect(parser.errors[field]).to eql([I18n.t("validations.sales.2024.bulk_upload.address.not_determined")])
end end
end end
end end

Loading…
Cancel
Save