From 0bf2229ca76050ae555057e88b66d4f9e6d315d6 Mon Sep 17 00:00:00 2001 From: Serena Abbott Date: Wed, 11 Oct 2023 16:41:42 +0100 Subject: [PATCH] feat(rfh): edit confirmation email --- app/presenters/framework_request_presenter.rb | 18 ++++++++ app/services/submit_framework_request.rb | 14 +++++- app/services/support/email_templates.rb | 2 +- .../framework_request_presenter_spec.rb | 46 +++++++++++++++++++ 4 files changed, 78 insertions(+), 2 deletions(-) diff --git a/app/presenters/framework_request_presenter.rb b/app/presenters/framework_request_presenter.rb index df59b86fc..5678a35a4 100644 --- a/app/presenters/framework_request_presenter.rb +++ b/app/presenters/framework_request_presenter.rb @@ -29,6 +29,16 @@ def org_name end end + def org_name_or_number + return I18n.t("support.case_categorisations.label.none") if org_id.blank? + + if group && school_urns.present? + "#{school_urns.count} out of #{organisation.organisations.count} schools" + else + org_name + end + end + # TODO: extract into a look-up service rather than access supported data directly def group_type group_type_id = Support::EstablishmentGroup.find_by(uid: org_id)&.establishment_group_type_id @@ -40,6 +50,8 @@ def bill_count end def bill_filenames + return if energy_bills.empty? + energy_bills.map(&:filename).join(", ") end @@ -47,6 +59,12 @@ def document_count documents.count end + def document_filenames + return if documents.empty? + + documents.map(&:filename).join(", ") + end + def contract_length return if super.nil? diff --git a/app/services/submit_framework_request.rb b/app/services/submit_framework_request.rb index f4fcaa6a2..1d249340a 100644 --- a/app/services/submit_framework_request.rb +++ b/app/services/submit_framework_request.rb @@ -13,7 +13,7 @@ class SubmitFrameworkRequest # @!attribute template # @return [String] Template UUID - option :template, Types::String, default: proc { "621a9fe9-018c-425e-ae6e-709c6718fe8d" } + option :template, Types::String, default: proc { "f07f24e6-e0b8-4887-910a-8bf22e0575cd" } # @!attribute referrer # @return [String] @@ -104,7 +104,13 @@ def send_confirmation_email recipient: request.user, reference: @kase.ref, variables: { + no_of_schools: request.org_name_or_number, + selected_category: request.category.title, + contract_length: request.contract_length || "NA", + contract_start: request.contract_start_date || "NA", + total_spend: request.procurement_amount || "NA", message: request.message_body, + files_uploaded: request.bill_filenames || "NA", }, ).call else @@ -113,7 +119,13 @@ def send_confirmation_email reference: @kase.ref, template:, variables: { + no_of_schools: request.org_name_or_number, + selected_category: request.category.title, + contract_length: request.contract_length || "NA", + contract_start: request.contract_start_date || "NA", + total_spend: request.procurement_amount || "NA", message: request.message_body, + files_uploaded: request.document_filenames || "NA", }, ).call end diff --git a/app/services/support/email_templates.rb b/app/services/support/email_templates.rb index e52d5d725..d6661ce21 100644 --- a/app/services/support/email_templates.rb +++ b/app/services/support/email_templates.rb @@ -10,7 +10,7 @@ class EmailTemplates exit_survey: "134bc268-2c6b-4b74-b6f4-4a58e22d6c8b", all_cases_survey_open: "76f6f7ba-26d1-4c00-addd-12dc9d8d49fc", all_cases_survey_resolved: "a56e5c50-78d1-4b5f-a2ff-73df78b7ad99", - confirmation_energy: "2a2b7b46-2034-4e7b-aaec-4c9bf0b76f3f", + confirmation_energy: "a771c164-422a-4d70-8d2f-64f66c329dfa", }.freeze def self.label_for(id) diff --git a/spec/presenters/self-serve/framework_request_presenter_spec.rb b/spec/presenters/self-serve/framework_request_presenter_spec.rb index 4852e678a..947872cdb 100644 --- a/spec/presenters/self-serve/framework_request_presenter_spec.rb +++ b/spec/presenters/self-serve/framework_request_presenter_spec.rb @@ -52,4 +52,50 @@ expect(presenter.bill_filenames).to eq "file1.pdf, file2.pdf" end end + + describe "#document_filenames" do + before do + create(:document, filename: "file1.pdf", framework_request:) + create(:document, filename: "file2.pdf", framework_request:) + end + + it "returns the names of the document files" do + expect(presenter.document_filenames).to eq "file1.pdf, file2.pdf" + end + end + + describe "#org_name_or_number" do + let(:framework_request) { create(:framework_request, group: true, org_id: "abc") } + + context "when there are school urns within framework request" do + before do + framework_request.update!(school_urns: %w[1 2]) + create(:support_establishment_group, uid: "abc", establishment_group_type: create(:support_establishment_group_type, code: 2)) + create(:support_organisation, urn: "1", trust_code: "abc") + create(:support_organisation, urn: "2", trust_code: "abc") + create(:support_organisation, urn: "3", trust_code: "abc") + end + + it "returns the number of schools selected out of the available schools" do + expect(presenter.org_name_or_number).to eq "2 out of 3 schools" + end + end + + context "when there are no school urns within framework request" do + context "and the organisation is a single school" do + it "returns the school name" do + framework_request.update!(group: false, org_id: "000001") + create(:support_organisation, urn: "000001", name: "School #1") + expect(presenter.org_name_or_number).to eq "School #1" + end + end + + context "and the organisation is a group" + it "returns the group name" do + framework_request.update!(group: true, org_id: "123") + create(:support_establishment_group, uid: "123", name: "Group #1") + expect(presenter.org_name_or_number).to eq "Group #1" + end + end + end end