require 'spec_helper' describe LifenFhir::Communication do describe ':find_by_uuid' do context 'valid communication_uuid' do it 'works' do VCR.use_cassette "communication/find_by_uuid/valid_uuid" do @communication = LifenFhir::Communication.find_by_uuid("11e74a9a-c769-ada3-81a2-0242ac110004") end expect(@communication.uuid).to eq("11e74a9a-c769-ada3-81a2-0242ac110004") expect(@communication.sender.uuid).to eq("11e5b841-4ff1-2dbb-9643-eabb809fa654") expect(@communication.recipient.uuid).to eq("11e5b841-4ff8-2dbb-9643-eabb809fa654") expect(@communication.recipient.class.name).to eq("LifenFhir::Practitioner") expect(@communication.medium.display).to eq("DR Xavier Apicrypt,33 rue des Buchers,31000 Toulouse") expect(@communication.medium.code).to eq("PAPER") expect(@communication.status).to eq("preparation") end end context 'non valid communication_uuid' do it 'fails nicely' do expect{ VCR.use_cassette "communication/find_by_uuid/non_valid_uuid" do @communication = LifenFhir::Communication.find_by_uuid("non_valid_communication_uuid") end }.to raise_error LifenFhir::Error end end context 'non valid status' do it 'fails nicely' do expect{ VCR.use_cassette "communication/find_by_uuid/non_valid_status" do @communication = LifenFhir::Communication.find_by_uuid("non_valid_communication_uuid") end }.to raise_error LifenFhir::Error end end context 'recipient is a patient' do it 'works' do VCR.use_cassette "communication/find_by_uuid/recipient_is_patient" do @communication = LifenFhir::Communication.find_by_uuid("11e75015-3d29-bcc5-998e-0242ac110005") end expect(@communication.uuid).to eq("11e75015-3d29-bcc5-998e-0242ac110005") expect(@communication.sender.uuid).to eq("11e5b841-4faa-2dbb-9643-eabb809fa654") expect(@communication.recipient.uuid).to eq("7d8d1805-eb43-4203-ab20-94a042b9d932") expect(@communication.recipient.class.name).to eq("LifenFhir::Patient") expect(@communication.medium.display).to eq("39 rue d'Aboukir,75002 PARIS") expect(@communication.medium.code).to eq("PAPER") expect(@communication.status).to eq("preparation") end end end end