80 lines
2.5 KiB
Ruby
80 lines
2.5 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe Public::MedicalReleasesController, type: :controller do
|
|
let(:user) { create(:user) }
|
|
let(:project) { create(:project, account: user.primary_account) }
|
|
|
|
render_views
|
|
|
|
describe "#create" do
|
|
it "displays validation errors" do
|
|
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",
|
|
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
|
|
contract_template = create(:contract_template, project: project)
|
|
|
|
post :create, params: { account_id: user.primary_account.to_param, project_id: project, contract_template_id: contract_template, medical_release: medical_release_params }
|
|
|
|
expect(response).to be_successful
|
|
end
|
|
|
|
it "runs attach contract to releasable job" do
|
|
contract_template = create(:contract_template, project: project)
|
|
|
|
expect {
|
|
post :create, params: { account_id: project.account.to_param, project_id: project, contract_template_id: contract_template, medical_release: medical_release_params }
|
|
}.to(
|
|
have_enqueued_job(AttachContractToReleasableJob)
|
|
.with(MedicalRelease.last)
|
|
)
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def medical_release_params
|
|
attributes_for(:medical_release, :native).except(:signature).merge(signature_param, photos_param)
|
|
end
|
|
|
|
def photos_param
|
|
path = Rails.root.join("spec", "fixtures", "files", "person_photo.png")
|
|
photo = Rack::Test::UploadedFile.new(path, "image/png")
|
|
|
|
{ photos: [photo] }
|
|
end
|
|
|
|
def signature_param
|
|
file = file_fixture("signature.png")
|
|
data_uri = Base64Image.from_image(file).data_uri
|
|
|
|
{ signature_base64: data_uri }
|
|
end
|
|
|
|
def question_answer_validation_error
|
|
t 'medical_releases.custom_validation_errors.question_answer_is_required'
|
|
end
|
|
end
|