Skip to content

Commit fdbd38e

Browse files
committed
Fix organisation name when form is not in group
1 parent a726c5d commit fdbd38e

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

app/helpers/report_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def report_questions_table_rows(questions)
7272
def report_forms_table_row(form)
7373
[
7474
govuk_link_to(form["content"]["name"], live_form_pages_path(form_id: form["form_id"])),
75-
form["group"]["organisation"]["name"],
75+
form.dig("group", "organisation", "name") || "",
7676
]
7777
end
7878

spec/helpers/report_helpers_spec.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,20 @@
136136
"Department for Testing",
137137
]
138138
end
139+
140+
context "when form is not in a group" do
141+
let(:forms) do
142+
[
143+
{ "form_id" => 1, "content" => { "name" => "All question types form" }, "group" => nil },
144+
]
145+
end
146+
147+
it "returns the empty string for the organisation name" do
148+
expect(helper.report_forms_table_rows(forms).map(&:second)).to eq [
149+
"",
150+
]
151+
end
152+
end
139153
end
140154

141155
describe "#report_forms_with_routes_table_head" do
@@ -188,6 +202,20 @@
188202
1
189203
]
190204
end
205+
206+
context "when form is not in a group" do
207+
let(:forms) do
208+
[
209+
{ "form_id" => 1, "content" => { "name" => "All question types form" }, "group" => nil },
210+
]
211+
end
212+
213+
it "returns the empty string for the organisation name" do
214+
expect(helper.report_forms_table_rows(forms).map(&:second)).to eq [
215+
"",
216+
]
217+
end
218+
end
191219
end
192220

193221
describe "#report_questions_table_head" do
@@ -228,5 +256,19 @@
228256
"What’s your email address?",
229257
]
230258
end
259+
260+
context "when form is not in a group" do
261+
let(:questions) do
262+
[
263+
{ "type" => "question_page", "data" => { "question_text" => "Email address" }, "form" => { "form_id" => 1, "content" => { "name" => "All question types form" }, "group" => nil } },
264+
]
265+
end
266+
267+
it "returns the empty string for the organisation name" do
268+
expect(helper.report_questions_table_rows(questions).map(&:second)).to eq [
269+
"",
270+
]
271+
end
272+
end
231273
end
232274
end

0 commit comments

Comments
 (0)