Skip to content

Commit

Permalink
Added spec test for duplicates when -e given
Browse files Browse the repository at this point in the history
  • Loading branch information
ngiger committed Apr 23, 2014
1 parent 14fca70 commit db9a1a2
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 12 deletions.
100 changes: 88 additions & 12 deletions spec/builder_spec.rb
@@ -1,6 +1,8 @@
# encoding: utf-8

require 'spec_helper'
require "rexml/document"
include REXML

module Kernel
def capture(stream)
Expand All @@ -27,6 +29,7 @@ def capture(stream)
setup_server_mocks
setup_swiss_index_server_mock(types = ['NonPharma', 'Pharma'])
end
if true
context 'should handle BAG-articles with and without pharmacode' do
it {
dat = File.read(File.expand_path('../data/Preparation.xml', __FILE__))
Expand All @@ -41,42 +44,42 @@ def capture(stream)
let(:cli) do
opts = {}
Oddb2xml::Cli.new(opts)
end
end
it 'should generate a valid oddb_product.xml' do
res = capture(:stdout){ cli.run }
res.should match(/products/)
article_filename = File.expand_path(File.join(File.dirname(__FILE__), '..', 'oddb_article.xml'))
File.exists?(article_filename).should be_true
File.exists?(article_filename).should be_true
article_xml = IO.read(article_filename)
product_filename = File.expand_path(File.join(File.dirname(__FILE__), '..', 'oddb_product.xml'))
File.exists?(product_filename).should be_true
unless /1\.8\.7/.match(RUBY_VERSION)
product_xml = IO.read(product_filename)
article_xml.should match(/3TC/)
article_xml.should match(/3TC/)
article_xml.should match(/<PHAR>1699947</)
article_xml.should match(/<SMNO>53662013</)
article_xml.should match(/<DSCRD>3TC Filmtabl 150 mg</)
article_xml.should match(/<COMPNO>7601001392175</)
article_xml.should match(/<SMNO>53662013</)
article_xml.should match(/<DSCRD>3TC Filmtabl 150 mg</)
article_xml.should match(/<COMPNO>7601001392175</)
article_xml.should match(/<BC>7680536620137</)
article_xml.should match(/<VDAT>01.10.2011</)
article_xml.should match(/<PTYP>PEXF</)
article_xml.should match(/<PRICE>164.55</)
article_xml.should match(/<PTYP>PPUB</)
article_xml.should match(/<PRICE>205.3</)
article_xml.should match(/Levetiracetam DESITIN/i) #

article_xml.should match(/Levetiracetam DESITIN/i) #
article_xml.should match(/7680536620137/) # Pharmacode
article_xml.should match(/<PRICE>13.49</)
article_xml.should match(/<PRICE>27.8</)
article_xml.should match(/<PRICE>13.49</)
article_xml.should match(/<PRICE>27.8</)

product_xml.should match(/3TC/)
product_xml.should match(/7680620690084/) # Levetiracetam DESITIN
article_xml.scan(/<ART DT=/).size.should eq(2) # we should find two articles
article_xml.scan(/<ART DT=/).size.should eq(3) # we should find two articles
article_xml.should match(/<PHAR>5819012</)
article_xml.should match(/<DSCRD>LEVETIRACETAM DESITIN Filmtabl 250 mg/)
article_xml.should match(/<COMPNO>7601001320451</)
end
end
end
end

context 'when -a nonpharma -f dat is given' do
Expand All @@ -99,5 +102,78 @@ def capture(stream)
it "pending should match EAN of Desitin. returns 0 at the moment"

end
end
context 'when option -e is given' do
let(:cli) do
opts = {
:extended => :true,
:nonpharma => :true,
:price => :zurrose,
}
Oddb2xml::Cli.new(opts)
end

it 'should emit correct data when called with -e (extended)' do
res = capture(:stdout){ cli.run }
res.should match(/products/)
article_filename = File.expand_path(File.join(File.dirname(__FILE__), '..', 'oddb_article.xml'))
File.exists?(article_filename).should be_true
article_xml = IO.read(article_filename)
product_filename = File.expand_path(File.join(File.dirname(__FILE__), '..', 'oddb_product.xml'))
File.exists?(product_filename).should be_true

# check substances
doc = REXML::Document.new File.new(File.join(File.dirname(__FILE__), '..', 'oddb_substance.xml'))
names = XPath.match( doc, "//NAML" )
names.size.should == 2
names.find_all{|x| x.text.match('Lamivudinum') }.size.should == 1

# check interactions
doc = REXML::Document.new File.new(File.join(File.dirname(__FILE__), '..', 'oddb_interaction.xml'))
titles = XPath.match( doc, "//TITD" )
titles.size.should == 2
titles.find_all{|x| x.text.match('Keine Interaktion') }.size.should == 1
titles.find_all{|x| x.text.match('Erhöhtes Risiko für Myopathie und Rhabdomyolyse') }.size.should == 1

unless /1\.8\.7/.match(RUBY_VERSION)
# check articles
article_xml.should match(/3TC/)
article_xml.should match(/<PHAR>1699947</)
article_xml.should match(/<SMNO>53662013</)
article_xml.should match(/<DSCRD>3TC Filmtabl 150 mg</)
article_xml.should match(/<COMPNO>7601001392175</)
article_xml.should match(/<BC>7680536620137</)
article_xml.should match(/<VDAT>01.10.2011</)
article_xml.should match(/<PTYP>PEXF</)
article_xml.should match(/<PRICE>164.55</)
article_xml.should match(/<PTYP>PPUB</)
article_xml.should match(/<PRICE>205.3</)

article_xml.should match(/Levetiracetam DESITIN/i) #
article_xml.should match(/7680536620137/) # Pharmacode
article_xml.should match(/<PRICE>13.49</)
article_xml.should match(/<PRICE>27.8</)
article_xml.scan(/<ART DT=/).size.should eq(60) # we should find some articles
article_xml.should match(/<PHAR>5819012</)
article_xml.should match(/<DSCRD>LEVETIRACETAM DESITIN Filmtabl 250 mg/)
article_xml.should match(/<COMPNO>7601001320451</)

# check products
product_xml = IO.read(product_filename)
product_xml.should match(/3TC/)
product_xml.should match(/7680620690084/) # Levetiracetam DESITIN

# check ZYVOXID in article
article_xml.should match(/7680555580054/) # ZYVOXID
article_xml.should match(/ZYVOXID/i)

product_xml.should match(/7680555580054/) # ZYVOXID
product_xml.should_not match(/ZYVOXID/i)
doc = REXML::Document.new File.new article_filename
dscrds = XPath.match( doc, "//DSCRD" )
dscrds.find_all{|x| x.text.match('ZYVOXID Filmtabl 600 mg') }.size.should == 1
end
end
end
end

14 changes: 14 additions & 0 deletions spec/data/swissindex_pharma.xml
Expand Up @@ -33,6 +33,20 @@
<GLN>7601001320451</GLN>
</COMP>
</ITEM>
<ITEM DT="2013-06-22T00:00:00">
<GTIN>7680555580054</GTIN>
<PHAR>2465312</PHAR>
<STATUS>A</STATUS>
<STDATE>2002-01-16T00:00:00</STDATE>
<LANG>DE</LANG>
<DSCR>ZYVOXID Filmtabl 600 mg</DSCR>
<ADDSCR>10 Stk</ADDSCR>
<ATC>J01XX08</ATC>
<COMP>
<NAME>Pfizer AG</NAME>
<GLN>7601001010604</GLN>
</COMP>
</ITEM>
<RESULT>
<OK_ERROR>OK</OK_ERROR>
<NBR_RECORD>2</NBR_RECORD>
Expand Down
1 change: 1 addition & 0 deletions spec/data/zurrose_transfer.dat
@@ -1,3 +1,4 @@
1122465312ZYVOXID Filmtabl 600 mg 10 Stk 096114108275100A080190076805555800542
1120020209ERYTRHOCIN I.V. Trockensub Fl 1g 001518002010300B080160000000000000002
1120020244FERRO-GRADUMET Depottabl 30 Stk 000895001090300C060710076803164401152
1120020273KENDURAL Depottabl 30 Stk 000492000840100C060710076803536601632
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Expand Up @@ -26,6 +26,7 @@ def setup_server_mocks
setup_lppv_server_mock
setup_migel_server_mock
setup_medregbm_server_mock
setup_zurrose_server_mock
end
def setup_bag_xml_server_mock
# zip
Expand Down

0 comments on commit db9a1a2

Please sign in to comment.