Skip to content
This repository was archived by the owner on Nov 10, 2025. It is now read-only.

Commit fada3ae

Browse files
authored
Merge pull request #726 from alphagov/remove-features-report-endpoint
Remove feature usage report endpoint
2 parents 27aa74b + 4cd5ea4 commit fada3ae

File tree

7 files changed

+67
-380
lines changed

7 files changed

+67
-380
lines changed

app/controllers/api/v1/reports_controller.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
class Api::V1::ReportsController < ApplicationController
2-
def features
3-
feature_stats = Reports::FeatureUsageService.new.report
4-
5-
render json: feature_stats.to_json, status: :ok
6-
end
7-
82
def add_another_answer_forms
9-
data = Reports::FeatureUsageService.new.add_another_answer_forms
3+
data = Reports::AddAnotherAnswerUsageService.new.add_another_answer_forms
104

115
render json: data.to_json, status: :ok
126
end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Reports::AddAnotherAnswerUsageService
2+
def add_another_answer_forms
3+
forms = Form.includes(:pages)
4+
.where(pages: { is_repeatable: true })
5+
.map(&method(:form_data))
6+
7+
# adding the count even though forms-admin doesn't use it as ActiveResource doesn't like parsing JSON with a single root key
8+
{ forms:, count: forms.length }
9+
end
10+
11+
private
12+
13+
def form_data(form)
14+
{
15+
form_id: form.id,
16+
name: form.name,
17+
state: form.state,
18+
repeatable_pages: form.pages.map { |page| { page_id: page.id, question_text: page.question_text } if page.is_repeatable },
19+
}
20+
end
21+
end

app/services/reports/feature_usage_service.rb

Lines changed: 0 additions & 69 deletions
This file was deleted.

config/routes.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
end
4848

4949
scope :reports do
50-
get "/features", to: "api/v1/reports#features"
5150
get "/add-another-answer-forms", to: "api/v1/reports#add_another_answer_forms"
5251
get "/selection-questions-summary", to: "api/v1/reports#selection_questions_summary"
5352
get "/selection-questions-with-autocomplete", to: "api/v1/reports#selection_questions_with_autocomplete"

spec/requests/api/v1/reports_controller_spec.rb

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,6 @@
11
require "rails_helper"
22

33
RSpec.describe Api::V1::ReportsController, type: :request do
4-
describe "GET /features" do
5-
let!(:form_with_repeatable_question) { create(:form, state: :live, pages: [repeatable_page]) }
6-
let(:repeatable_page) { build(:page, answer_type: "text", is_repeatable: true) }
7-
8-
before do
9-
create :form, state: :live, payment_url: Faker::Internet.url(host: "gov.uk"), submission_type: "email_with_csv", pages: [
10-
(build :page, answer_type: "text"),
11-
(build :page, answer_type: "text"),
12-
]
13-
14-
create :form, state: :live, pages: [
15-
(build :page, answer_type: "name"),
16-
(build :page, answer_type: "organisation_name"),
17-
(build :page, answer_type: "phone_number"),
18-
(build :page, answer_type: "email"),
19-
(build :page, answer_type: "address"),
20-
(build :page, answer_type: "national_insurance_number"),
21-
(build :page, answer_type: "date"),
22-
(build :page, answer_type: "number"),
23-
(build :page, answer_type: "selection", routing_conditions: [(build :condition)]),
24-
(build :page, answer_type: "text"),
25-
]
26-
27-
get "/api/v1/reports/features"
28-
end
29-
30-
it "returns the breakdown of form features used" do
31-
response_hash = JSON.parse(response.body, symbolize_names: true)
32-
33-
expect(response_hash).to eq({
34-
total_live_forms: 3,
35-
live_forms_with_answer_type: {
36-
name: 1,
37-
organisation_name: 1,
38-
phone_number: 1,
39-
email: 1,
40-
address: 1,
41-
national_insurance_number: 1,
42-
date: 1,
43-
number: 1,
44-
selection: 1,
45-
text: 3,
46-
},
47-
live_pages_with_answer_type: {
48-
name: 1,
49-
organisation_name: 1,
50-
phone_number: 1,
51-
email: 1,
52-
address: 1,
53-
national_insurance_number: 1,
54-
date: 1,
55-
number: 1,
56-
selection: 1,
57-
text: 4,
58-
},
59-
live_forms_with_payment: 1,
60-
live_forms_with_routing: 1,
61-
live_forms_with_add_another_answer: 1,
62-
live_forms_with_csv_submission_enabled: 1,
63-
all_forms_with_add_another_answer: [{ form_id: form_with_repeatable_question.id, name: form_with_repeatable_question.name, state: form_with_repeatable_question.state, repeatable_pages: [{ page_id: repeatable_page.id, question_text: repeatable_page.question_text }] }],
64-
})
65-
end
66-
67-
it "returns http success" do
68-
expect(response).to have_http_status(:success)
69-
end
70-
end
71-
724
describe "GET /add-another-answer-forms" do
735
let!(:form_with_repeatable_question) { create(:form, state: :live, pages: [repeatable_page]) }
746
let(:repeatable_page) { build(:page, answer_type: "text", is_repeatable: true) }
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
require "rails_helper"
2+
3+
describe Reports::AddAnotherAnswerUsageService do
4+
subject(:features_report_service) { described_class.new }
5+
6+
describe "#add_another_answer_forms" do
7+
let!(:add_another_answer_draft_form) { create(:form, state: "draft", pages: draft_form_pages) }
8+
let(:draft_form_pages) do
9+
[
10+
(build :page, answer_type: "name", is_repeatable: true),
11+
]
12+
end
13+
let!(:add_another_answer_live_form) { create(:form, state: "live", pages: live_form_pages) }
14+
let(:live_form_pages) do
15+
[
16+
(build :page, answer_type: "name", is_repeatable: true),
17+
(build :page, answer_type: "text", is_repeatable: true),
18+
]
19+
end
20+
21+
it "obtains all forms in the add another answer report" do
22+
report = features_report_service.add_another_answer_forms
23+
24+
expect(report[:forms]).to contain_exactly({
25+
form_id: add_another_answer_draft_form.id,
26+
name: add_another_answer_draft_form.name,
27+
state: add_another_answer_draft_form.state,
28+
repeatable_pages: contain_exactly({ page_id: draft_form_pages.first.id, question_text: draft_form_pages.first.question_text }),
29+
}, {
30+
form_id: add_another_answer_live_form.id,
31+
name: add_another_answer_live_form.name,
32+
state: add_another_answer_live_form.state,
33+
repeatable_pages: contain_exactly(
34+
{ page_id: live_form_pages.first.id, question_text: live_form_pages.first.question_text },
35+
{ page_id: live_form_pages.second.id, question_text: live_form_pages.second.question_text },
36+
),
37+
})
38+
end
39+
40+
it "returns the count" do
41+
report = features_report_service.add_another_answer_forms
42+
expect(report[:count]).to eq 2
43+
end
44+
end
45+
end

0 commit comments

Comments
 (0)