Browse Source

bulk upload declaration validated as setup field (#1583)

pull/1587/head v0.3.17
Phil Lee 2 years ago committed by GitHub
parent
commit
5862e02d1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      app/services/bulk_upload/lettings/year2022/row_parser.rb
  2. 8
      app/services/bulk_upload/lettings/year2023/row_parser.rb
  3. 48
      spec/services/bulk_upload/lettings/validator_spec.rb
  4. 3
      spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb
  5. 3
      spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb
  6. 2
      spec/services/bulk_upload/processor_spec.rb

8
app/services/bulk_upload/lettings/year2022/row_parser.rb

@ -329,6 +329,8 @@ class BulkUpload::Lettings::Year2022::RowParser
validate :validate_created_by_related, on: :after_log
validate :validate_rent_type, on: :after_log
validate :validate_declaration_acceptance, on: :after_log
validate :validate_valid_radio_option, on: :before_log
def self.question_for_field(field)
@ -392,6 +394,12 @@ class BulkUpload::Lettings::Year2022::RowParser
private
def validate_declaration_acceptance
unless field_132 == 1
errors.add(:field_132, I18n.t("validations.declaration.missing"), category: :setup)
end
end
def validate_valid_radio_option
log.attributes.each do |question_id, _v|
question = log.form.get_question(question_id, log)

8
app/services/bulk_upload/lettings/year2023/row_parser.rb

@ -332,6 +332,8 @@ class BulkUpload::Lettings::Year2023::RowParser
validate :validate_created_by_exists, on: :after_log
validate :validate_created_by_related, on: :after_log
validate :validate_declaration_acceptance, on: :after_log
validate :validate_valid_radio_option, on: :before_log
validate :validate_uprn_exists_if_any_key_adddress_fields_are_blank, on: :after_log
@ -397,6 +399,12 @@ class BulkUpload::Lettings::Year2023::RowParser
private
def validate_declaration_acceptance
unless field_45 == 1
errors.add(:field_45, I18n.t("validations.declaration.missing"), category: :setup)
end
end
def validate_valid_radio_option
log.attributes.each do |question_id, _v|
question = log.form.get_question(question_id, log)

48
spec/services/bulk_upload/lettings/validator_spec.rb

@ -214,7 +214,7 @@ RSpec.describe BulkUpload::Lettings::Validator do
end
end
context "when a log has incomplete setup secion" do
context "when a log has incomplete setup section" do
let(:log) { build(:lettings_log, :in_progress, created_by: user, startdate: Time.zone.local(2022, 5, 1)) }
before do
@ -227,51 +227,5 @@ RSpec.describe BulkUpload::Lettings::Validator do
expect(validator).not_to be_create_logs
end
end
context "when a column has error rate below absolute threshold" do
context "when a column is over 60% error threshold" do
let(:log_1) { build(:lettings_log, :completed, renttype: 1, created_by: user) }
let(:log_2) { build(:lettings_log, renttype: 2, created_by: user, builtype: nil, startdate: Time.zone.local(2022, 5, 1)) }
let(:log_3) { build(:lettings_log, renttype: 2, created_by: user, builtype: nil, startdate: Time.zone.local(2022, 5, 1)) }
let(:log_4) { build(:lettings_log, renttype: 2, created_by: user, builtype: nil, startdate: Time.zone.local(2022, 5, 1)) }
let(:log_5) { build(:lettings_log, renttype: 2, created_by: user, builtype: nil, startdate: Time.zone.local(2022, 5, 1)) }
before do
file.write(BulkUpload::LogToCsv.new(log: log_1, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::LogToCsv.new(log: log_2, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::LogToCsv.new(log: log_3, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::LogToCsv.new(log: log_4, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::LogToCsv.new(log: log_5, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.close
end
it "returns true" do
validator.call
expect(validator).to be_create_logs
end
end
context "when a column is under 60% error threshold" do
let(:log_1) { build(:lettings_log, :completed, renttype: 1, created_by: user) }
let(:log_2) { build(:lettings_log, :completed, renttype: 1, created_by: user) }
let(:log_3) { build(:lettings_log, renttype: 2, created_by: user, builtype: nil, startdate: Time.zone.local(2022, 5, 1)) }
let(:log_4) { build(:lettings_log, renttype: 2, created_by: user, builtype: nil, startdate: Time.zone.local(2022, 5, 1)) }
let(:log_5) { build(:lettings_log, renttype: 2, created_by: user, builtype: nil, startdate: Time.zone.local(2022, 5, 1)) }
before do
file.write(BulkUpload::LogToCsv.new(log: log_1, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::LogToCsv.new(log: log_2, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::LogToCsv.new(log: log_3, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::LogToCsv.new(log: log_4, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::LogToCsv.new(log: log_5, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.close
end
it "returns true" do
validator.call
expect(validator).to be_create_logs
end
end
end
end
end

3
spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb

@ -24,6 +24,7 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do
field_97: now.month.to_s,
field_98: now.strftime("%g"),
field_134: "2",
field_132: "1",
}
end
@ -224,7 +225,7 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do
it "has errors on setup fields" do
errors = parser.errors.select { |e| e.options[:category] == :setup }.map(&:attribute)
expect(errors).to eql(%i[field_1 field_98 field_97 field_96 field_111 field_113])
expect(errors).to eql(%i[field_1 field_98 field_97 field_96 field_111 field_113 field_132])
end
end

3
spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb

@ -25,6 +25,7 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
field_7: now.day.to_s,
field_8: now.month.to_s,
field_9: now.strftime("%g"),
field_45: "1",
}
end
@ -256,7 +257,7 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
it "has errors on setup fields" do
errors = parser.errors.select { |e| e.options[:category] == :setup }.map(&:attribute).sort
expect(errors).to eql(%i[field_1 field_2 field_4 field_5 field_6 field_7 field_8 field_9])
expect(errors).to eql(%i[field_1 field_2 field_4 field_45 field_5 field_6 field_7 field_8 field_9])
end
end

2
spec/services/bulk_upload/processor_spec.rb

@ -208,6 +208,7 @@ RSpec.describe BulkUpload::Processor do
managing_organisation: owning_org,
startdate: Time.zone.local(2022, 10, 1),
renewal: 2,
declaration: 1,
)
end
@ -258,6 +259,7 @@ RSpec.describe BulkUpload::Processor do
startdate: Time.zone.local(2022, 10, 1),
renewal: 2,
created_by: other_user, # unaffiliated user
declaration: 1,
)
end

Loading…
Cancel
Save