Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CDPT-2390 CT: Hide Send Commissioning Email button for Offender SAR Complaints #2534

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/policies/case/sar/offender_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ def can_record_data_request?
check_can_trigger_event(:add_data_received)
end

def can_send_day_1_email
MeenaModhvadia marked this conversation as resolved.
Show resolved Hide resolved
clear_failed_checks
check_can_trigger_event(:send_day_1_email)
end

def can_send_acknowledgement_letter?
clear_failed_checks
check_user_can_manage_offender_sar
Expand Down
2 changes: 1 addition & 1 deletion app/views/cases/data_request_areas/show.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ div class="case"
td
span = @commissioning_document&.download_link

- if @data_request_area.data_request_emails.blank? && policy(@case).can_record_data_request?
- if @data_request_area.data_request_emails.blank? && policy(@case).can_send_day_1_email?
div.button-holder
= link_to t('button.send_email'), send_email_case_data_request_area_path(@case, @data_request_area), class: 'button button-high data_request_area_send_email'

Expand Down
41 changes: 37 additions & 4 deletions spec/views/cases/data_request_areas/show_html_slim_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@
end

let(:can_record_data_request) { true }
let(:can_send_day_1_email) { true }

before do
allow(policy).to receive(:can_record_data_request?).and_return can_record_data_request
allow(policy).to receive(:can_send_day_1_email?).and_return can_send_day_1_email
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are mocking this value, then it's not actually testing if the behaviour changes for a complaint and a non-complaint. That is fine because the view spec shouldn't care about what kind of case it is. You should change the test names though.

You also need to add tests for the new method you have added in the offender_policy to test that it returns different values for a complaint and non-complaint.

end

context "when data request area has a data request" do
Expand All @@ -65,10 +67,12 @@
expect(row.edit.text).to eq "Edit"
end

it "displays the send 'commissioning email button'" do
request_count = data_request_area.data_requests.size
expect(request_count).to eq 1
expect(page.commissioning_document.button_send_email.text).to eq "Send commissioning email"
context "when case is not an offender SAR Complaint" do
it "displays the send 'commissioning email button'" do
request_count = data_request_area.data_requests.size
expect(request_count).to eq 1
expect(page.commissioning_document.button_send_email.text).to eq "Send commissioning email"
end
end

it "translates the data_request_area_type using the relevant key" do
Expand All @@ -77,6 +81,35 @@
end
end

context "when case is an offender SAR Complaint" do
let(:kase_offender_sar_complaint) do
create(
:offender_sar_complaint,
current_state: "to_be_assessed",
)
end

let(:data_request_area) { create :data_request_area, data_request_area_type: "prison", offender_sar_case: kase_offender_sar_complaint }

let(:can_send_day_1_email) { false }

before do
assign(:data_request, data_request)
assign(:data_request_area, data_request_area.decorate)
assign(:case, data_request_area.kase)
assign(:commissioning_document, data_request_area.commissioning_document.decorate)

render
data_request_area_show_page.load(rendered)
end

it "doesn't display the send 'commissioning email button'" do
request_count = data_request_area.data_requests.size
expect(request_count).to eq 1
expect { page.commissioning_document.button_send_email }.to raise_error(Capybara::ElementNotFound)
end
end

context "when data request area does not have any data requests" do
before do
assign(:data_request_area, data_request_area.decorate)
Expand Down
Loading