Skip to content

Commit

Permalink
PWNN-1653 Request Case Origin from E&O during Create Case
Browse files Browse the repository at this point in the history
  • Loading branch information
cocoaken committed Sep 25, 2023
1 parent 5a6827d commit 67795a0
Show file tree
Hide file tree
Showing 22 changed files with 179 additions and 47 deletions.
2 changes: 2 additions & 0 deletions app/controllers/engagement/cases_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ def form_params
:email,
:phone_number,
:extension_number,
:discovery_method,
:discovery_method_other_text,
:category_id,
:query_id,
:other_category,
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/support/cases/previews_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def form_params
:email,
:phone_number,
:extension_number,
:discovery_method,
:discovery_method_other_text,
:category_id,
:query_id,
:other_category,
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/support/cases_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ def form_params
:email,
:phone_number,
:extension_number,
:discovery_method,
:discovery_method_other_text,
:category_id,
:query_id,
:estimated_procurement_completion_date,
Expand Down
2 changes: 2 additions & 0 deletions app/forms/support/create_case_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class CreateCaseForm
option :email, optional: true
option :phone_number, optional: true
option :extension_number, optional: true
option :discovery_method, optional: true
option :discovery_method_other_text, optional: true
option :source, optional: true
option :creation_source, optional: true
option :procurement_amount, ->(value) { value&.gsub(/[£,]/, "") }, optional: true
Expand Down
13 changes: 13 additions & 0 deletions app/forms/support/create_case_form_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class CreateCaseFormSchema < ::Support::Schema
required(:last_name).value(:string)
required(:email).value(:string)
required(:source).value(:string)

required(:discovery_method).value(:integer)
required(:discovery_method_other_text).value(:str?)

optional(:organisation_id).value(:string)
optional(:organisation_type).value(:string)
optional(:organisation_name).value(:string)
Expand Down Expand Up @@ -60,6 +64,15 @@ class CreateCaseFormSchema < ::Support::Schema
key(:source).failure(:missing) if value.blank?
end

rule(:discovery_method) do
key.failure(:invalid) if
value < (Support::Case.discovery_methods.values.min) || value > (Support::Case.discovery_methods.values.max)
end

rule(:discovery_method_other_text) do
key(:discovery_method_other_text).failure(:missing) if value.blank? && values[:discovery_method].eql?(Support::Case.discovery_methods.keys.index("other"))
end

rule(:procurement_amount) do
validator = Support::Forms::ValidateProcurementAmount.new(value)
key(:procurement_amount).failure(:invalid) if validator.invalid_number?
Expand Down
12 changes: 12 additions & 0 deletions app/models/support/case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ class Case < ApplicationRecord
# faf - find a framework
enum source: { digital: 0, nw_hub: 1, sw_hub: 2, incoming_email: 3, faf: 4, engagement_and_outreach: 5, schools_commercial_team: 6, engagement_and_outreach_cms: 7 }

# Discovery Method
#
# used_before - I've used this service before
# meeting_or_event - Meeting or event
# newsletter - Newsletter
# recommendation - Recommendation
# search_engine - Search engine, such as Google
# social_media - Social media, such as Twitter
# website - Website, such as GOV.UK
# other - Other
enum discovery_method: { used_before: 0, meeting_or_event: 1, newsletter: 2, recommendation: 3, search_engine: 4, social_media: 5, website: 6, other: 7 }

# Creation Source
#
# default - created by a member of the ProcOps team
Expand Down
2 changes: 2 additions & 0 deletions app/services/support/create_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def call
email: @attrs[:email],
phone_number: @attrs[:phone_number],
extension_number: @attrs[:extension_number],
discovery_method: @attrs[:discovery_method],
discovery_method_other_text: @attrs[:discovery_method_other_text],
request_text: @attrs[:request_text],
action_required: @attrs.fetch(:action_required, false),
procurement_amount: @attrs[:procurement_amount],
Expand Down
2 changes: 2 additions & 0 deletions app/views/engagement/cases/forms/_create_case_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
<%= form.govuk_phone_field :phone_number, label: { text: I18n.t("support.case_hub_migration.label.phone_number", optional: I18n.t("support.generic.form.optional")) } %>
<%= form.govuk_phone_field :extension_number, label: { text: I18n.t("support.case_hub_migration.label.extension_number", optional: I18n.t("support.generic.form.optional")) } %>

