Browse Source

Test valid form submit request

pull/112/head
baarkerlounger 3 years ago
parent
commit
1e5236ca4a
  1. 4
      app/models/form/page.rb
  2. 2
      app/models/form/section.rb
  3. 2
      app/models/form/subsection.rb
  4. 15
      spec/requests/case_log_controller_spec.rb

4
app/models/form/page.rb

@ -6,9 +6,9 @@ class Form::Page
@id = id @id = id
@header = hsh["header"] @header = hsh["header"]
@description = hsh["description"] @description = hsh["description"]
@questions = hsh["questions"].map { |q_id, q| Form::Question.new(q_id, q, self) } @questions = hsh["questions"].map { |id, q| Form::Question.new(id, q, self) }
@depends_on = hsh["depends_on"] @depends_on = hsh["depends_on"]
@soft_validations = hsh["soft_validations"]&.map { |v_id, s| Form::Question.new(v_id, s, self) } @soft_validations = hsh["soft_validations"]&.map { |id, s| Form::Question.new(id, s, self) }
@subsection = subsection @subsection = subsection
end end

2
app/models/form/section.rb

@ -5,6 +5,6 @@ class Form::Section
@id = id @id = id
@label = hsh["label"] @label = hsh["label"]
@form = form @form = form
@subsections = hsh["subsections"].map { |s_id, s| Form::Subsection.new(s_id, s, self) } @subsections = hsh["subsections"].map { |id, s| Form::Subsection.new(id, s, self) }
end end
end end

2
app/models/form/subsection.rb

@ -5,7 +5,7 @@ class Form::Subsection
@id = id @id = id
@label = hsh["label"] @label = hsh["label"]
@depends_on = hsh["depends_on"] @depends_on = hsh["depends_on"]
@pages = hsh["pages"].map { |s_id, p| Form::Page.new(s_id, p, self) } @pages = hsh["pages"].map { |id, p| Form::Page.new(id, p, self) }
@section = section @section = section
end end

15
spec/requests/case_log_controller_spec.rb

@ -278,9 +278,9 @@ RSpec.describe CaseLogsController, type: :request do
describe "Submit Form" do describe "Submit Form" do
let(:user) { FactoryBot.create(:user) } let(:user) { FactoryBot.create(:user) }
let(:form) { Form.new("spec/fixtures/forms/test_form.json") }
let(:case_log) { FactoryBot.create(:case_log, :in_progress) } let(:case_log) { FactoryBot.create(:case_log, :in_progress) }
let(:page_id) { "person_1_age" } let(:page_id) { "person_1_age" }
let(:answer) { 2000 }
let(:params) do let(:params) do
{ {
id: case_log.id, id: case_log.id,
@ -292,12 +292,25 @@ RSpec.describe CaseLogsController, type: :request do
end end
before do before do
allow(FormHandler.instance).to receive(:get_form).and_return(form)
sign_in user sign_in user
post "/case_logs/#{case_log.id}/form", params: params post "/case_logs/#{case_log.id}/form", params: params
end end
context "invalid answers" do
let(:answer) { 2000 }
it "re-renders the same page with errors if validation fails" do it "re-renders the same page with errors if validation fails" do
expect(response).to have_http_status(:unprocessable_entity) expect(response).to have_http_status(:unprocessable_entity)
end end
end end
context "valid answers" do
let(:answer) { 20 }
it "re-renders the same page with errors if validation fails" do
expect(response).to have_http_status(:redirect)
end
end
end
end end

Loading…
Cancel
Save