From f1841ad653743f25564b5c73f8e0287359255a94 Mon Sep 17 00:00:00 2001 From: edwin-jebaraj Date: Thu, 23 Jan 2025 16:16:44 +0000 Subject: [PATCH] Updated parsing method for case without sub category --- .../email_evaluators_variable_parser.rb | 2 +- spec/factories/support/case.rb | 4 + .../agent_can_email_to_evaluators_spec.rb | 76 ++++++++++++++++++- 3 files changed, 77 insertions(+), 5 deletions(-) diff --git a/app/services/support/email_evaluators_variable_parser.rb b/app/services/support/email_evaluators_variable_parser.rb index c9f7619f6..dd693da2d 100644 --- a/app/services/support/email_evaluators_variable_parser.rb +++ b/app/services/support/email_evaluators_variable_parser.rb @@ -11,7 +11,7 @@ def initialize(current_case, email_evaluators, unique_link) def variables { "organisation_name" => @current_case.organisation_name || @current_case.email, - "sub_category" => @current_case.sub_category_with_indefinite_article || "[sub_category]", + "sub_category" => @current_case.sub_category ? @current_case.sub_category_with_indefinite_article : "a", "unique_case_specific_link" => link_to("unique case-specific link", @unique_link, target: "_blank", rel: "noopener noreferrer"), "evaluation_due_date" => @current_case.evaluation_due_date.strftime("%d %B %Y"), } diff --git a/spec/factories/support/case.rb b/spec/factories/support/case.rb index 50795cf21..fad0fda66 100644 --- a/spec/factories/support/case.rb +++ b/spec/factories/support/case.rb @@ -90,5 +90,9 @@ trait :stage_unspecified do association :procurement, factory: %i[support_procurement stage_unspecified] end + + trait :with_support_category do + association :category, factory: :support_category, title: "Audit Accessibility (buildings and digital)" + end end end diff --git a/spec/features/support/agent_can_email_to_evaluators_spec.rb b/spec/features/support/agent_can_email_to_evaluators_spec.rb index 4ed70ad33..bae1dca62 100644 --- a/spec/features/support/agent_can_email_to_evaluators_spec.rb +++ b/spec/features/support/agent_can_email_to_evaluators_spec.rb @@ -8,6 +8,19 @@ let(:file_2) { fixture_file_upload(Rails.root.join("spec/fixtures/support/another-text-file.txt"), "text/plain") } let(:document_uploader) { support_case.document_uploader(files: [file_1, file_2]) } + before do + create(:support_email_template, title: "Invitation to complete procurement evaluation", subject: "about energy", body: "Test body {{sub_category}} ") + end + + def create_evaluator_and_upload_document + support_case.evaluators.create!(first_name: "Momo", last_name: "Taro", email: "email@address") + document_uploader.save! + end + + def send_email_to_evaluators(support_case) + create(:support_email, :inbox, ticket: support_case, outlook_conversation_id: "OCID1", subject: "Email Evaluators", recipients: [{ "name" => "Test 1", "address" => "test1@email.com" }], unique_body: "Email 1", is_read: false) + end + specify "When add evaluators, set due date and upload documents status are not complete" do visit support_case_path(support_case, anchor: "tasklist") @@ -29,9 +42,9 @@ specify "When add evaluators, set due date and upload documents status are complete" do support_case.update!(evaluation_due_date: Date.tomorrow, has_uploaded_documents: true) - support_case.evaluators.create!(first_name: "Momo", last_name: "Taro", email: "email@address") - document_uploader.save! - create(:support_email_template, title: "Invitation to complete procurement evaluation", subject: "about energy", body: "energy body") + + create_evaluator_and_upload_document + support_case.reload visit support_case_path(support_case, anchor: "tasklist") @@ -42,11 +55,66 @@ expect(page).to have_content("Email evaluators") - create(:support_email, :inbox, ticket: support_case, outlook_conversation_id: "OCID1", subject: "Email Evaluators", recipients: [{ "name" => "Test 1", "address" => "test1@email.com" }], unique_body: "Email 1", is_read: false) + send_email_to_evaluators(support_case) + support_case.update!(sent_email_to_evaluators: true) visit support_case_path(support_case, anchor: "tasklist") expect(find("#complete-evaluation-4-status")).to have_text("Complete") end + + context "without sub_category" do + it "sends support email" do + support_case.update!(evaluation_due_date: Date.tomorrow, has_uploaded_documents: true, category_id: nil) + + create_evaluator_and_upload_document + + support_case.reload + + visit support_case_path(support_case, anchor: "tasklist") + + expect(find("#complete-evaluation-4-status")).to have_text("To do") + + visit edit_support_case_email_evaluators_path(support_case) + + expect(page).not_to have_content("an Audit Accessibility (buildings and digital)") + + send_email_to_evaluators(support_case) + + support_case.update!(sent_email_to_evaluators: true) + + visit support_case_path(support_case, anchor: "tasklist") + + expect(find("#complete-evaluation-4-status")).to have_text("Complete") + end + end + + context "with sub_category" do + let(:support_case) { create(:support_case, :with_support_category) } + + it "sends support email" do + support_case.update!(evaluation_due_date: Date.tomorrow, has_uploaded_documents: true) + + create_evaluator_and_upload_document + + support_case.reload + + visit support_case_path(support_case, anchor: "tasklist") + + expect(find("#complete-evaluation-4-status")).to have_text("To do") + + visit edit_support_case_email_evaluators_path(support_case) + + expect(page).to have_content("an Audit Accessibility (buildings and digital)") + + send_email_to_evaluators(support_case) + + support_case.update!(sent_email_to_evaluators: true) + + visit support_case_path(support_case, anchor: "tasklist") + + expect(find("#complete-evaluation-4-status")).to have_text("Complete") + end + end end