Browse Source

Update display_actions

pull/2273/head
Kat 2 years ago
parent
commit
6f139e15a4
  1. 11
      app/components/create_log_actions_component.rb
  2. 30
      spec/components/create_log_actions_component_spec.rb

11
app/components/create_log_actions_component.rb

@ -14,9 +14,8 @@ class CreateLogActionsComponent < ViewComponent::Base
def display_actions?
return false if bulk_upload.present?
return true if user.support?
return false if !user.organisation.holds_own_stock? && user.organisation.stock_owners.empty? && user.organisation.absorbed_organisations.empty?
user.organisation.data_protection_confirmed?
organisation_or_stock_owner_signed_dsa_and_holds_own_stock?(user.organisation)
end
def create_button_href
@ -54,4 +53,12 @@ class CreateLogActionsComponent < ViewComponent::Base
bulk_upload_sales_log_path(id: "start")
end
end
def organisation_or_stock_owner_signed_dsa_and_holds_own_stock?(organisation)
return true if organisation.data_protection_confirmed? && organisation.holds_own_stock?
return true if organisation.stock_owners.any? { |stock_owner| stock_owner.data_protection_confirmed? && stock_owner.holds_own_stock? }
return true if organisation.absorbed_organisations.any? { |stock_owner| stock_owner.data_protection_confirmed? && stock_owner.holds_own_stock? }
false
end
end

30
spec/components/create_log_actions_component_spec.rb

@ -74,7 +74,7 @@ RSpec.describe CreateLogActionsComponent, type: :component do
end
context "when has data sharing agremeent" do
let(:user) { create(:user, :support) }
let(:user) { create(:user) }
it "renders actions" do
expect(component.display_actions?).to eq(true)
@ -114,6 +114,34 @@ RSpec.describe CreateLogActionsComponent, type: :component do
expect(component.create_button_href).to eq("/sales-logs")
end
end
context "when organisation doesn't own stock" do
before do
user.organisation.update!(holds_own_stock: false)
end
context "and stock owners that have signed data sharing agreement" do
before do
parent_organisation = create(:organisation)
create(:organisation_relationship, child_organisation: user.organisation, parent_organisation:)
end
it "renders actions" do
expect(component.display_actions?).to eq(true)
end
end
context "and no stock owners have signed data sharing agreement" do
before do
parent_organisation = create(:organisation, :without_dpc)
create(:organisation_relationship, child_organisation: user.organisation, parent_organisation:)
end
it "does not render actions" do
expect(component.display_actions?).to eq(false)
end
end
end
end
end
end

Loading…
Cancel
Save