require 'spec_helper' describe Lifen::CommunicationRequest do let(:medium1) { Lifen::Medium.new(uuid: "valid-medium-uuid-1") } #valid_channel_uuid let(:medium2) { Lifen::Medium.new(uuid: "valid-medium-uuid-2") } let(:sender) { Lifen::Practitioner.new(uuid: "valid-sender-uuid") } #valid_sender_uuid let(:recipient1) { Lifen::Practitioner.new(uuid: "valid-recipient-uuid-1") } let(:recipient2) { Lifen::Practitioner.new(uuid: "valid-recipient-uuid-2") }#valid_recipient_uuid let(:binary) { Lifen::Binary.new(uuid: "valid-binary-uuid") } let(:attachment) { Lifen::Attachment.new(title: "Master Plan", path: File.dirname(__FILE__) + "/support/master_plan.pdf", content_type: "application/pdf") } let(:patient) { Lifen::Patient.new(first_name: "Jean", last_name: "Dupond", birthdate: Date.new(2000,1,1)) } describe ':send multi-recipients with a binary' do let(:communication_request) { Lifen::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) { Lifen::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) { Lifen::Medium.new(uuid: "invalid-medium-uuid") } let(:communication_request) { Lifen::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 Lifen::Error end end end end