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

1574 - feat(rfh): edit confirmation email #1634

Merged
merged 1 commit into from
Oct 19, 2023
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
18 changes: 18 additions & 0 deletions app/presenters/framework_request_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -40,13 +50,21 @@ def bill_count
end

def bill_filenames
return if energy_bills.empty?

energy_bills.map(&:filename).join(", ")
end

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?

Expand Down
14 changes: 13 additions & 1 deletion app/services/submit_framework_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/services/support/email_templates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
46 changes: 46 additions & 0 deletions spec/presenters/self-serve/framework_request_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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