<%= render "support/cases/discovery_method/discovery_method", form: form %>

<%= render "support/cases/request_details/form_fields", form: form, show_request_text: false %>

<%= form.govuk_text_field :procurement_amount, width: 5,
Expand Down
35 changes: 20 additions & 15 deletions app/views/engagement/cases/previews/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,26 @@
</dd>
</div>
</dl>

<h2 class="govuk-heading-m">
<%= I18n.t("support.case.label.discovery_method.legend") %>
</h2>

<dl class="govuk-summary-list govuk-!-margin-bottom-9">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= I18n.t("support.case.label.discovery_method.field") %>
</dt>
<dd class="govuk-summary-list__value">
<%= I18n.t("support.case.label.discovery_method.#{Support::Case::discovery_methods.keys[@form.discovery_method]}") %>
<%= if @form.discovery_method == Support::Case::discovery_methods[:other] && !@form.discovery_method_other_text.empty? then "- #{@form.discovery_method_other_text}" end %>
</dd>
<dd id="changeDiscoveryMethod" class="govuk-summary-list__actions">
<%= form.button I18n.t("generic.button.change_answer"), class: "govuk-link", value: "change" %>
</dd>
</div>
</dl>


<h2 class="govuk-heading-m">
<%= I18n.t("support.case_hub_migration.edit.section.case") %>
Expand Down Expand Up @@ -163,21 +183,6 @@
<% end %>
</dl>

<h2 class="govuk-heading-m">
<%= I18n.t("support.case_hub_migration.edit.section.source") %>
</h2>

<dl class="govuk-summary-list govuk-!-margin-bottom-9">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= I18n.t("support.case_hub_migration.label.case_source") %>
</dt>
<dd class="govuk-summary-list__value">
<%= I18n.t("support.case.label.source.#{@form.source}") %>
</dd>
</div>
</dl>

<h2 class="govuk-heading-m">
<%= I18n.t("support.case_hub_migration.edit.section.request_text") %>
</h2>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%= form.govuk_radio_buttons_fieldset :discovery_method, class: "discovery-method-radios", legend: { size: 'm', text: I18n.t("support.case.label.discovery_method.legend") } do %>

<%= form.govuk_radio_button :discovery_method, '0', label: { text: I18n.t("support.case.label.discovery_method.used_before") }, link_errors: true %>
<%= form.govuk_radio_button :discovery_method, '1', label: { text: I18n.t("support.case.label.discovery_method.meeting_or_event") } %>
<%= form.govuk_radio_button :discovery_method, '2', label: { text: I18n.t("support.case.label.discovery_method.newsletter") } %>
<%= form.govuk_radio_button :discovery_method, '3', label: { text: I18n.t("support.case.label.discovery_method.recommendation") } %>
<%= form.govuk_radio_button :discovery_method, '4', label: { text: I18n.t("support.case.label.discovery_method.search_engine") } %>
<%= form.govuk_radio_button :discovery_method, '5', label: { text: I18n.t("support.case.label.discovery_method.social_media") } %>
<%= form.govuk_radio_button :discovery_method, '6', label: { text: I18n.t("support.case.label.discovery_method.website") } %>
<%= form.govuk_radio_button :discovery_method, '7', label: { text: I18n.t("support.case.label.discovery_method.other") } do %>
<%= form.govuk_text_field :discovery_method_other_text,
id: "discovery_method_other_text",
label: { text: I18n.t("support.case.label.discovery_method.other_text_field") },
link_errors: true
%>
<% end %>
<% end %>
4 changes: 2 additions & 2 deletions app/views/support/cases/forms/_create_case_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
label: { text: I18n.t("support.case_hub_migration.label.extension_number", optional: I18n.t("support.generic.form.optional")) }
%>

<%= render "support/cases/discovery_method/discovery_method", form: form %>

<%= render "support/cases/request_details/form_fields", form: form, show_request_text: false %>

