Skip to content

Commit 84f0f8f

Browse files
committed
Add whether a question has branch routes to the questions CSV report
1 parent fad323b commit 84f0f8f

4 files changed

Lines changed: 73 additions & 0 deletions

File tree

app/services/reports/form_documents_service.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ def count_secondary_skip_routes(form_document)
3434
secondary_skip_conditions(form_document).count
3535
end
3636

37+
def step_has_secondary_skip_route?(form_document, step)
38+
secondary_skip_conditions(form_document).any? do |condition|
39+
condition["check_page_id"] == step["id"]
40+
end
41+
end
42+
3743
def has_payments?(form_document)
3844
form_document["content"]["payment_url"].present?
3945
end

app/services/reports/questions_csv_report_service.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Reports::QuestionsCsvReportService
1919
"Is optional?",
2020
IS_REPEATABLE,
2121
"Has routes?",
22+
"Has branch routes?",
2223
"Answer settings - Input type",
2324
"Selection settings - Only one option?",
2425
"Selection settings - Number of options",
@@ -68,6 +69,7 @@ def question_row(step)
6869
step["data"]["is_optional"],
6970
step["data"]["is_repeatable"],
7071
step["routing_conditions"].present?,
72+
Reports::FormDocumentsService.step_has_secondary_skip_route?(form, step),
7173
step.dig("data", "answer_settings", "input_type"),
7274
step.dig("data", "answer_settings", "only_one_option").presence.try { |o| o.to_s == "true" },
7375
step.dig("data", "answer_settings", "selection_options")&.length,

spec/services/reports/form_documents_service_spec.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,35 @@ def response_headers(total, offset, limit)
162162
it { is_expected.to eq 0 }
163163
end
164164
end
165+
166+
describe ".step_has_secondary_skip_route?" do
167+
let(:form_documents) { JSON.load_file file_fixture("form_documents_response.json") }
168+
169+
context "when step is check page for secondary skip condition" do
170+
let(:form_document) { branch_route_form }
171+
let(:step) { form_document["content"]["steps"][0] }
172+
173+
it "returns true" do
174+
expect(described_class.step_has_secondary_skip_route?(form_document, step)).to be true
175+
end
176+
end
177+
178+
context "when step is not check page for secondary skip condition" do
179+
let(:form_document) { branch_route_form }
180+
let(:step) { form_document["content"]["steps"][3] }
181+
182+
it "returns false" do
183+
expect(described_class.step_has_secondary_skip_route?(form_document, step)).to be false
184+
end
185+
end
186+
187+
context "when form has no secondary skip conditions" do
188+
let(:form_document) { skip_route_form }
189+
let(:step) { form_document["content"]["steps"][0] }
190+
191+
it "returns false" do
192+
expect(described_class.step_has_secondary_skip_route?(form_document, step)).to be false
193+
end
194+
end
195+
end
165196
end

spec/services/reports/questions_csv_report_service_spec.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"false",
4646
"true",
4747
"false",
48+
"false",
4849
"single_line",
4950
nil,
5051
nil,
@@ -74,6 +75,7 @@
7475
"true",
7576
"false",
7677
"false",
78+
"false",
7779
nil,
7880
"false",
7981
"3",
@@ -103,6 +105,7 @@
103105
"false",
104106
"false",
105107
"false",
108+
"false",
106109
"full_name",
107110
nil,
108111
nil,
@@ -112,6 +115,36 @@
112115
end
113116

114117
it "has expected values for question with routing conditions" do
118+
csv = csv_reports_service.csv
119+
rows = CSV.parse(csv)
120+
routing_question_row = rows.detect { |row| row.include? "Would you like to submit anonymously?" }
121+
expect(routing_question_row).to eq([
122+
"4",
123+
"live",
124+
"Skip route form",
125+
group.organisation.name,
126+
group.organisation.id.to_s,
127+
group.name,
128+
group.external_id,
129+
"1",
130+
"Would you like to submit anonymously?",
131+
"selection",
132+
nil,
133+
nil,
134+
nil,
135+
"false",
136+
"false",
137+
"true",
138+
"false",
139+
nil,
140+
"true",
141+
"2",
142+
nil,
143+
"{\"only_one_option\" => \"true\", \"selection_options\" => [{\"name\" => \"Yes\"}, {\"name\" => \"No\"}]}",
144+
])
145+
end
146+
147+
it "has expected values for question with branch routing conditions" do
115148
csv = csv_reports_service.csv
116149
rows = CSV.parse(csv)
117150
routing_question_row = rows.detect { |row| row.include? "How many times have you filled out this form?" }
@@ -132,6 +165,7 @@
132165
"false",
133166
"false",
134167
"true",
168+
"true",
135169
nil,
136170
"true",
137171
"2",

0 commit comments

Comments
 (0)