require 'spec_helper' describe Lifen::Practitioner do describe ':find_by_rpps' do it 'finds the practitionners' do VCR.use_cassette "practitionner/find_by_rpps/existing_rpps" do @practitionner = Lifen::Practitioner.find_by_rpps("810004085790") end expect(@practitionner.channels.size).to eq(3) address = @practitionner.channels.last expect(address.value).to eq "11 RUE CHARLES TELLIER, 75016 Paris" end it 'cannot find rpps' do VCR.use_cassette "practitionner/find_by_rpps/wrong_rpps" do expect { @practitionner = Lifen::Practitioner.find_by_rpps("8888888888") }.to raise_error Lifen::Error end end end context 'missing lines attribute' do it 'does not raise an issue' do VCR.use_cassette "practitionner/find_by_rpps/missing_line_attribute" do @practitionner = Lifen::Practitioner.find_by_rpps("810004085790") end address = @practitionner.channels.last expect(address.value).to eq ", 75016 Paris" end end describe ':create_address' do let(:practitionner) { Lifen::Practitioner.new(uuid: "11e5c85e-9bc0-4c6e-9b29-deb9993a92c0") } it 'creates the address' do VCR.use_cassette "practitionner/create_channel/address/valid_attributes" do @channel = practitionner.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(practitionner.channels.size).to eq 1 end it 'creates the channel - old version' do VCR.use_cassette "practitionner/create_channel/address/old_valid_attributes" do @channel = practitionner.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(practitionner.channels.size).to eq 1 end it 'creates the telecom-fax channel' do VCR.use_cassette "practitionner/create_channel/telecom/valid_attributes" do @channel = practitionner.create_telecom(type: "telecom", system: "fax", value: "+33102030405") end expect(@channel.uuid).to eq "11e73ca3-c56a-8e9b-b5c5-0242ac110002" expect(practitionner.channels.size).to eq 1 end end end