Skip to content
Closed
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
2 changes: 2 additions & 0 deletions app/helpers/report_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def report_forms_with_routes_table_head
[
*report_forms_table_head,
I18n.t("reports.form_or_questions_list_table.headings.number_of_routes"),
I18n.t("reports.form_or_questions_list_table.headings.number_of_branch_routes"),
]
end

Expand Down Expand Up @@ -80,6 +81,7 @@ def report_forms_with_routes_table_row(form)
[
*report_forms_table_row(form),
form["metadata"]["number_of_routes"].to_s,
form["metadata"]["number_of_branch_routes"].to_s,
]
end

Expand Down
9 changes: 9 additions & 0 deletions app/services/reports/feature_report_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def report(name = nil)
total_forms: 0,
forms_with_payment: 0,
forms_with_routing: 0,
forms_with_branch_routing: 0,
forms_with_add_another_answer: 0,
forms_with_csv_submission_enabled: 0,
forms_with_answer_type: HashWithIndifferentAccess.new,
Expand All @@ -46,6 +47,7 @@ def report(name = nil)
report[:total_forms] += 1
report[:forms_with_payment] += 1 if Reports::FormDocumentsService.has_payments?(form)
report[:forms_with_routing] += 1 if Reports::FormDocumentsService.has_routes?(form)
report[:forms_with_branch_routing] += 1 if Reports::FormDocumentsService.has_secondary_skip_routes?(form)
report[:forms_with_add_another_answer] += 1 if form["content"]["steps"].any? { |step| step["data"]["is_repeatable"] }
report[:forms_with_csv_submission_enabled] += 1 if Reports::FormDocumentsService.has_csv_submission_enabled?(form)

Expand Down Expand Up @@ -94,6 +96,12 @@ def questions_with_answer_type(answer_type)
.map { |form| form_with_routes_details(form) }
end

define_report :forms_with_branch_routes do
form_documents
.select { |form| Reports::FormDocumentsService.has_secondary_skip_routes?(form) }
.map { |form| form_with_routes_details(form) }
end

define_report :forms_with_payments do
form_documents
.select { |form| Reports::FormDocumentsService.has_payments?(form) }
Expand All @@ -117,6 +125,7 @@ def form_with_routes_details(form)
form = form_details(form)
form["metadata"] = {
"number_of_routes" => form["content"]["steps"].count { |step| step["routing_conditions"].present? },
"number_of_branch_routes" => Reports::FormDocumentsService.count_secondary_skip_routes(form),
}
form
end
Expand Down
22 changes: 22 additions & 0 deletions app/services/reports/form_documents_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ def has_routes?(form_document)
form_document["content"]["steps"].any? { |step| step["routing_conditions"].present? }
end

def has_secondary_skip_routes?(form_document)
secondary_skip_conditions(form_document).any?
end

def count_secondary_skip_routes(form_document)
secondary_skip_conditions(form_document).count
end

def step_has_secondary_skip_route?(form_document, step)
secondary_skip_conditions(form_document).any? do |condition|
condition["check_page_id"] == step["id"]
end
end

def has_payments?(form_document)
form_document["content"]["payment_url"].present?
end
Expand Down Expand Up @@ -67,5 +81,13 @@ def is_in_internal_organisation?(form)

group_form.group.organisation.internal?
end

def secondary_skip_conditions(form_document)
form_document["content"]["steps"].lazy.flat_map do |step|
(step["routing_conditions"]&.lazy || []).reject do |condition|
condition["check_page_id"] == condition["routing_page_id"]
end
end
end
end
end
2 changes: 2 additions & 0 deletions app/services/reports/forms_csv_report_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Reports::FormsCsvReportService
"Updated at",
"Number of questions",
"Has routes",
"Has branch routes",
"Payment URL",
"Support URL",
"Support URL text",
Expand Down Expand Up @@ -58,6 +59,7 @@ def form_row(form)
form["content"]["updated_at"],
form["content"]["steps"].length,
form["content"]["steps"].any? { |step| step["routing_conditions"].present? },
Reports::FormDocumentsService.has_secondary_skip_routes?(form),
form["content"]["payment_url"],
form["content"]["support_url"],
form["content"]["support_url_text"],
Expand Down
2 changes: 2 additions & 0 deletions app/services/reports/questions_csv_report_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Reports::QuestionsCsvReportService
"Is optional?",
IS_REPEATABLE,
"Has routes?",
"Has branch routes?",
"Answer settings - Input type",
"Selection settings - Only one option?",
"Selection settings - Number of options",
Expand Down Expand Up @@ -68,6 +69,7 @@ def question_row(step)
step["data"]["is_optional"],
step["data"]["is_repeatable"],
step["routing_conditions"].present?,
Reports::FormDocumentsService.step_has_secondary_skip_route?(form, step),
step.dig("data", "answer_settings", "input_type"),
step.dig("data", "answer_settings", "only_one_option").presence.try { |o| o.to_s == "true" },
step.dig("data", "answer_settings", "selection_options")&.length,
Expand Down
4 changes: 4 additions & 0 deletions app/views/reports/features.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
<%= row.with_key(text: t(".features.live_forms_with_routes")) %>
<%= row.with_value(text: govuk_link_to(data[:forms_with_routing], feature_report_path(report: "forms-with-routes"), no_visited_state: true)) %>
<% end %>
<%= summary_list.with_row do |row| %>
<%= row.with_key(text: t(".features.live_forms_with_branch_routes")) %>
<%= row.with_value(text: govuk_link_to(data[:forms_with_branch_routing], feature_report_path(report: "forms-with-branch-routes"), no_visited_state: true)) %>
<% end %>
<%= summary_list.with_row do |row| %>
<%= row.with_key(text: t(".features.live_forms_with_payments")) %>
<%= row.with_value(text: govuk_link_to(data[:forms_with_payment], feature_report_path(report: "forms-with-payments"), no_visited_state: true)) %>
Expand Down
5 changes: 5 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1382,6 +1382,7 @@ en:
features:
heading: Feature usage
live_forms_with_add_another_answer: Live forms with add another answer
live_forms_with_branch_routes: Live forms with branch routes
live_forms_with_csv_submission_enabled: Live forms with CSV submission enabled
live_forms_with_payments: Live forms with payments
live_forms_with_routes: Live forms with routes
Expand All @@ -1392,9 +1393,13 @@ en:
form_or_questions_list_table:
headings:
form_name: Form name
number_of_branch_routes: Number of branch routes
number_of_routes: Number of routes
organisation: Organisation
question_text: Question text
forms_with_branch_routes:
download_csv: Download data about all live forms with branch routes as a CSV file
heading: Live forms with branch routes
forms_with_csv_submission_enabled:
download_csv: Download data about all live forms with CSV submission enabled as a CSV file
heading: Live forms with CSV submission enabled
Expand Down
12 changes: 10 additions & 2 deletions spec/helpers/report_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

