Skip to content

Commit 4587253

Browse files
committed
Add feature report for forms getting a weekly CSV
Adds a count of forms that will be receiving a weekly CSV of completed forms to the feature reports.
1 parent 1e09f9d commit 4587253

9 files changed

Lines changed: 98 additions & 5 deletions

File tree

app/controllers/reports_controller.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ def forms_with_daily_submission_csv
9999
forms_feature_report(tag, params[:action], forms)
100100
end
101101

102+
def forms_with_weekly_submission_csv
103+
tag = params[:tag]
104+
forms = Reports::FormDocumentsService.form_documents(tag:)
105+
forms = Reports::FeatureReportService.new(forms).forms_with_weekly_submission_csv
106+
107+
forms_feature_report(tag, params[:action], forms)
108+
end
109+
102110
def forms_with_s3_submissions
103111
tag = params[:tag]
104112
forms = Reports::FormDocumentsService.form_documents(tag:)

app/services/reports/feature_report_service.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def report
1616
forms_with_csv_submission_email_attachments: 0,
1717
forms_with_json_submission_email_attachments: 0,
1818
forms_with_daily_submission_csv: 0,
19+
forms_with_weekly_submission_csv: 0,
1920
forms_with_s3_submissions: 0,
2021
forms_with_answer_type: HashWithIndifferentAccess.new,
2122
steps_with_answer_type: HashWithIndifferentAccess.new,
@@ -33,6 +34,7 @@ def report
3334
report[:forms_with_csv_submission_email_attachments] += 1 if Reports::FormDocumentsService.has_csv_submission_email_attachments(form)
3435
report[:forms_with_json_submission_email_attachments] += 1 if Reports::FormDocumentsService.has_json_submission_email_attachments(form)
3536
report[:forms_with_daily_submission_csv] += 1 if Reports::FormDocumentsService.has_daily_submission_csv(form)
37+
report[:forms_with_weekly_submission_csv] += 1 if Reports::FormDocumentsService.has_weekly_submission_csv(form)
3638
report[:forms_with_s3_submissions] += 1 if Reports::FormDocumentsService.has_s3_submissions(form)
3739
report[:forms_with_exit_pages] += 1 if Reports::FormDocumentsService.has_exit_pages?(form)
3840
report[:forms_with_welsh_translation] += 1 if Reports::FormDocumentsService.has_welsh_translation(form)
@@ -163,6 +165,11 @@ def forms_with_daily_submission_csv
163165
.select { |form| Reports::FormDocumentsService.has_daily_submission_csv(form) }
164166
end
165167

168+
def forms_with_weekly_submission_csv
169+
form_documents
170+
.select { |form| Reports::FormDocumentsService.has_weekly_submission_csv(form) }
171+
end
172+
166173
def forms_with_s3_submissions
167174
form_documents
168175
.select { |form| Reports::FormDocumentsService.has_s3_submissions(form) }

app/services/reports/form_documents_service.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ def has_daily_submission_csv(form_document)
5252
form_document["content"]["send_daily_submission_batch"]
5353
end
5454

55+
def has_weekly_submission_csv(form_document)
56+
form_document["content"]["send_weekly_submission_batch"]
57+
end
58+
5559
def has_s3_submissions(form_document)
5660
form_document["content"]["submission_type"] == "s3"
5761
end

app/views/reports/features.html.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
<%= row.with_key(text: t(".features.forms_with_daily_submission_csv", tag: tag_label(tag)).upcase_first) %>
4747
<%= row.with_value(text: govuk_link_to(data[:forms_with_daily_submission_csv], report_forms_with_daily_submission_csv_path, no_visited_state: true)) %>
4848
<% end %>
49+
<%= summary_list.with_row do |row| %>
50+
<%= row.with_key(text: t(".features.forms_with_weekly_submission_csv", tag: tag_label(tag)).upcase_first) %>
51+
<%= row.with_value(text: govuk_link_to(data[:forms_with_weekly_submission_csv], report_forms_with_weekly_submission_csv_path, no_visited_state: true)) %>
52+
<% end %>
4953
<%= summary_list.with_row do |row| %>
5054
<%= row.with_key(text: t(".features.forms_with_s3_submissions", tag: tag_label(tag)).upcase_first) %>
5155
<%= row.with_value(text: govuk_link_to(data[:forms_with_s3_submissions], report_forms_with_s3_submissions_path, no_visited_state: true)) %>

