Skip to content
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
8 changes: 8 additions & 0 deletions app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ def forms_with_daily_submission_csv
forms_feature_report(tag, params[:action], forms)
end

def forms_with_weekly_submission_csv
tag = params[:tag]
forms = Reports::FormDocumentsService.form_documents(tag:)
forms = Reports::FeatureReportService.new(forms).forms_with_weekly_submission_csv

forms_feature_report(tag, params[:action], forms)
end

def forms_with_s3_submissions
tag = params[:tag]
forms = Reports::FormDocumentsService.form_documents(tag:)
Expand Down
7 changes: 7 additions & 0 deletions app/services/reports/feature_report_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def report
forms_with_csv_submission_email_attachments: 0,
forms_with_json_submission_email_attachments: 0,
forms_with_daily_submission_csv: 0,
forms_with_weekly_submission_csv: 0,
forms_with_s3_submissions: 0,
forms_with_answer_type: HashWithIndifferentAccess.new,
steps_with_answer_type: HashWithIndifferentAccess.new,
Expand All @@ -33,6 +34,7 @@ def report
report[:forms_with_csv_submission_email_attachments] += 1 if Reports::FormDocumentsService.has_csv_submission_email_attachments(form)
report[:forms_with_json_submission_email_attachments] += 1 if Reports::FormDocumentsService.has_json_submission_email_attachments(form)
report[:forms_with_daily_submission_csv] += 1 if Reports::FormDocumentsService.has_daily_submission_csv(form)
report[:forms_with_weekly_submission_csv] += 1 if Reports::FormDocumentsService.has_weekly_submission_csv(form)
report[:forms_with_s3_submissions] += 1 if Reports::FormDocumentsService.has_s3_submissions(form)
report[:forms_with_exit_pages] += 1 if Reports::FormDocumentsService.has_exit_pages?(form)
report[:forms_with_welsh_translation] += 1 if Reports::FormDocumentsService.has_welsh_translation(form)
Expand Down Expand Up @@ -163,6 +165,11 @@ def forms_with_daily_submission_csv
.select { |form| Reports::FormDocumentsService.has_daily_submission_csv(form) }
end

def forms_with_weekly_submission_csv
form_documents
.select { |form| Reports::FormDocumentsService.has_weekly_submission_csv(form) }
end

def forms_with_s3_submissions
form_documents
.select { |form| Reports::FormDocumentsService.has_s3_submissions(form) }
Expand Down
4 changes: 4 additions & 0 deletions app/services/reports/form_documents_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ def has_daily_submission_csv(form_document)
form_document["content"]["send_daily_submission_batch"]
end

def has_weekly_submission_csv(form_document)
form_document["content"]["send_weekly_submission_batch"]
end

def has_s3_submissions(form_document)
form_document["content"]["submission_type"] == "s3"
end
Expand Down
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 @@ -28,6 +28,7 @@ class Reports::FormsCsvReportService
"Submission type",
"Submission formats",
"Daily submissions CSV enabled",
"Weekly submissions CSV enabled",
].freeze

