Browse Source

Test for multiple forms

pull/178/head
baarkerlounger 3 years ago
parent
commit
fc3b775827
  1. 25
      spec/fixtures/forms/2022_2023.json
  2. 2
      spec/lib/tasks/form_definition_validator_spec.rb
  3. 12
      spec/requests/form_controller_spec.rb

25
spec/fixtures/forms/2022_2023.json vendored

@ -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
}
}
}
}
}
}
}
}
}

2
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

12
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: {}

Loading…
Cancel
Save