require 'spec_helper' describe LifenFhir::Patient do describe ':create' do let(:address) { LifenFhir::Address.new( lines: ["M et Mme Potter", "39 rue d'Aboukir"], 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 ) } 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 VCR.use_cassette "patient/find/with_valid_id" do @patient = LifenFhir::Patient.find_by_uuid("ab7002e2-f017-48a5-ae09-1e232dc7c726") end expect(@patient.last_name).to eq("Potter") expect(@patient.first_name).to eq(["Pierre", "Henri"]) expect(@patient.birth_date).to eq(Date.new(1974, 12, 25)) address = @patient.address expect(address.postal_code).to eq("75002") expect(address.city).to eq("paris") expect(address.lines.size).to eq(2) end 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