<%= form.govuk_text_field :procurement_amount, width: 5,
Expand All @@ -55,8 +57,6 @@
<%= form.govuk_select(:source,
[
["Please select", ""],
[I18n.t("support.case.label.source.nw_hub"), "nw_hub"],
[I18n.t("support.case.label.source.sw_hub"), "sw_hub"],
[I18n.t("support.case.label.source.engagement_and_outreach"), "engagement_and_outreach"],
[I18n.t("support.case.label.source.schools_commercial_team"), "schools_commercial_team"]
],
Expand Down
58 changes: 39 additions & 19 deletions app/views/support/cases/previews/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,44 @@
</dd>
</div>
</dl>

<h2 class="govuk-heading-m">
<%= I18n.t("support.case.label.discovery_method.legend") %>
</h2>

<dl class="govuk-summary-list govuk-!-margin-bottom-9">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= I18n.t("support.case.label.discovery_method.field") %>
</dt>
<dd class="govuk-summary-list__value">
<%= I18n.t("support.case.label.discovery_method.#{Support::Case::discovery_methods.keys[@form.discovery_method]}") %>
<%= if @form.discovery_method == Support::Case::discovery_methods[:other] && !@form.discovery_method_other_text.empty? then "- #{@form.discovery_method_other_text}" end %>
</dd>
<dd id="changeDiscoveryMethod" class="govuk-summary-list__actions">
<%= form.button I18n.t("generic.button.change_answer"), class: "govuk-link", value: "change" %>
</dd>
</div>
</dl>

<h2 class="govuk-heading-m">
<%= I18n.t("support.case_hub_migration.edit.section.source") %>
</h2>

<dl class="govuk-summary-list govuk-!-margin-bottom-9">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= I18n.t("support.case_hub_migration.label.case_source") %>
</dt>
<dd class="govuk-summary-list__value">
<%= I18n.t("support.case.label.source.#{@form.source}") %>
</dd>
<dd id="changeSource" class="govuk-summary-list__list__actions">
<%= form.button I18n.t("generic.button.change_answer"), class: "govuk-link", value: "change" %>
</dd>
</div>
</dl>


<h2 class="govuk-heading-m">
<%= I18n.t("support.case_hub_migration.edit.section.case") %>
Expand Down Expand Up @@ -163,25 +201,7 @@
</div>
<% end %>
</dl>

<h2 class="govuk-heading-m">
<%= I18n.t("support.case_hub_migration.edit.section.source") %>
</h2>

<dl class="govuk-summary-list govuk-!-margin-bottom-9">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= I18n.t("support.case_hub_migration.label.case_source") %>
</dt>
<dd class="govuk-summary-list__value">
<%= I18n.t("support.case.label.source.#{@form.source}") %>
</dd>
<dd id="changeSource" class="govuk-summary-list__list__actions">
<%= form.button I18n.t("generic.button.change_answer"), class: "govuk-link", value: "change" %>
</dd>
</div>
</dl>


<h2 class="govuk-heading-m">
<%= I18n.t("support.case_hub_migration.edit.section.request_text") %>
</h2>
Expand Down
15 changes: 15 additions & 0 deletions app/views/support/cases/show/_case_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@
<dd class="govuk-summary-list__actions"></dd>
</div>

<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= I18n.t("support.case.label.discovery_method.field") %>
</dt>
<dd class="govuk-summary-list__value">
<% if current_case.discovery_method.present? %>
<%= I18n.t("support.case.label.discovery_method.#{current_case.discovery_method}") %>
<%= if current_case.other? && !current_case.discovery_method_other_text.empty? then "- #{current_case.discovery_method_other_text}" end %>
<% else %>
<%= "Unknown" %>
<% end %>
</dd>
<dd class="govuk-summary-list__actions"></dd>
</div>

<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= I18n.t("support.case.label.source.header") %>
Expand Down
13 changes: 13 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,19 @@ en:
schools_commercial_team: Schools Commercial Team (SCT)
sw_hub: South West (SW) Hub
unspecified: "-"
discovery_method:
legend: Case origin
field: Origin
please_select: Please select
other_text_field: Please specify origin
used_before: Used this service before
meeting_or_event: Meeting or event
newsletter: Newsletter
recommendation: Recommendation
search_engine: Search engine, such as Google
social_media: Social media, such as Twitter
website: Website, such as GOV.UK
other: Other
special_requirements: Accessibility
stage: Stage
state:
Expand Down
8 changes: 8 additions & 0 deletions config/locales/validation/support/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ en:
last_name: "" # Omitted
email: "" # Omitted
phone_number: Phone number
discovery_method: Case origin # Omitted
discovery_method_other_text: "" # Omitted
estimated_procurement_completion_date: Estimated procurement date
organisation_id: "" # Omitted
organisation_name: "" # Omitted
Expand Down Expand Up @@ -148,6 +150,12 @@ en:
# value in schema set to 13 as includes the + in +44
max_size?: "can not have more than 12 digits"

discovery_method:
missing: Select how you heard about this service
invalid: unknown selection
discovery_method_other_text:
missing: Explain how you heard about this service

estimated_procurement_completion_date:
format?: must follow the format of DD/MM/YYYY
category_id:
Expand Down
8 changes: 8 additions & 0 deletions db/migrate/20230906141522_add_discovery_method_to_case.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class AddDiscoveryMethodToCase < ActiveRecord::Migration[7.0]
def change
change_table :support_cases, bulk: true do |t|
t.integer :discovery_method
t.string :discovery_method_other_text
end
end
end
2 changes: 2 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,8 @@
t.boolean "with_school", default: false, null: false
t.date "next_key_date"
t.string "next_key_date_description"
t.integer "discovery_method"
t.string "discovery_method_other_text"
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
1 change: 1 addition & 0 deletions spec/features/engagement/create_case_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def valid_form_data_without_organisation
fill_in "create_case_form[last_name]", with: "last_name"
fill_in "create_case_form[email]", with: "[email protected]"
fill_in "create_case_form[phone_number]", with: "0778974653"
choose "Newsletter" # case origin
choose "Procurement" # request type
select "Other (General)", from: "select_request_details_category_id"
find("#request_details_other_category_text").set("Other Category Details")
Expand Down
16 changes: 10 additions & 6 deletions spec/features/support/case_summary_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,24 @@
context "when value and support level have been set to nil" do
let(:support_case) { create(:support_case, :with_fixed_category, :opened, value: nil, support_level: nil) }

it "shows hypens" do
it "shows hyphens" do
within("div#case-details") do
expect(all("dt.govuk-summary-list__key")[0]).to have_text "Sub-category"
expect(all("dd.govuk-summary-list__value")[0]).to have_text "Fixed Category"
expect(all("dt.govuk-summary-list__key")[1]).to have_text "Case level"
expect(all("dd.govuk-summary-list__value")[1]).to have_text "Not specified"
expect(all("dt.govuk-summary-list__key")[2]).to have_text "Case value"
expect(all("dd.govuk-summary-list__value")[2]).to have_text "Not specified"
expect(all("dt.govuk-summary-list__key")[3]).to have_text "Source"
expect(all("dd.govuk-summary-list__value")[3]).to have_text "-"
expect(all("dt.govuk-summary-list__key")[3]).to have_text "Origin"
expect(all("dd.govuk-summary-list__value")[3]).to have_text "Unknown"
expect(all("dt.govuk-summary-list__key")[4]).to have_text "Source"
expect(all("dd.govuk-summary-list__value")[4]).to have_text "-"
end
end
end

context "when value and support levels have been populated" do
let(:support_case) { create(:support_case, :with_fixed_category, :opened, value: 123.32, support_level: "L2", source: :incoming_email) }
let(:support_case) { create(:support_case, :with_fixed_category, :opened, value: 123.32, support_level: "L2", source: :incoming_email, discovery_method: :newsletter) }

it "shows fields with details" do
within("div#case-details") do
Expand All @@ -34,8 +36,10 @@
expect(all("dd.govuk-summary-list__value")[1]).to have_text "2 - Specific advice"
expect(all("dt.govuk-summary-list__key")[2]).to have_text "Case value"
expect(all("dd.govuk-summary-list__value")[2]).to have_text "£123.32"
expect(all("dt.govuk-summary-list__key")[3]).to have_text "Source"
expect(all("dd.govuk-summary-list__value")[3]).to have_text "Email"
expect(all("dt.govuk-summary-list__key")[3]).to have_text "Origin"
expect(all("dd.govuk-summary-list__value")[3]).to have_text "Newsletter"
expect(all("dt.govuk-summary-list__key")[4]).to have_text "Source"
expect(all("dd.govuk-summary-list__value")[4]).to have_text "Email"
end
end
end
Expand Down
Loading

0 comments on commit 67795a0

Please sign in to comment.