Skip to content
This repository was archived by the owner on Nov 10, 2025. It is now read-only.
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
6 changes: 6 additions & 0 deletions app/controllers/api/v1/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ def features
render json: feature_stats.to_json, status: :ok
end

def add_another_answer_forms
data = Reports::FeatureUsageService.new.add_another_answer_forms

render json: data.to_json, status: :ok
end

def selection_questions_summary
statistics = Reports::SelectionQuestionService.new.live_form_statistics

Expand Down
7 changes: 7 additions & 0 deletions app/services/reports/feature_usage_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ def report
}
end

def add_another_answer_forms
forms = all_forms_with_add_another_answer

# adding the count even though forms-admin doesn't use it as ActiveResource doesn't like parsing JSON with a single root key
{ forms:, count: forms.length }
end

private

# NOTE: all of these methods currently query the Form table rather than the MadeLiveForm table.
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

scope :reports do
get "/features", to: "api/v1/reports#features"
get "/add-another-answer-forms", to: "api/v1/reports#add_another_answer_forms"
get "/selection-questions-summary", to: "api/v1/reports#selection_questions_summary"
get "/selection-questions-with-autocomplete", to: "api/v1/reports#selection_questions_with_autocomplete"
get "/selection-questions-with-radios", to: "api/v1/reports#selection_questions_with_radios"
Expand Down
36 changes: 36 additions & 0 deletions spec/requests/api/v1/reports_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,42 @@
end
end

describe "GET /add-another-answer-forms" do
let!(:form_with_repeatable_question) { create(:form, state: :live, pages: [repeatable_page]) }
let(:repeatable_page) { build(:page, answer_type: "text", is_repeatable: true) }

before do
create :form, state: :live, pages: [
(build :page, answer_type: "text"),
(build :page, answer_type: "text"),
]

get "/api/v1/reports/add-another-answer-forms"
end

it "returns the forms with repeatable questions" do
response_hash = JSON.parse(response.body, symbolize_names: true)

expect(response_hash).to eq({
count: 1,
forms: [
{
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 },
],
},
],
})
end

it "returns http success" do
expect(response).to have_http_status(:success)
end
end

describe "GET /selection-questions-summary" do
before do
form_1_pages = [
Expand Down
36 changes: 36 additions & 0 deletions spec/services/reports/feature_usage_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,40 @@
end
end
end

describe "#add_another_answer_forms" do
let!(:add_another_answer_draft_form) { create(:form, state: "draft", pages: draft_form_pages) }
let(:draft_form_pages) { pages_with_add_another_answer }
let!(:add_another_answer_live_form) { create(:form, state: "live", pages: live_form_pages) }
let(:live_form_pages) do
[
(build :page, answer_type: "name", is_repeatable: true),
(build :page, answer_type: "text", is_repeatable: true),
]
end

it "obtains all forms in the add another answer report" do
report = features_report_service.add_another_answer_forms

expect(report[:forms]).to contain_exactly({
form_id: add_another_answer_draft_form.id,
name: add_another_answer_draft_form.name,
state: add_another_answer_draft_form.state,
repeatable_pages: contain_exactly({ page_id: draft_form_pages.first.id, question_text: draft_form_pages.first.question_text }),
}, {
form_id: add_another_answer_live_form.id,
name: add_another_answer_live_form.name,
state: add_another_answer_live_form.state,
repeatable_pages: contain_exactly(
{ page_id: live_form_pages.first.id, question_text: live_form_pages.first.question_text },
{ page_id: live_form_pages.second.id, question_text: live_form_pages.second.question_text },
),
})
end

it "returns the count" do
report = features_report_service.add_another_answer_forms
expect(report[:count]).to eq 2
end
end
end