attr_reader :form_documents
Expand Down Expand Up @@ -77,6 +78,7 @@ def form_row(form)
form["content"]["submission_type"],
form["content"]["submission_format"]&.sort&.join(" "),
form["content"]["send_daily_submission_batch"],
form["content"]["send_weekly_submission_batch"],
]
end
end
4 changes: 4 additions & 0 deletions app/views/reports/features.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
<%= row.with_key(text: t(".features.forms_with_daily_submission_csv", tag: tag_label(tag)).upcase_first) %>
<%= row.with_value(text: govuk_link_to(data[:forms_with_daily_submission_csv], report_forms_with_daily_submission_csv_path, no_visited_state: true)) %>
<% end %>
<%= summary_list.with_row do |row| %>
<%= row.with_key(text: t(".features.forms_with_weekly_submission_csv", tag: tag_label(tag)).upcase_first) %>
<%= row.with_value(text: govuk_link_to(data[:forms_with_weekly_submission_csv], report_forms_with_weekly_submission_csv_path, no_visited_state: true)) %>
<% end %>
<%= summary_list.with_row do |row| %>
<%= row.with_key(text: t(".features.forms_with_s3_submissions", tag: tag_label(tag)).upcase_first) %>
<%= row.with_value(text: govuk_link_to(data[:forms_with_s3_submissions], report_forms_with_s3_submissions_path, 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 @@ -1757,6 +1757,7 @@ en:
forms_with_payments: "%{tag} forms with payments"
forms_with_routes: "%{tag} forms with routes"
forms_with_s3_submissions: "%{tag} forms with S3 submissions"
forms_with_weekly_submission_csv: "%{tag} forms getting a weekly CSV of completed forms"
forms_with_welsh_translation: "%{tag} forms with Welsh translation"
heading: Feature usage
total_forms: Total %{tag} forms
Expand Down Expand Up @@ -1811,6 +1812,10 @@ en:
download_csv: Download data about all %{tag} forms with S3 submissions enabled (as a CSV)
empty: There are no %{tag} forms with S3 submissions enabled
heading: "%{tag} forms with S3 submissions enabled"
forms_with_weekly_submission_csv:
download_csv: Download data about all %{tag} forms getting a weekly CSV of completed forms (as a CSV)
empty: There are no %{tag} forms getting a weekly CSV of completed forms
heading: "%{tag} forms getting a weekly CSV of completed forms"
forms_with_welsh_translation:
download_csv: Download data about all %{tag} forms with a Welsh translation (as a CSV)
empty: There are no %{tag} forms with a Welsh translation
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@
get "forms-with-csv-submission-email-attachments", to: "reports#forms_with_csv_submission_email_attachments", as: :report_forms_with_csv_submission_email_attachments
get "forms-with-json-submission-email-attachments", to: "reports#forms_with_json_submission_email_attachments", as: :report_forms_with_json_submission_email_attachments
get "forms-with-daily-submission-csv", to: "reports#forms_with_daily_submission_csv", as: :report_forms_with_daily_submission_csv
get "forms-with-weekly-submission-csv", to: "reports#forms_with_weekly_submission_csv", as: :report_forms_with_weekly_submission_csv
get "forms-with-s3-submissions", to: "reports#forms_with_s3_submissions", as: :report_forms_with_s3_submissions
get "forms-with-exit-pages", to: "reports#forms_with_exit_pages", as: :report_forms_with_exit_pages
get "forms-with-welsh-translation", to: "reports#forms_with_welsh_translation", as: :report_forms_with_welsh_translation
Expand Down
25 changes: 25 additions & 0 deletions spec/requests/reports_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,31 @@
end
end

describe "#forms_with_weekly_submission_csv" do
let(:path) { report_forms_with_weekly_submission_csv_path(tag: :live) }
let(:form) { create(:form, :live, submission_type: "email", send_weekly_submission_batch: true) }
let(:forms) { [form] }

include_examples "unauthorized user is forbidden"

context "when the user is a super admin" do
before do
login_as_super_admin_user

get path
end

it "returns http code 200 with the expected report data" do
expect(response).to have_http_status(:ok)
expect(response).to render_template("reports/feature_report")

node = Capybara.string(response.body)
expect(node).to have_xpath "//thead/tr/th[1]", text: "Form name"
expect(node).to have_xpath "//tbody/tr[1]/td[1]", text: form.name
end
end
end

describe "#forms_with_s3_submissions" do
let(:path) { report_forms_with_s3_submissions_path(tag: :live) }
let(:form) { create(:form, :live, submission_type: "s3", submission_format: %w[json]) }
Expand Down
31 changes: 26 additions & 5 deletions spec/services/reports/feature_report_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,16 @@
])
end
let(:form_with_a_few_answer_types) do
create(:form, :live, submission_type: "email", submission_format: %w[csv json], send_daily_submission_batch: true,
pages: [
create(:page, answer_type: "email"),
*create_list(:page, 3, answer_type: "name"),
])
create(:form,
:live,
submission_type: "email",
submission_format: %w[csv json],
send_daily_submission_batch: true,
send_weekly_submission_batch: true,
pages: [
create(:page, answer_type: "email"),
*create_list(:page, 3, answer_type: "name"),
])
end
let(:branch_route_form) do
form = create(:form, :live, :ready_for_routing, submission_type: "s3", submission_format: %w[csv])
Expand Down Expand Up @@ -85,6 +90,7 @@
forms_with_csv_submission_email_attachments: 2,
forms_with_json_submission_email_attachments: 1,
forms_with_daily_submission_csv: 1,
forms_with_weekly_submission_csv: 1,
forms_with_s3_submissions: 1,
forms_with_answer_type: {
"address" => 1,
Expand Down Expand Up @@ -446,6 +452,21 @@
end
end

describe "#forms_with_weekly_submission_csv" do
it "returns live forms with weekly submission csv enabled" do
forms = described_class.new(form_documents).forms_with_weekly_submission_csv
expect(forms.length).to eq 1
expect(forms).to match [
a_hash_including(
"form_id" => form_with_a_few_answer_types.id,
"content" => a_hash_including(
"name" => form_with_a_few_answer_types.name,
),
),
]
end
end

describe "#forms_with_s3_submissions" do
it "returns live forms with json enabled" do
forms = described_class.new(form_documents).forms_with_s3_submissions
Expand Down
18 changes: 18 additions & 0 deletions spec/services/reports/form_documents_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,24 @@
end
end

describe ".has_weekly_submission_csv" do
context "when the form has send_weekly_submission_batch enabled" do
let(:form_document) { create(:form, :live, send_weekly_submission_batch: true).live_form_document }

it "returns true" do
expect(described_class.has_weekly_submission_csv(form_document)).to be true
end
end

context "when the form has send_weekly_submission_batch disabled" do
let(:form_document) { create(:form, :live, send_weekly_submission_batch: false).live_form_document }

it "returns false" do
expect(described_class.has_weekly_submission_csv(form_document)).to be false
end
end
end

describe ".has_welsh_translation" do
subject(:has_welsh_translation) do
described_class.has_welsh_translation(form_document)
Expand Down
4 changes: 3 additions & 1 deletion spec/services/reports/forms_csv_report_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
end
let(:form) do
create(:form, :live, :with_support, submission_type: "email", submission_format: %w[csv json],
payment_url: "https://www.gov.uk/payments/organisation/service", send_daily_submission_batch: true, pages: [
payment_url: "https://www.gov.uk/payments/organisation/service", send_daily_submission_batch: true,
send_weekly_submission_batch: true, pages: [
create(:page, :with_address_settings, is_repeatable: true),
create(:page, :with_date_settings),
create(:page, answer_type: "email"),
Expand Down Expand Up @@ -74,6 +75,7 @@
"email",
"csv json",
"true",
"true",
)
end
end
Expand Down
Loading