require 'spec_helper' describe LifenFhir::CommunicationRequest do let(:medium1) { LifenFhir::Medium.new(uuid: "valid-medium-uuid-1") } #valid_channel_uuid let(:medium2) { LifenFhir::Medium.new(uuid: "valid-medium-uuid-2") } let(:sender) { LifenFhir::Practitioner.new(uuid: "valid-sender-uuid") } #valid_sender_uuid let(:recipient1) { LifenFhir::Practitioner.new(uuid: "valid-recipient-uuid-1") } let(:recipient2) { LifenFhir::Practitioner.new(uuid: "valid-recipient-uuid-2") }#valid_recipient_uuid let(:binary) { LifenFhir::Binary.new(uuid: "valid-binary-uuid") } let(:attachment) { LifenFhir::Attachment.new(title: "Master Plan", path: File.dirname(__FILE__) + "/support/master_plan.pdf", content_type: "application/pdf") } let(:patient) { LifenFhir::Patient.new(first_name: "Jean", last_name: "Dupond", birth_date: Date.new(2000,1,1)) } describe ':send multi-recipients with a binary' do let(:communication_request) { LifenFhir::CommunicationRequest.new(sender: sender, recipients: [recipient1, recipient2], medium: [medium1, medium2], binary: binary, patient: patient) } it 'works' do VCR.use_cassette "communication_request/send/valid_attributes_binary" do communication_request.send end expect(communication_request.uuid).to_not be_nil expect(communication_request.number_communications).to eq(2) end end describe ':send multi-recipients with an attachment' do let(:communication_request) { LifenFhir::CommunicationRequest.new(sender: sender, recipients: [recipient1, recipient2], medium: [medium1, medium2], attachment: attachment, patient: patient) } it 'works' do VCR.use_cassette "communication_request/send/valid_attributes" do communication_request.send end expect(communication_request.uuid).to_not be_nil expect(communication_request.number_communications).to eq(2) end end describe 'invalid medium' do let(:invalid_medium) { LifenFhir::Medium.new(uuid: "invalid-medium-uuid") } let(:communication_request) { LifenFhir::CommunicationRequest.new(sender: sender, recipients: [recipient1, recipient2], medium: [invalid_medium, medium2], binary: binary, patient: patient) } it 'raises an error' do VCR.use_cassette "communication_request/send/invalid_medium" do expect{ communication_request.send }.to raise_error LifenFhir::Error end end end end