add specs

This commit is contained in:
Bilal
2020-07-03 18:44:27 +02:00
parent 08f6380aaa
commit 85b99e18f5
3 changed files with 79 additions and 2 deletions

View File

@@ -19,14 +19,29 @@ RSpec.describe Public::MedicalReleasesController, type: :controller do
end
it "displays validation errors" do
contract_template = create(:contract_template, project: project)
contract_template = create(:contract_template,
project: project,
question_1_text: "Question 1",
question_2_text: "Question 2"
)
sign_in(user)
post :create, params: { account_id: user.primary_account.to_param, project_id: project, contract_template_id: contract_template, medical_release: { person_address_city: "Albuquerque" } }
post :create, params: {
account_id: user.primary_account.to_param,
project_id: project,
contract_template_id: contract_template,
medical_release: {
person_address_city: "Albuquerque",
question_2_answer: "Answer 2"
}
}
body = CGI.unescape_html(response.body)
expect(body).to match /Person first name can't be blank/
expect(body).to match /Person last name can't be blank/
expect(body).to match />can't be blank</
expect(body).to match /Question 1 #{question_answer_validation_error}/
expect(body).not_to match /Question 2 #{question_answer_validation_error}/
end
it "responds with success " do
@@ -68,4 +83,8 @@ RSpec.describe Public::MedicalReleasesController, type: :controller do
{ signature_base64: data_uri }
end
def question_answer_validation_error
t 'medical_releases.custom_validation_errors.question_answer_is_required'
end
end

View File

@@ -121,6 +121,43 @@ feature "User managing medical releases" do
expect(page).to have_content(successful_submission_message)
expect(MedicalRelease.last.guardian_2_first_name).to eq 'Second'
end
scenario 'when signing release, question answers are required', js: true do
project = create(:project, members: current_user, account: current_user.primary_account)
contract_template = create(:contract_template,
project: project,
question_1_text: 'Question 1',
question_2_text: 'Question 2'
)
visit new_account_project_contract_template_medical_release_path(project.account, project, contract_template)
fill_in person_first_name_field, with: 'Jane'
fill_in person_last_name_field, with: 'Doe'
draw_signature file_fixture("signature.png"), "medical_release_signature_base64"
expect do
click_button submit_release_button
end.to change(MedicalRelease, :count).by(0)
expect(page).not_to have_content(successful_submission_message)
fill_in answer_field_for_question(1), with: 'Answer 1'
draw_signature file_fixture("signature.png"), "medical_release_signature_base64"
expect do
click_button submit_release_button
end.to change(MedicalRelease, :count).by(0)
expect(page).not_to have_content(successful_submission_message)
fill_in answer_field_for_question(2), with: 'Answer 2'
draw_signature file_fixture("signature.png"), "medical_release_signature_base64"
expect do
click_button submit_release_button
end.to change(MedicalRelease, :count).by(1)
expect(page).to have_content(successful_submission_message)
end
end
context "when signed in as account manager" do
@@ -396,4 +433,8 @@ feature "User managing medical releases" do
def guardian_2_information_heading
t 'public.medical_releases.new.guardian_2_info.heading'
end
def answer_field_for_question(number)
"medical_release[question_#{number}_answer]"
end
end

View File

@@ -22,6 +22,23 @@ RSpec.describe MedicalRelease do
context "for non-native releases" do
it { is_expected.to validate_attachment_of(:contract).on(:non_native) }
end
context "question answers" do
let(:project) { create(:project) }
let(:contract_template) { create(:contract_template, project: project, question_1_text: 'Question 1') }
it "returns validation errors if answers are missing" do
expect do
create(:medical_release, contract_template: contract_template)
end.to raise_exception ActiveRecord::RecordInvalid
end
it "creates release if answers are present" do
expect do
create(:medical_release, contract_template: contract_template, question_1_answer: 'Answer 1')
end.to change(MedicalRelease, :count).by(1)
end
end
end
describe "attachments" do