require 'spec_helper' describe Lifen::Communication do let(:channel) { Lifen::Channel.new(uuid: "valid_channel_uuid", type: "address") } #valid_channel_uuid let(:sender) { Lifen::User.new(uuid: "valid_sender_uuid") } #valid_sender_uuid let(:recipient) { Lifen::User.new(uuid: "valid_recipient_uuid") } #valid_recipient_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)) } let(:binary) { Lifen::Binary.new(uuid: "valid_binary_id") } describe ':send with an Attachment' do let(:communication) { Lifen::Communication.new(sender: sender, recipient: recipient, channel: channel, attachment: attachment, patient: patient) } it 'works' do VCR.use_cassette "communication/send/valid_attributes" do communication.send end expect(communication.uuid).to_not be_nil end context 'invalid channel' do let(:channel) { Lifen::Channel.new(uuid: nil) } it 'raises an error' do expect{ communication.send }.to raise_error Lifen::Error, "Invalid channel: an UUID is required" end end end describe ':send with a Binary' do let(:communication) { Lifen::Communication.new(sender: sender, recipient: recipient, channel: channel, binary: binary, patient: patient) } let(:contentString) { Lifen::ContentString.new(text: "Cher Dr Coeur, je viens de voir votre patiente Mme Paulette Michu")} it 'works' do VCR.use_cassette "communication/send/binary_valid_attributes" do communication.send end expect(communication.uuid).to_not be_nil end it 'works with contentString' do communication.content_string = contentString VCR.use_cassette "communication/send/binary_and_content_string" do communication.send end expect(communication.uuid).to_not be_nil end end describe ':find' do it 'works' do VCR.use_cassette "communication/find/valid_uuid" do @communication = Lifen::Communication.find "11e71070-15f9-23c1-9ad2-0242ac110002" end expect(@communication.status).to eq "completed" expect(@communication.uuid).to eq "11e71070-15f9-23c1-9ad2-0242ac110002" expect(@communication.sent_at).to eq DateTime.new(2017,3,24,8,58,45) expect(@communication.received_at).to eq DateTime.new(2017,3,24,8,58,44) expect(@communication.sender.uuid).to eq "11e5b841-4ff1-2dbb-9643-eabb809fa654" expect(@communication.recipient.uuid).to eq "11e5c866-a698-cfb0-9b29-deb9993a92c0" end context 'invalid uuid' do it 'raises an error' do VCR.use_cassette "communication/find/invalid_uuid" do expect{ Lifen::Communication.find "invalid-communication-uuid" }.to raise_error Lifen::Error, "Error 404, Page not found, App Client, GET 'https://develop.lifen.fr/fhir/Communication/invalid-communication-uuid' with params '{}' and bearer 'valid_application_access******'" end end end end end