From fc3b7758274f655a7bbd714a90fe5031fdd019c5 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Tue, 21 Dec 2021 16:36:53 +0000 Subject: [PATCH] Test for multiple forms --- spec/fixtures/forms/2022_2023.json | 25 +++++++++++++++++++ .../tasks/form_definition_validator_spec.rb | 2 +- spec/requests/form_controller_spec.rb | 12 +++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/forms/2022_2023.json diff --git a/spec/fixtures/forms/2022_2023.json b/spec/fixtures/forms/2022_2023.json new file mode 100644 index 000000000..bcf82242d --- /dev/null +++ b/spec/fixtures/forms/2022_2023.json @@ -0,0 +1,25 @@ +{ + "form_type": "lettings", + "sections": { + "household": { + "label": "About the household", + "subsections": { + "household_characteristics": { + "label": "Household characteristics", + "pages": { + "tenant_code": { + "questions": { + "tenant_code": { + "check_answer_label": "Tenant code", + "header": "Different question header text for this year - 2023", + "type": "text", + "width": 10 + } + } + } + } + } + } + } + } + } diff --git a/spec/lib/tasks/form_definition_validator_spec.rb b/spec/lib/tasks/form_definition_validator_spec.rb index 6cbfc5178..e08b69f58 100644 --- a/spec/lib/tasks/form_definition_validator_spec.rb +++ b/spec/lib/tasks/form_definition_validator_spec.rb @@ -11,7 +11,7 @@ describe "rake form_definition:validate_all", type: :task do end it "runs the validate task for each form definition in the project" do - expect(Rake::Task["form_definition:validate"]).to receive(:invoke).exactly(3).times + expect(Rake::Task["form_definition:validate"]).to receive(:invoke).exactly(4).times task.invoke end end diff --git a/spec/requests/form_controller_spec.rb b/spec/requests/form_controller_spec.rb index 872b798e3..2435209ac 100644 --- a/spec/requests/form_controller_spec.rb +++ b/spec/requests/form_controller_spec.rb @@ -48,6 +48,18 @@ RSpec.describe FormController, type: :request do describe "GET" do context "form pages" do + context "forms exist for multiple years" do + let(:case_log_year_1) { FactoryBot.create(:case_log, startdate: Time.zone.local(2021, 1, 1), owning_organisation: organisation) } + let(:case_log_year_2) { FactoryBot.create(:case_log, startdate: Time.zone.local(2022, 1, 1), owning_organisation: organisation) } + + it "displays the correct question details for each case log based on form year" do + get "/logs/#{case_log_year_1.id}/tenant-code", headers: headers, params: {} + expect(response.body).to include("What is the tenant code?") + get "/logs/#{case_log_year_2.id}/tenant-code", headers: headers, params: {} + expect(response.body).to match("Different question header text for this year - 2023") + end + end + context "case logs that are not owned or managed by your organisation" do it "does not show form pages for case logs you don't have access to" do get "/logs/#{unauthorized_case_log.id}/person-1-age", headers: headers, params: {}