config/locales/en.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,7 @@ en:
17221722
forms_with_payments: "%{tag} forms with payments"
17231723
forms_with_routes: "%{tag} forms with routes"
17241724
forms_with_s3_submissions: "%{tag} forms with S3 submissions"
1725+
forms_with_weekly_submission_csv: "%{tag} forms getting a weekly CSV of completed forms"
17251726
forms_with_welsh_translation: "%{tag} forms with Welsh translation"
17261727
heading: Feature usage
17271728
total_forms: Total %{tag} forms
@@ -1776,6 +1777,10 @@ en:
17761777
download_csv: Download data about all %{tag} forms with S3 submissions enabled (as a CSV)
17771778
empty: There are no %{tag} forms with S3 submissions enabled
17781779
heading: "%{tag} forms with S3 submissions enabled"
1780+
forms_with_daily_submission_csv:
1781+
download_csv: Download data about all %{tag} forms getting a weekly CSV of completed forms (as a CSV)
1782+
empty: There are no %{tag} forms getting a weekly CSV of completed forms
1783+
heading: "%{tag} forms getting a weekly CSV of completed forms"
17791784
forms_with_welsh_translation:
17801785
download_csv: Download data about all %{tag} forms with a Welsh translation (as a CSV)
17811786
empty: There are no %{tag} forms with a Welsh translation

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@
247247
get "forms-with-csv-submission-email-attachments", to: "reports#forms_with_csv_submission_email_attachments", as: :report_forms_with_csv_submission_email_attachments
248248
get "forms-with-json-submission-email-attachments", to: "reports#forms_with_json_submission_email_attachments", as: :report_forms_with_json_submission_email_attachments
249249
get "forms-with-daily-submission-csv", to: "reports#forms_with_daily_submission_csv", as: :report_forms_with_daily_submission_csv
250+
get "forms-with-weekly-submission-csv", to: "reports#forms_with_weekly_submission_csv", as: :report_forms_with_weekly_submission_csv
250251
get "forms-with-s3-submissions", to: "reports#forms_with_s3_submissions", as: :report_forms_with_s3_submissions
251252
get "forms-with-exit-pages", to: "reports#forms_with_exit_pages", as: :report_forms_with_exit_pages
252253
get "forms-with-welsh-translation", to: "reports#forms_with_welsh_translation", as: :report_forms_with_welsh_translation

spec/requests/reports_controller_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,31 @@
317317
end
318318
end
319319

320+
describe "#forms_with_weekly_submission_csv" do
321+
let(:path) { report_forms_with_weekly_submission_csv_path(tag: :live) }
322+
let(:form) { create(:form, :live, submission_type: "email", send_weekly_submission_batch: true) }
323+
let(:forms) { [form] }
324+
325+
include_examples "unauthorized user is forbidden"
326+
327+
context "when the user is a super admin" do
328+
before do
329+
login_as_super_admin_user
330+
331+
get path
332+
end
333+
334+
it "returns http code 200 with the expected report data" do
335+
expect(response).to have_http_status(:ok)
336+
expect(response).to render_template("reports/feature_report")
337+
338+
node = Capybara.string(response.body)
339+
expect(node).to have_xpath "//thead/tr/th[1]", text: "Form name"
340+
expect(node).to have_xpath "//tbody/tr[1]/td[1]", text: form.name
341+
end
342+
end
343+
end
344+
320345
describe "#forms_with_s3_submissions" do
321346
let(:path) { report_forms_with_s3_submissions_path(tag: :live) }
322347
let(:form) { create(:form, :live, submission_type: "s3", submission_format: %w[json]) }

spec/services/reports/feature_report_service_spec.rb

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,16 @@
3636
])
3737
end
3838
let(:form_with_a_few_answer_types) do
39-
create(:form, :live, submission_type: "email", submission_format: %w[csv json], send_daily_submission_batch: true,
40-
pages: [
41-
create(:page, answer_type: "email"),
42-
*create_list(:page, 3, answer_type: "name"),
43-
])
39+
create(:form,
40+
:live,
41+
submission_type: "email",
42+
submission_format: %w[csv json],
43+
send_daily_submission_batch: true,
44+
send_weekly_submission_batch: true,
45+
pages: [
46+
create(:page, answer_type: "email"),
47+
*create_list(:page, 3, answer_type: "name"),
48+
])
4449
end
4550
let(:branch_route_form) do
4651
form = create(:form, :live, :ready_for_routing, submission_type: "s3", submission_format: %w[csv])
@@ -85,6 +90,7 @@
8590
forms_with_csv_submission_email_attachments: 2,
8691
forms_with_json_submission_email_attachments: 1,
8792
forms_with_daily_submission_csv: 1,
93+
forms_with_weekly_submission_csv: 1,
8894
forms_with_s3_submissions: 1,
8995
forms_with_answer_type: {
9096
"address" => 1,
@@ -446,6 +452,21 @@
446452
end
447453
end
448454

455+
describe "#forms_with_weekly_submission_csv" do
456+
it "returns live forms with weekly submission csv enabled" do
457+
forms = described_class.new(form_documents).forms_with_weekly_submission_csv
458+
expect(forms.length).to eq 1
459+
expect(forms).to match [
460+
a_hash_including(
461+
"form_id" => form_with_a_few_answer_types.id,
462+
"content" => a_hash_including(
463+
"name" => form_with_a_few_answer_types.name,
464+
),
465+
),
466+
]
467+
end
468+
end
469+
449470
describe "#forms_with_s3_submissions" do
450471
it "returns live forms with json enabled" do
451472
forms = described_class.new(form_documents).forms_with_s3_submissions

spec/services/reports/form_documents_service_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,24 @@
259259
end
260260
end
261261

262+
describe ".has_weekly_submission_csv" do
263+
context "when the form has send_weekly_submission_batch enabled" do
264+
let(:form_document) { create(:form, :live, send_weekly_submission_batch: true).live_form_document }
265+
266+
it "returns true" do
267+
expect(described_class.has_weekly_submission_csv(form_document)).to be true
268+
end
269+
end
270+
271+
context "when the form has send_weekly_submission_batch disabled" do
272+
let(:form_document) { create(:form, :live, send_weekly_submission_batch: false).live_form_document }
273+
274+
it "returns false" do
275+
expect(described_class.has_weekly_submission_csv(form_document)).to be false
276+
end
277+
end
278+
end
279+
262280
describe ".has_welsh_translation" do
263281
subject(:has_welsh_translation) do
264282
described_class.has_welsh_translation(form_document)

0 commit comments

Comments
 (0)