spec/extractor_spec.rb in oddb2xml-2.1.7 vs spec/extractor_spec.rb in oddb2xml-2.1.8

- old
+ new

@@ -1,19 +1,114 @@ # encoding: utf-8 require 'spec_helper' require "#{Dir.pwd}/lib/oddb2xml/downloader" +ENV['TZ'] = 'UTC' # needed for last_change -describe Oddb2xml::Extractor do - it "pending" +describe Oddb2xml::BMUpdateExtractor do + before(:all) { VCR.eject_cassette; VCR.insert_cassette('oddb2xml') } + after(:all) { VCR.eject_cassette } + before(:all) { + VCR.eject_cassette; VCR.insert_cassette('oddb2xml') + @downloader = Oddb2xml::BMUpdateDownloader.new + xml = @downloader.download + @items = Oddb2xml::BMUpdateExtractor.new(xml).to_hash + } + it "should have at least one item" do + expect(@items.size).not_to eq 0 + end end -describe Oddb2xml::TxtExtractorMethods do - it "pending" +describe Oddb2xml::LppvExtractor do + before(:all) { + VCR.eject_cassette; VCR.insert_cassette('oddb2xml') + @downloader = Oddb2xml::LppvDownloader.new + @content = @downloader.download + @lppvs = Oddb2xml::LppvExtractor.new(@content).to_hash + } + after(:all) { VCR.eject_cassette } + it "should have at least one item" do + expect(@lppvs.size).not_to eq 0 + end end +describe Oddb2xml::MigelExtractor do + before(:all) { + VCR.eject_cassette; VCR.insert_cassette('oddb2xml') + @downloader = Oddb2xml::MigelDownloader.new + xml = @downloader.download + @items = Oddb2xml::MigelExtractor.new(xml).to_hash + } + after(:all) { VCR.eject_cassette } + it "should have at some items" do + expect(@items.size).not_to eq 0 + expect(@items.find{|k,v| /3248410/i.match(v[:pharmacode]) }).not_to be_nil + expect(@items.find{|k,v| /Novopen/i.match(v[:desc_de]) }).not_to be_nil + expect(@items.find{|k,v| /3036984/i.match(v[:pharmacode]) }).not_to be_nil + end +end + +describe Oddb2xml::RefdataExtractor do + before(:all) { VCR.eject_cassette; VCR.insert_cassette('oddb2xml') } + after(:all) { VCR.eject_cassette } + context 'should handle pharma articles' do + subject do + @downloader = Oddb2xml::RefdataDownloader.new({}, :pharma) + xml = @downloader.download + @pharma_items = Oddb2xml::RefdataExtractor.new(xml, 'PHARMA').to_hash + end + + it "should have correct info for pharmacode 1699947 correctly" do + @pharma_items = subject.to_hash + pharma_code_LEVETIRACETAM = "5819012" + item_found = @pharma_items.values.find{ |x| x[:pharmacode].eql?(pharma_code_LEVETIRACETAM)} + expect(item_found).not_to be nil + expected = { :refdata=>true, + :_type=>:pharma, + :ean=> Oddb2xml::LEVETIRACETAM_GTIN, + :pharmacode=> pharma_code_LEVETIRACETAM, + :last_change => "2015-06-04 00:00:00 +0000", + :desc_de=>"LEVETIRACETAM DESITIN Mini Filmtab 250 mg 30 Stk", + :desc_fr=>"LEVETIRACETAM DESITIN mini cpr pel 250 mg 30 pce", + :atc_code=>"N03AX14", + :company_name=>"Desitin Pharma GmbH", + :company_ean=>"7601001320451"} + expect(item_found).to eq(expected) + expect(@pharma_items.size).to eq(15) + end + end + context 'should handle nonpharma articles' do + subject do + @downloader = Oddb2xml::RefdataDownloader.new({}, :nonpharma) + xml = @downloader.download + @non_pharma_items = Oddb2xml::RefdataExtractor.new(xml, :non_pharma).to_hash + end + + it "should have correct info for nonpharma with pharmacode 0058502 correctly" do + @non_pharma_items = subject.to_hash + pharma_code_TUBEGAZE = '0058519' + item_found = @non_pharma_items.values.find{ |x| x[:pharmacode].eql?(pharma_code_TUBEGAZE)} + expect(item_found).not_to be nil + expected = {:refdata=>true, + :_type=>:nonpharma, + :ean=>"7611600441020", + :pharmacode=>pharma_code_TUBEGAZE, + :last_change => "2015-06-04 00:00:00 +0000", + :desc_de=>"TUBEGAZE Verband weiss Nr 12 20m Finger gross", + :desc_fr=>"TUBEGAZE pans tubul blanc Nr 12 20m doigts grands", + :atc_code=>"", + :company_name=>"IVF HARTMANN AG", + :company_ean=>"7601001000896"} + expect(item_found).to eq(expected) + expect(@non_pharma_items.size).to eq(9) + end + end +end + describe Oddb2xml::BagXmlExtractor do + before(:all) { VCR.eject_cassette; VCR.insert_cassette('oddb2xml') } + after(:all) { VCR.eject_cassette } context 'should handle articles with and without pharmacode' do subject do dat = File.read(File.join(Oddb2xml::SpecData, 'Preparations.xml')) Oddb2xml::BagXmlExtractor.new(dat).to_hash end @@ -39,99 +134,83 @@ expect(no_pharma[:packages].first[1][:prices][:pub_price][:price]).to eq('27.8') end end end -describe Oddb2xml::SwissIndexExtractor do - it "pending" -end - -describe Oddb2xml::BMUpdateExtractor do - it "pending" -end - -describe Oddb2xml::LppvExtractor do - it "pending" -end - -describe Oddb2xml::SwissIndexExtractor do - it "pending" -end - -describe Oddb2xml::MigelExtractor do - it "pending" -end - describe Oddb2xml::SwissmedicInfoExtractor do + before(:all) { VCR.eject_cassette; VCR.insert_cassette('oddb2xml') } + after(:all) { VCR.eject_cassette } include ServerMockHelper before(:each) do - setup_swissmedic_info_server_mock @downloader = Oddb2xml::SwissmedicInfoDownloader.new end context 'builds fachfinfo' do it { xml = @downloader.download @infos = Oddb2xml::SwissmedicInfoExtractor.new(xml).to_hash - expect(@infos.size).to eq(1) - erbiumcitrat = nil + expect(@infos.keys).to eq ['de', 'fr'] + expect(@infos['de'].size).to eq 5 + expect(@infos['fr'].size).to eq 2 + levetiracetam = nil @infos['de'].each{|info| - erbiumcitrat = info if /Erbiumcitrat/.match(info[:name]) + levetiracetam = info if /Levetiracetam/.match(info[:name]) } - expect(erbiumcitrat[:owner]).to eq('CBI Medical Products Vertriebs GmbH') - expect(erbiumcitrat[:paragraph].to_s).to match(/Packungen/) - expect(erbiumcitrat[:paragraph].to_s).to match(/Stand der Information/) - expect(erbiumcitrat[:paragraph].to_s).to match(/Zulassungsinhaberin/) + expect(levetiracetam[:owner]).to eq('Desitin Pharma GmbH') + expect(levetiracetam[:paragraph].to_s).to match(/Packungen/) + expect(levetiracetam[:paragraph].to_s).to match(/Zulassungsinhaberin/) } end end describe Oddb2xml::SwissmedicExtractor do - before(:each) do - setup_epha_atc_csv_mock - end + before(:all) { VCR.eject_cassette; VCR.insert_cassette('oddb2xml') } + after(:all) { VCR.eject_cassette } context 'when transfer.dat is empty' do subject { Oddb2xml::SwissmedicInfoExtractor.new("") } it { expect(subject.to_hash).to be_empty } end context 'can parse swissmedic_package.xlsx' do it { + cleanup_directories_before_run filename = File.join(Oddb2xml::SpecData, 'swissmedic_package.xlsx') @packs = Oddb2xml::SwissmedicExtractor.new(filename, :package).to_hash expect(@packs.size).to eq(17) serocytol = nil @packs.each{|pack| - serocytol = pack[1] if pack[0].to_s == '00274001' + serocytol = pack[1] if pack[1][:ean] == '7680620690084' } - expect(serocytol[:atc_code]).to eq('J06AA') + expect(serocytol[:atc_code]).to eq('N03AX14') expect(serocytol[:swissmedic_category]).to eq('B') - expect(serocytol[:package_size]).to eq('3') - expect(serocytol[:einheit_swissmedic]).to eq('Suppositorien') - expect(serocytol[:substance_swissmedic]).to eq('globulina equina (immunisé avec coeur, tissu pulmonaire, reins de porcins)') + expect(serocytol[:package_size]).to eq('30') + expect(serocytol[:einheit_swissmedic]).to eq('Tablette(n)') + expect(serocytol[:substance_swissmedic]).to eq('levetiracetamum') } end context 'can parse swissmedic_fridge.xlsx' do it { filename = File.join(Oddb2xml::SpecData, 'swissmedic_fridge.xlsx') @packs = Oddb2xml::SwissmedicExtractor.new(filename, :fridge).to_arry - expect(@packs.size).to eq(17) + expect(@packs.size >= 17).to eq true expect(@packs[0]).to eq("58618") expect(@packs[1]).to eq("00696") } end context 'can parse swissmedic_orphans.xls' do it { filename = File.join(Oddb2xml::SpecData, 'swissmedic_orphan.xlsx') expect(File.exists?(filename)).to eq(true), "File #{filename} must exists" @packs = Oddb2xml::SwissmedicExtractor.new(filename, :orphan).to_arry - expect(@packs.size).to eq(78) + expect(@packs.size >= 78).to eq true expect(@packs.first).to eq("62132") expect(@packs[7]).to eq("00687") } end end describe Oddb2xml::EphaExtractor do + before(:all) { VCR.eject_cassette; VCR.insert_cassette('oddb2xml') } + after(:all) { VCR.eject_cassette } context 'can parse epha_interactions.csv' do it { filename = File.join(Oddb2xml::SpecData, 'epha_interactions.csv') string = IO.read(filename) @actions = Oddb2xml::EphaExtractor.new(string).to_arry @@ -139,14 +218,18 @@ } end end describe Oddb2xml::MedregbmExtractor do + before(:all) { VCR.eject_cassette; VCR.insert_cassette('oddb2xml') } + after(:all) { VCR.eject_cassette } it "pending" end describe Oddb2xml::ZurroseExtractor do + before(:all) { VCR.eject_cassette; VCR.insert_cassette('oddb2xml') } + after(:all) { VCR.eject_cassette } context 'when transfer.dat is empty' do subject { Oddb2xml::ZurroseExtractor.new("") } it { expect(subject.to_hash).to be_empty } end context 'when transfer.dat is nil' do @@ -178,11 +261,10 @@ dat = <<-DAT 1130921929OESTRADIOL Inj L�s 5 mg 10 Amp 1 ml 000940001630300B070820076802840708402\r\n DAT Oddb2xml::ZurroseExtractor.new(dat) end - #it { expect(pp subject.to_hash) } it { expect(subject.to_hash.keys.length).to eq(1) } it { expect(subject.to_hash.keys.first).to eq("7680284070840") } it { expect(subject.to_hash.values.first[:vat]).to eq("2") } it { expect(subject.to_hash.values.first[:price]).to eq("9.40") } it { expect(subject.to_hash.values.first[:pub_price]).to eq("16.30") } @@ -246,6 +328,6 @@ end } end -end +end \ No newline at end of file