Browse Source

Test validate_owning_org_permitted & validate empty assigned to (when support uploads)

pull/2629/head
Manny Dinssa 2 years ago
parent
commit
c55a5d1952
  1. 19
      app/services/bulk_upload/lettings/year2024/row_parser.rb
  2. 19
      app/services/bulk_upload/sales/year2024/row_parser.rb
  3. 35
      spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb
  4. 35
      spec/services/bulk_upload/sales/year2024/row_parser_spec.rb

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

@ -432,6 +432,7 @@ class BulkUpload::Lettings::Year2024::RowParser
validate :validate_assigned_to_exists, on: :after_log
validate :validate_assigned_to_related, on: :after_log
validate :validate_assigned_to_when_support, on: :after_log
validate :validate_all_charges_given, on: :after_log, if: proc { is_carehome.zero? }
validate :validate_address_option_found, on: :after_log, unless: -> { supported_housing? }
@ -580,6 +581,13 @@ private
end
end
def validate_assigned_to_when_support
if field_3.blank? && bulk_upload.user.support?
block_log_creation!
errors.add(:field_3, :setup, message: "User was not provided")
end
end
def validate_assigned_to_related
return unless assigned_to
return if assigned_to.organisation == owning_organisation || assigned_to.organisation == managing_organisation
@ -891,12 +899,13 @@ private
def validate_owning_org_permitted
return unless owning_organisation
if (bulk_upload.user.support? && !bulk_upload.organisation.affiliated_stock_owners.include?(bulk_upload.organisation)) || (!bulk_upload.user.support? && !bulk_upload.user.organisation.affiliated_stock_owners.include?(owning_organisation))
block_log_creation!
return if (bulk_upload.user.support? && bulk_upload.organisation.affiliated_stock_owners.include?(bulk_upload.organisation)) ||
(!bulk_upload.user.support? && bulk_upload.user.organisation.affiliated_stock_owners.include?(owning_organisation))
if errors[:field_1].blank?
errors.add(:field_1, "You do not have permission to add logs for this owning organisation", category: :setup)
end
block_log_creation!
if errors[:field_1].blank?
errors.add(:field_1, "You do not have permission to add logs for this owning organisation", category: :setup)
end
end

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

@ -462,6 +462,7 @@ class BulkUpload::Sales::Year2024::RowParser
validate :validate_assigned_to_exists, on: :after_log
validate :validate_assigned_to_related, on: :after_log
validate :validate_assigned_to_when_support, on: :after_log
validate :validate_managing_org_related, on: :after_log
validate :validate_relevant_collection_window, on: :after_log
validate :validate_incomplete_soft_validations, on: :after_log
@ -1302,12 +1303,13 @@ private
def validate_owning_org_permitted
return unless owning_organisation
if (bulk_upload.user.support? && !bulk_upload.organisation.affiliated_stock_owners.include?(bulk_upload.organisation)) || (!bulk_upload.user.support? && !bulk_upload.user.organisation.affiliated_stock_owners.include?(owning_organisation))
block_log_creation!
return if (bulk_upload.user.support? && bulk_upload.organisation.affiliated_stock_owners.include?(bulk_upload.organisation)) ||
(!bulk_upload.user.support? && bulk_upload.user.organisation.affiliated_stock_owners.include?(owning_organisation))
if errors[:field_1].blank?
errors.add(:field_1, "You do not have permission to add logs for this owning organisation", category: :setup)
end
block_log_creation!
if errors[:field_1].blank?
errors.add(:field_1, "You do not have permission to add logs for this owning organisation", category: :setup)
end
end
@ -1319,6 +1321,13 @@ private
end
end
def validate_assigned_to_when_support
if field_3.blank? && bulk_upload.user.support?
block_log_creation!
errors.add(:field_3, :setup, message: "User was not provided")
end
end
def validate_assigned_to_related
return unless assigned_to
return if assigned_to.organisation == owning_organisation || assigned_to.organisation == managing_organisation

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

@ -1439,6 +1439,41 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
expect(parser.errors[:field_10]).to include(/Enter a date when the owning and managing organisation was active/)
end
end
context "when user is an unaffiliated non-support user and bulk upload organisation is affiliated with the owning organisation" do
let(:affiliated_org) { create(:organisation, :with_old_visible_id) }
let(:unaffiliated_user) { create(:user, organisation: create(:organisation)) }
let(:attributes) { { bulk_upload:, field_1: affiliated_org.old_visible_id } }
before do
create(:organisation_relationship, parent_organisation: owning_org, child_organisation: affiliated_org)
bulk_upload.update!(organisation_id: affiliated_org.id, user: unaffiliated_user)
end
it "blocks log creation and adds an error to field_1" do
parser = described_class.new(attributes)
parser.valid?
expect(parser).to be_block_log_creation
expect(parser.errors[:field_1]).to include("You do not have permission to add logs for this owning organisation")
end
end
context "when user is an unaffiliated support user and bulk upload organisation is affiliated with the owning organisation" do
let(:affiliated_org) { create(:organisation, :with_old_visible_id) }
let(:unaffiliated_support_user) { create(:user, :support, organisation: create(:organisation)) }
let(:attributes) { { bulk_upload:, field_1: affiliated_org.old_visible_id } }
before do
create(:organisation_relationship, parent_organisation: owning_org, child_organisation: affiliated_org)
bulk_upload.update!(organisation_id: affiliated_org.id, user: unaffiliated_support_user)
end
it "does not block log creation and does not add an error to field_1" do
parser = described_class.new(attributes)
parser.valid?
expect(parser.errors[:field_1]).not_to include("You do not have permission to add logs for this owning organisation")
end
end
end
describe "#field_2" do # managing org

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

@ -554,6 +554,41 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do
expect(parser.errors[:field_6]).to include(/Enter a date when the owning organisation was active/)
end
end
context "when user is an unaffiliated non-support user and bulk upload organisation is affiliated with the owning organisation" do
let(:affiliated_org) { create(:organisation, :with_old_visible_id) }
let(:unaffiliated_user) { create(:user, organisation: create(:organisation)) }
let(:attributes) { { bulk_upload:, field_1: affiliated_org.old_visible_id } }
before do
create(:organisation_relationship, parent_organisation: owning_org, child_organisation: affiliated_org)
bulk_upload.update!(organisation_id: affiliated_org.id, user: unaffiliated_user)
end
it "blocks log creation and adds an error to field_1" do
parser = described_class.new(attributes)
parser.valid?
expect(parser).to be_block_log_creation
expect(parser.errors[:field_1]).to include("You do not have permission to add logs for this owning organisation")
end
end
context "when user is an unaffiliated support user and bulk upload organisation is affiliated with the owning organisation" do
let(:affiliated_org) { create(:organisation, :with_old_visible_id) }
let(:unaffiliated_support_user) { create(:user, :support, organisation: create(:organisation)) }
let(:attributes) { { bulk_upload:, field_1: affiliated_org.old_visible_id } }
before do
create(:organisation_relationship, parent_organisation: owning_org, child_organisation: affiliated_org)
bulk_upload.update!(organisation_id: affiliated_org.id, user: unaffiliated_support_user)
end
it "does not block log creation and does not add an error to field_1" do
parser = described_class.new(attributes)
parser.valid?
expect(parser.errors[:field_1]).not_to include("You do not have permission to add logs for this owning organisation")
end
end
end
describe "#field_3" do # username for assigned_to

Loading…
Cancel
Save