require 'spec_helper' describe LifenFhir::Practitioner do describe ':find_by_rpps' do it 'works' do VCR.use_cassette "practitioner/find_by_rpps/existing_rpps" do @practitioner = LifenFhir::Practitioner.find_by_rpps("810004085790") end expect(@practitioner.channels.size).to eq(3) address = @practitioner.channels.last expect(address.value).to eq "11 RUE CHARLES TELLIER, 75016 Paris" end context 'wrong rpps' do it 'fails nicely' do VCR.use_cassette "practitioner/find_by_rpps/wrong_rpps" do expect { @practitioner = LifenFhir::Practitioner.find_by_rpps("8888888888") }.to raise_error LifenFhir::Error end end end context 'missing lines attribute' do it 'does not raise an issue' do VCR.use_cassette "practitioner/find_by_rpps/missing_line_attribute" do @practitioner = LifenFhir::Practitioner.find_by_rpps("810004085790") end address = @practitioner.channels.last expect(address.value).to eq ", 75016 Paris" end end end describe ':create_address' do let(:practitioner) { LifenFhir::Practitioner.new(uuid: "11e5c85e-9bc0-4c6e-9b29-deb9993a92c0") } it 'works' do VCR.use_cassette "practitioner/create_channel/address/valid_attributes" do @channel = practitioner.create_address(type: "address", lines: ["Honestica", "39 rue d'Aboukir"], city: "Paris", postal_code: "75002", country: "France") end expect(@channel.value).to eq "Honestica, 39 rue d'Aboukir, 75002 Paris" expect(@channel.uuid).to eq "11e73ca3-c4b2-fe69-b5c5-0242ac110002" expect(practitioner.channels.size).to eq 1 end context 'old version' do it 'works' do VCR.use_cassette "practitioner/create_channel/address/old_valid_attributes" do @channel = practitioner.create_address(type: "address", lines: ["Honestica", "39 rue d'Aboukir"], city: "Paris", postal_code: "75002", country: "France") end expect(@channel.value).to eq "Honestica, 39 rue d'Aboukir, 75002 Paris" expect(@channel.uuid).to eq "11e73ca4-e3d4-8c5f-b5c5-0242ac110002" expect(practitioner.channels.size).to eq 1 end end context 'invalid attributes' do it 'fails nicely' do expect{ VCR.use_cassette "practitioner/create_channel/address/invalid_attributes" do practitioner.create_address(type: "address", lines: [], city: "Paris", postal_code: "75002", country: "France") end }.to raise_error LifenFhir::Error end end end describe ':create_telecom' do let(:practitioner) { LifenFhir::Practitioner.new(uuid: "11e5c85e-9bc0-4c6e-9b29-deb9993a92c0") } it 'works' do VCR.use_cassette "practitioner/create_channel/telecom/valid_attributes" do @channel = practitioner.create_telecom(type: "telecom", system: "fax", value: "+33102030405") end expect(@channel.uuid).to eq "11e73ca3-c56a-8e9b-b5c5-0242ac110002" expect(practitioner.channels.size).to eq 1 end context 'invalid attributes' do it 'fails nicely' do expect{ VCR.use_cassette "practitioner/create_channel/telecom/invalid_attributes" do practitioner.create_telecom(type: "telecom", system: "fax", value: "") end }.to raise_error LifenFhir::Error end end end end