From 35012cfd052a7331db38abccf6c24957a7063ded Mon Sep 17 00:00:00 2001 From: edwin-jebaraj Date: Wed, 27 Nov 2024 19:45:14 +0000 Subject: [PATCH] Added evaluation due date update functionality --- .../cases/evaluation_due_dates_controller.rb | 30 +++++++++++++++++++ app/models/support/case.rb | 11 +++++++ .../cases/evaluation_due_dates/edit.html.erb | 12 ++++++++ config/locales/en.yml | 7 +++++ config/locales/validation/en.yml | 6 ++++ config/routes.rb | 1 + ...dd_evaluation_due_date_to_support_cases.rb | 5 ++++ db/schema.rb | 3 +- .../agent_can_add_evaluation_due_date_spec.rb | 28 +++++++++++++++++ spec/models/support/case_spec.rb | 2 +- 10 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 app/controllers/support/cases/evaluation_due_dates_controller.rb create mode 100644 app/views/support/cases/evaluation_due_dates/edit.html.erb create mode 100644 db/migrate/20241126122758_add_evaluation_due_date_to_support_cases.rb create mode 100644 spec/features/support/agent_can_add_evaluation_due_date_spec.rb diff --git a/app/controllers/support/cases/evaluation_due_dates_controller.rb b/app/controllers/support/cases/evaluation_due_dates_controller.rb new file mode 100644 index 000000000..878b461f6 --- /dev/null +++ b/app/controllers/support/cases/evaluation_due_dates_controller.rb @@ -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 diff --git a/app/models/support/case.rb b/app/models/support/case.rb index cfb02886b..68ff074c8 100644 --- a/app/models/support/case.rb +++ b/app/models/support/case.rb @@ -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| @@ -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 diff --git a/app/views/support/cases/evaluation_due_dates/edit.html.erb b/app/views/support/cases/evaluation_due_dates/edit.html.erb new file mode 100644 index 000000000..4a9b5a5fc --- /dev/null +++ b/app/views/support/cases/evaluation_due_dates/edit.html.erb @@ -0,0 +1,12 @@ +<%= render partial: "support/cases/components/case_header", locals: { current_case: @current_case } %> +

<%= I18n.t("support.cases.evaluation_due_date.header") %>

+ +<%= 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") } %> + +
+ <%= 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" %> +
+<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index dc1721414..d4906fe20 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 diff --git a/config/locales/validation/en.yml b/config/locales/validation/en.yml index 1ea4f39b5..09f8a32f6 100644 --- a/config/locales/validation/en.yml +++ b/config/locales/validation/en.yml @@ -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 diff --git a/config/routes.rb b/config/routes.rb index f7347ef9e..091660488 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/db/migrate/20241126122758_add_evaluation_due_date_to_support_cases.rb b/db/migrate/20241126122758_add_evaluation_due_date_to_support_cases.rb new file mode 100644 index 000000000..8c7bf6090 --- /dev/null +++ b/db/migrate/20241126122758_add_evaluation_due_date_to_support_cases.rb @@ -0,0 +1,5 @@ +class AddEvaluationDueDateToSupportCases < ActiveRecord::Migration[7.2] + def change + add_column :support_cases, :evaluation_due_date, :date + end +end diff --git a/db/schema.rb b/db/schema.rb index 1e6de7e1a..9ac9743f6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" @@ -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" diff --git a/spec/features/support/agent_can_add_evaluation_due_date_spec.rb b/spec/features/support/agent_can_add_evaluation_due_date_spec.rb new file mode 100644 index 000000000..f582cb15b --- /dev/null +++ b/spec/features/support/agent_can_add_evaluation_due_date_spec.rb @@ -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 diff --git a/spec/models/support/case_spec.rb b/spec/models/support/case_spec.rb index eda6d2af1..ac1912a4d 100644 --- a/spec/models/support/case_spec.rb +++ b/spec/models/support/case_spec.rb @@ -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