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

Ability to update problem description on a case #899

Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.case_management.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog 1.0.0].

## [unreleased]

- Agent can update the problem description on a case [#ref](https://github.com/DFE-Digital/buy-for-your-school/pull/899)
- Agent can save email attachments to a case [#ref](https://github.com/DFE-Digital/buy-for-your-school/pull/896)
- Agent can reopen, close and place a case on-hold, while incoming emails on closed cases create a new case, and reopens resolved cases. Agent can also track the time a state transition occurred [#ref](https://github.com/DFE-Digital/buy-for-your-school/pull/887)

Expand Down
26 changes: 25 additions & 1 deletion app/controllers/support/cases_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Support
class CasesController < Cases::ApplicationController
require "will_paginate/array"
before_action :current_case, only: %i[show]
before_action :current_case, only: %i[show edit]

include Concerns::HasInteraction

Expand Down Expand Up @@ -41,6 +41,22 @@ def create
end
end

def edit
return redirect_to support_case_path(current_case) unless current_case.created_manually?

@back_url = support_case_path(current_case)
end

def update
@form = EditCaseForm.from_validation(edit_validation)
if edit_validation.success?
current_case.update!(**@form.to_h)
redirect_to support_case_path(current_case), notice: I18n.t("support.case_description.flash.updated")
else
render :edit
end
end

private

# @return [CasePresenter, nil]
Expand All @@ -52,6 +68,10 @@ def validation
CreateCaseFormSchema.new.call(**form_params)
end

def edit_validation
EditCaseFormSchema.new.call(**edit_form_params)
end

def form_params
params.require(:create_case_form).permit(
:organisation_urn,
Expand All @@ -71,5 +91,9 @@ def form_params
:request_type,
)
end

def edit_form_params
params.require(:edit_case_form).permit(:request_text)
end
end
end
15 changes: 15 additions & 0 deletions app/forms/support/edit_case_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module Support
class EditCaseForm
extend Dry::Initializer
include Concerns::ValidatableForm

option :request_text, optional: true

# @return [Hash] form parms as request attributes
def to_h
self.class.dry_initializer.attributes(self).except(:messages)
end
end
end
7 changes: 7 additions & 0 deletions app/forms/support/edit_case_form_schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Support
class EditCaseFormSchema < ::Support::Schema
params do
optional(:request_text).value(:string)
end
end
end
7 changes: 7 additions & 0 deletions app/presenters/support/case_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ def last_updated_at_date
Time.zone.parse(last_updated_at)
end

# true if the case source is `nw_hub`, `sw_hub` or nil
#
# @return [Boolean]
def created_manually?
["nw_hub", "sw_hub", nil].any? { |t| t == source }
end

private

# @return [String] 20 March 2021 at 12:00
Expand Down
6 changes: 5 additions & 1 deletion app/views/support/cases/_case_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
<dd class="govuk-summary-list__value">
<%= current_case.request_text %>
</dd>
<dd class="govuk-summary-list__actions"></dd>
<dd class="govuk-summary-list__actions">
<% if current_case.created_manually? %>
<%= link_to I18n.t("support.case.link.edit_description"), edit_support_case_path(current_case), class: "govuk-link" %>
<% end %>
</dd>
</div>

<div class="govuk-summary-list__row">
Expand Down
11 changes: 11 additions & 0 deletions app/views/support/cases/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= form_with model: @current_case, scope: :edit_case_form, url: support_case_path(@current_case), method: :patch do |form| %>
<%= form.govuk_error_summary %>

<%= form.govuk_text_area :request_text, autofocus: true, rows: 5, label: { text: I18n.t("support.case_description.header"), size: "l" } %>

<%= form.submit I18n.t("support.case_description.submit"), class: "govuk-button" %>
<% end %>
</div>
</div>
7 changes: 7 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@ en:
all_cases: All cases
link:
edit_category: Change
edit_description: Change
view_school_information: View school information (opens in a new tab)
view_group_information: View group information (opens in a new tab)

Expand Down Expand Up @@ -866,6 +867,12 @@ en:
cases:
my_cases:
header_link: My cases

case_description:
header: Update description of problem
flash:
updated: Description of problem updated successfully
submit: Save changes

save_attachments:
initiate_journey: Save attachments
Expand Down
45 changes: 45 additions & 0 deletions spec/features/support/case_description_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
RSpec.describe "Case problem description" do
include_context "with an agent"

before do
click_button "Agent Login"
end

context "when a case is created via 'create a case'" do
# 'create a case' includes case source types 'nw_hub', 'sw_hub' and nil

let(:support_case) { create(:support_case, source: nil) }

before do
visit "/support/cases/#{support_case.id}"
end

it "shows a change link for the problem description in case details" do
within("div#case-details") do
within(all("div.govuk-summary-list__row")[1]) do
expect(page).to have_text "Description of problem"
expect(page).to have_text "This is an example request for support - please help!"
expect(page).to have_link "Change", href: "/support/cases/#{support_case.id}/edit", class: "govuk-link"
end
end
end

it "allows a user to update the problem description" do
within("div#case-details") do
within(all("div.govuk-summary-list__row")[1]) do
click_on "Change"
end
end

fill_in "edit_case_form[request_text]", with: "updated problem"
click_button "Save changes"
expect(page).to have_text "Description of problem updated successfully"

within("div#case-details") do
within(all("div.govuk-summary-list__row")[1]) do
expect(page).to have_text "updated problem"
end
end
end
end
end
78 changes: 78 additions & 0 deletions spec/forms/support/create_case_form_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
RSpec.describe Support::CreateCaseForm, type: :model do
subject(:form) { described_class.new }

describe "#case_type" do
context "when there is no hub case reference" do
it "is nil" do
expect(form.case_type).to be_nil
end
end

context "when hub case reference is an integer in range 1000-99_999" do
subject(:form) { described_class.new(hub_case_ref: "5400") }

it "is nw_hub" do
expect(form.case_type).to eq "nw_hub"
end
end

context "when hub case reference is prefixed with 'ce-'" do
subject(:form) { described_class.new(hub_case_ref: "CE-553") }

it "is sw_hub" do
expect(form.case_type).to eq "sw_hub"
end
end
end

describe "#to_h" do
subject(:form) do
described_class.new(
organisation_id: "123",
organisation_type: "school",
organisation_name: "Test School",
organisation_urn: "321",
first_name: "Test",
last_name: "User",
email: "test@test.com",
phone_number: "5554321",
category_id: "987",
hub_case_ref: "CE-553",
estimated_procurement_completion_date: "2022-01-01",
estimated_savings: "25000",
hub_notes: "note",
progress_notes: "progress",
request_type: "true",
)
end

it "returns form values" do
expect(form.to_h).to eql({
organisation_id: "123",
organisation_type: "school",
organisation_name: "Test School",
organisation_urn: "321",
first_name: "Test",
last_name: "User",
email: "test@test.com",
phone_number: "5554321",
category_id: "987",
hub_case_ref: "CE-553",
estimated_procurement_completion_date: "2022-01-01",
estimated_savings: "25000",
hub_notes: "note",
progress_notes: "progress",
source: "sw_hub",
})
end
end

describe "#request_type?" do
it "returns field value" do
form = described_class.new(request_type: "true")
expect(form.request_type?).to eq true
form = described_class.new(request_type: "false")
expect(form.request_type?).to eq false
end
end
end
13 changes: 13 additions & 0 deletions spec/forms/support/edit_case_form_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
RSpec.describe Support::EditCaseForm, type: :model do
subject(:form) { described_class.new }

describe "#to_h" do
subject(:form) { described_class.new(request_text: "help") }

it "returns form values" do
expect(form.to_h).to eql({
request_text: "help",
})
end
end
end
24 changes: 24 additions & 0 deletions spec/presenters/support/case_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,28 @@
end
end
end

describe "#created_manually?" do
context "when case source is 'nw_hub', 'sw_hub' or nil" do
it "is true" do
support_case.nw_hub!
expect(presenter.created_manually?).to eq true
support_case.sw_hub!
expect(presenter.created_manually?).to eq true
support_case.source = nil
expect(presenter.created_manually?).to eq true
end
end

context "when case source is not 'nw_hub', 'sw_hub' or nil" do
it "is false" do
support_case.digital!
expect(presenter.created_manually?).to eq false
support_case.incoming_email!
expect(presenter.created_manually?).to eq false
support_case.faf!
expect(presenter.created_manually?).to eq false
end
end
end
end