spec/patient_spec.rb in lifen_fhir-0.4.1 vs spec/patient_spec.rb in lifen_fhir-0.4.2

- old
+ new

@@ -2,32 +2,72 @@ describe LifenFhir::Patient do describe ':create' do - it 'works' do - - address = LifenFhir::Address.new( + let(:address) { + LifenFhir::Address.new( lines: ["M et Mme Potter", "39 rue d'Aboukir"], - city:"paris", - postal_code: "75002" + city: "paris", + postal_code: "75002", + country: "France" ) + } + let(:patient) { patient = LifenFhir::Patient.new( first_name: ["Pierre", "Henri"], last_name: "Potter", birth_date: Date.new(1974, 12, 25), address: address ) + } - VCR.use_cassette("patient/create/with_all_information", match_requests_on: [:method, :uri, :body]) do + it 'works' do + VCR.use_cassette("patient/create/with_all_information") do patient.save end expect(patient.uuid).to eq("ab7002e2-f017-48a5-ae09-1e232dc7c726") end + context 'with first_name as a string' do + + it 'works' do + patient.first_name = "Pierre" + + VCR.use_cassette("patient/create/with_first_name_as_a_string") do + patient.save + end + + expect(patient.uuid).to eq("f15cd0df-4edb-4b5b-9785-7390405af6cb") + end + + end + + context 'with no birth_date' do + + it 'has no birthDate in fhir_payload' do + patient.birth_date = nil + + expect(patient.fhir_payload["birthDate"]).to be_nil + end + + end + + context 'invalid attributes' do + it 'fails nicely' do + patient.last_name = nil + + expect{ + VCR.use_cassette("patient/create/invalid_attributes") do + patient.save + end + }.to raise_error LifenFhir::Error + end + end + end describe ':find_by_uuid' do it 'works' do @@ -44,15 +84,16 @@ expect(address.postal_code).to eq("75002") expect(address.city).to eq("paris") expect(address.lines.size).to eq(2) end - it 'wrong uuid' do - - VCR.use_cassette "patient/find/with_wrong_id" do - expect { - @patient = LifenFhir::Patient.find_by_uuid("wrong-uuid") - }.to raise_error LifenFhir::Error + context 'invalid uuid' do + it 'fails nicely' do + VCR.use_cassette "patient/find/with_wrong_id" do + expect { + @patient = LifenFhir::Patient.find_by_uuid("wrong-uuid") + }.to raise_error LifenFhir::Error + end end end end end