Skip to content

Commit

Permalink
Added evaluation due date update functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
edwin-jebaraj committed Nov 27, 2024
1 parent 7b3a466 commit 35012cf
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 2 deletions.
30 changes: 30 additions & 0 deletions app/controllers/support/cases/evaluation_due_dates_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module Support
class Cases::EvaluationDueDatesController < Cases::ApplicationController
before_action :set_current_case
before_action { @back_url = support_case_tasklist_path(params[:case_id]) }
def edit
@evaluation_due_date = @current_case
end

def update
@evaluation_due_date = Support::Case.find(params[:case_id])
@evaluation_due_date.assign_attributes(evaluaton_due_date_params)

if @evaluation_due_date.save(context: :update_due_date_form)
redirect_to edit_support_case_evaluation_due_dates_path(case_id: @current_case)
else
render :edit
end
end

private

def set_current_case
@current_case = Support::Case.find(params[:case_id])
end

def evaluaton_due_date_params
params.require(:support_case).permit(:evaluation_due_date)
end
end
end
11 changes: 11 additions & 0 deletions app/models/support/case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ class Case < ApplicationRecord
before_validation :generate_ref
validates :ref, uniqueness: true, length: { is: 6 }, format: { with: /\A\d+\z/, message: "numbers only" }

validates :evaluation_due_date, presence: true, on: :update_due_date_form
validate :evaluation_due_date_must_be_in_the_future, on: :update_due_date_form

# @return [String]
def self.to_csv
CSV.generate(headers: true) do |csv|
Expand Down Expand Up @@ -205,5 +208,13 @@ def assign_to_agent(agent, assigned_by: Current.agent)
update!(agent:)
agent.notify_assigned_to_case(support_case: self, assigned_by:)
end

private

def evaluation_due_date_must_be_in_the_future
if evaluation_due_date.present? && evaluation_due_date <= Time.zone.today
errors.add(:evaluation_due_date, :evaluation_due_date_must_be_in_the_future)
end
end
end
end
12 changes: 12 additions & 0 deletions app/views/support/cases/evaluation_due_dates/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<%= render partial: "support/cases/components/case_header", locals: { current_case: @current_case } %>
<h1 class="govuk-heading-l"><%= I18n.t("support.cases.evaluation_due_date.header") %></h1>

<%= form_with model: @evaluation_due_date, url: support_case_evaluation_due_dates_path(@current_case), method: :patch do |form| %>
<%= form.govuk_error_summary %>
<%= form.govuk_date_field :evaluation_due_date, legend: { text: I18n.t("support.cases.evaluation_due_date.date.label"), }, hint: { text: I18n.t("support.cases.evaluation_due_date.date.hint") } %>

<div class="govuk-button-group flex-align-center">
<%= form.submit I18n.t("support.cases.evaluation_due_date.submit"), class: "govuk-button" %>
<%= link_to I18n.t("support.cases.evaluation_due_date.cancel"), @back_url, class: "govuk-link govuk-link--no-visited-state" %>
</div>
<% end %>
7 changes: 7 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,13 @@ en:
cases:
my_cases:
header_link: My cases
evaluation_due_date:
header: Set due date
date:
label: When does the evaluation need to be completed by?
hint: For example, 27 3 2025
submit: Continue
cancel: Cancel
emails:
button:
mark_as_read: Mark as read
Expand Down
6 changes: 6 additions & 0 deletions config/locales/validation/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ en:
blank: Enter provider end date
unique_name_and_provider: The combination of name and provider must be unique

support/case:
attributes:
evaluation_due_date:
blank: Enter the evaluation due date
evaluation_due_date_must_be_in_the_future: Evaluation due date must be in the future

request:
rules:
procurement_amount: "" # Omitted
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@
resources :contracts, only: %i[edit update]
resources :additional_contacts
resources :evaluators, except: %i[show]
resource :evaluation_due_dates, only: %i[edit update]
resource :email, only: %i[create] do
scope module: :emails do
resources :content, only: %i[show], param: :template
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddEvaluationDueDateToSupportCases < ActiveRecord::Migration[7.2]
def change
add_column :support_cases, :evaluation_due_date, :date
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.2].define(version: 2024_11_25_131721) do
ActiveRecord::Schema[7.2].define(version: 2024_11_26_122758) do
create_sequence "evaluation_refs"
create_sequence "framework_refs"

Expand Down Expand Up @@ -623,6 +623,7 @@
t.string "project"
t.string "other_school_urns", default: [], array: true
t.boolean "is_evaluator", default: false
t.date "evaluation_due_date"
t.index ["category_id"], name: "index_support_cases_on_category_id"
t.index ["existing_contract_id"], name: "index_support_cases_on_existing_contract_id"
t.index ["new_contract_id"], name: "index_support_cases_on_new_contract_id"
Expand Down
28 changes: 28 additions & 0 deletions spec/features/support/agent_can_add_evaluation_due_date_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require "rails_helper"

describe "Edit evaluation due date", :js do
include_context "with an agent"

let(:support_case) { create(:support_case) }

specify "Update evaluation due date evaluators" do
visit edit_support_case_evaluation_due_dates_path(case_id: support_case)

expect(page).to have_text("Set due date")
expect(page).to have_text("When does the evaluation need to be completed by?")

fill_in "Day", with: ""
fill_in "Month", with: ""
fill_in "Year", with: ""
click_button "Continue"

expect(page).to have_text("Enter the evaluation due date")

fill_in "Day", with: Date.yesterday.day
fill_in "Month", with: Date.yesterday.month
fill_in "Year", with: Date.yesterday.year
click_button "Continue"

expect(page).to have_text("Evaluation due date must be in the future")
end
end
2 changes: 1 addition & 1 deletion spec/models/support/case_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
describe "#to_csv" do
it "includes headers" do
expect(described_class.to_csv).to eql(
"id,ref,category_id,request_text,support_level,status,state,created_at,updated_at,agent_id,first_name,last_name,email,phone_number,source,organisation_id,existing_contract_id,new_contract_id,procurement_id,savings_status,savings_estimate_method,savings_actual_method,savings_estimate,savings_actual,action_required,organisation_type,value,closure_reason,extension_number,other_category,other_query,procurement_amount,confidence_level,special_requirements,query_id,exit_survey_sent,detected_category_id,creation_source,user_selected_category,created_by_id,procurement_stage_id,initial_request_text,with_school,next_key_date,next_key_date_description,discovery_method,discovery_method_other_text,project,other_school_urns,is_evaluator\n",
"id,ref,category_id,request_text,support_level,status,state,created_at,updated_at,agent_id,first_name,last_name,email,phone_number,source,organisation_id,existing_contract_id,new_contract_id,procurement_id,savings_status,savings_estimate_method,savings_actual_method,savings_estimate,savings_actual,action_required,organisation_type,value,closure_reason,extension_number,other_category,other_query,procurement_amount,confidence_level,special_requirements,query_id,exit_survey_sent,detected_category_id,creation_source,user_selected_category,created_by_id,procurement_stage_id,initial_request_text,with_school,next_key_date,next_key_date_description,discovery_method,discovery_method_other_text,project,other_school_urns,is_evaluator,evaluation_due_date\n",
)
end
end
Expand Down

0 comments on commit 35012cf

Please sign in to comment.