let(:forms_with_routes) do
[
{ "form_id" => 3, "content" => { "name" => "Branch route form" }, "group" => { "organisation" => { "name" => "Ministry of Tests" } }, "metadata" => { "number_of_routes" => 2 } },
{ "form_id" => 4, "content" => { "name" => "Skip route form" }, "group" => { "organisation" => { "name" => "Department for Testing" } }, "metadata" => { "number_of_routes" => 1 } },
{ "form_id" => 3, "content" => { "name" => "Branch route form" }, "group" => { "organisation" => { "name" => "Ministry of Tests" } }, "metadata" => { "number_of_routes" => 2, "number_of_branch_routes" => 1 } },
{ "form_id" => 4, "content" => { "name" => "Skip route form" }, "group" => { "organisation" => { "name" => "Department for Testing" } }, "metadata" => { "number_of_routes" => 1, "number_of_branch_routes" => 0 } },
]
end

Expand Down Expand Up @@ -158,6 +158,7 @@
"Form name",
"Organisation",
"Number of routes",
"Number of branch routes",
]
end
end
Expand Down Expand Up @@ -203,6 +204,13 @@
]
end

it "includes the number of branch routes in the form" do
expect(helper.report_forms_with_routes_table_rows(forms).map(&:fourth)).to eq %w[
1
0
]
end

context "when form is not in a group" do
let(:forms) do
[
Expand Down
60 changes: 60 additions & 0 deletions spec/services/reports/feature_report_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
total_forms: 4,
forms_with_payment: 1,
forms_with_routing: 2,
forms_with_branch_routing: 1,
forms_with_add_another_answer: 1,
forms_with_csv_submission_enabled: 1,
forms_with_answer_type: {
Expand Down Expand Up @@ -277,6 +278,7 @@
),
"metadata" => {
"number_of_routes" => 2,
"number_of_branch_routes" => 1,
},
),
a_hash_including(
Expand All @@ -291,6 +293,7 @@
),
"metadata" => {
"number_of_routes" => 1,
"number_of_branch_routes" => 0,
},
),
]
Expand Down Expand Up @@ -319,6 +322,7 @@
expect(forms).to all include(
"metadata" => a_hash_including(
"number_of_routes" => an_instance_of(Integer),
"number_of_branch_routes" => an_instance_of(Integer),
),
)
end
Expand All @@ -335,6 +339,62 @@
end
end

describe "#forms_with_branch_routes" do
it "returns details needed to render report" do
forms = described_class.new(form_documents).forms_with_branch_routes
expect(forms).to match [
a_hash_including(
"form_id" => 3,
"content" => a_hash_including(
"name" => "Branch route form",
),
"group" => a_hash_including(
"organisation" => a_hash_including(
"name" => group.organisation.name,
),
),
"metadata" => {
"number_of_routes" => 2,
"number_of_branch_routes" => 1,
},
),
]
end

it "returns forms with branch routes" do
forms = described_class.new(form_documents).forms_with_branch_routes
expect(forms).to match [
a_hash_including(
"form_id" => 3,
"content" => a_hash_including(
"name" => "Branch route form",
),
),
]
end

it "includes counts of routes" do
forms = described_class.new(form_documents).forms_with_branch_routes
expect(forms).to all include(
"metadata" => a_hash_including(
"number_of_routes" => an_instance_of(Integer),
"number_of_branch_routes" => an_instance_of(Integer),
),
)
end

it "includes a reference to the organisation record" do
forms = described_class.new(form_documents).forms_with_branch_routes
expect(forms).to all include(
"group" => a_hash_including(
"organisation" => a_hash_including(
"name",
),
),
)
end
end

describe "#forms_with_payments" do
it "returns live forms with payments" do
forms = described_class.new(form_documents).forms_with_payments
Expand Down
Loading