From d95b0995b3208072d7d0a596c548d1d4d19a69c8 Mon Sep 17 00:00:00 2001 From: Niklaus Giger Date: Wed, 6 Aug 2014 12:40:04 +0200 Subject: [PATCH] Removed usage of persistent_user_input(:drugs). Added test for fachinfo_search Signed-off-by: Niklaus Giger --- spec/fachinfo_search_spec.rb | 86 +++++++++++++++++++++++++++ spec/rezept_and_instantsearch_spec.rb | 14 +++-- src/state/drugs/fachinfo_search.rb | 32 +++------- src/state/drugs/prescription.rb | 51 +++------------- src/state/global.rb | 1 - src/state/interactions/interaction_chooser.rb | 8 ++- src/util/session.rb | 13 ++++ src/view/drugs/fachinfo_search.rb | 8 +-- src/view/drugs/prescription.rb | 28 +++++---- src/view/interactions/interaction_chooser.rb | 12 ++-- src/view/searchbar.rb | 3 +- test/test_util/session.rb | 29 ++++++++- 12 files changed, 186 insertions(+), 99 deletions(-) create mode 100644 spec/fachinfo_search_spec.rb diff --git a/spec/fachinfo_search_spec.rb b/spec/fachinfo_search_spec.rb new file mode 100644 index 0000000..1fda478 --- /dev/null +++ b/spec/fachinfo_search_spec.rb @@ -0,0 +1,86 @@ +#!/usr/bin/env ruby +# encoding: utf-8 +# kate: space-indent on; indent-width 2; mixedindent off; indent-mode ruby; +require 'spec_helper' +require 'pp' +require 'tmpdir' +require "selenium-webdriver" + +describe "ch.oddb.org" do + + def enter_search_to_field_by_name(search_text, field_name) + idx = -2 + chooser = @browser.text_field(:name,field_name) + 0.upto(5).each{ + |idx| + break if chooser and chooser.present? + sleep 1 + chooser = @browser.text_field(:name,field_name) + } + unless chooser and chooser.present? + msg = "idx #{idx} could not find textfield prescription_searchbar in #{@browser.url}" + puts msg + # require 'pry'; binding.pry + raise msg + end + 0.upto(30).each{ |idx| + begin + chooser.set(search_text) + sleep idx*0.1 + chooser.send_keys(:down) + sleep idx*0.1 + chooser.send_keys(:enter) + sleep idx*0.1 + value = chooser.value + break unless /#{search_text}/.match(value) + sleep 0.5 + rescue StandardError => e + puts "in rescue" + createScreenshot(@browser, "rescue_#{search_text}_#{__LINE__}") + puts e.inspect + puts caller[0..5] + return + end + } + chooser.set(chooser.value + "\n") + puts "chooser set to #{chooser.value}" + createScreenshot(@browser, "_#{search_text}_#{__LINE__}") + end + + before :all do + $prescription_test_id = 1 + waitForOddbToBeReady(@browser, OddbUrl) + login + end + + before :each do + @timestamp = Time.now.strftime('%Y%m%d%H%M%S') + # puts "before #{$prescription_test_id} with #{@browser.windows.size} windows" + while @browser.windows.size > 1 + @browser.windows.first.use + @browser.windows.last.close if @browser.windows.last + end + @browser.goto OddbUrl + if @browser.link(:name=>'fachinfo_search').exists? + puts "Going to search FI erweitert" + @browser.link(:name=>'fachinfo_search').click + end + end + + after :each do + createScreenshot(@browser, '_'+$prescription_test_id.to_s) if @browser + $prescription_test_id += 1 + end + + + it "should show the chapter unwanted effects for Schwindel and show 61374 Quetiapin Sandoz:" do + @browser.select_list(:name, "fachinfo_search_type").select(/Unerw.Wirk/i) + # require 'pry'; binding.pry + @browser.checkbox(:name,'fachinfo_search_full_text').set + @browser.text_field(:name,'fachinfo_search_term').set('Gewichtszunahme') + enter_search_to_field_by_name('Quetiapin Sandoz', 'searchbar'); + @browser.button(:name, "search").click + @browser.text.should match /Sehr häufig: Gewichtszunahme/ + end + +end \ No newline at end of file diff --git a/spec/rezept_and_instantsearch_spec.rb b/spec/rezept_and_instantsearch_spec.rb index 5dbcc5c..2f5dd06 100644 --- a/spec/rezept_and_instantsearch_spec.rb +++ b/spec/rezept_and_instantsearch_spec.rb @@ -8,7 +8,8 @@ require "selenium-webdriver" describe "ch.oddb.org" do Four_Medis = [ 'Losartan', 'Nolvadex', 'Paroxetin', 'Aspirin'] - + QrCodeError = /Error generating QRCode/i + def add_one_drug_to_rezept(name) idx = -2 chooser = @browser.text_field(:id, 'prescription_searchbar') @@ -98,7 +99,7 @@ describe "ch.oddb.org" do def checkGeneralInfo(nrMedis=0) if @browser.url.index('/print/rezept/') inhalt = @browser.text - inhalt.should_not match /Error generating QRCode/i + inhalt.should_not match QrCodeError [FirstName, FamilyName, Birthday, " m\n"].each { |what| if inhalt.index(what).class == NilClass @@ -145,7 +146,7 @@ describe "ch.oddb.org" do # puts "waitForPrintInfo finished after #{(Time.now - startTime).to_i} seconds. size is #{@browser.text.size}" sleep(1) end -if false + it "should print the fachinfo when opening the fachinfo from a prescription" do @browser.select_list(:name, "search_type").select("Markenname") @browser.text_field(:name, "search_query").set(Four_Medis.first) @@ -173,7 +174,7 @@ if false @browser.windows.last.use waitForPrintInfo inhalt = @browser.text - inhalt.should_not match /Error generating QRCode/i + inhalt.should_not match QrCodeError inhalt.should_not match /Bemerkungen/ inhalt.should match(/Ausdruck/i) ['Ausdruck', @@ -357,7 +358,7 @@ if false inhalt.should match(/Zusammensetzung/i) inhalt.should match(/Filmtabletten/i) end -end + # this tests takes (at the moment) over 2,5 minutes it "should be possible to print a presciption with 10 drugs" do startTime = Time.now @@ -383,8 +384,9 @@ end waitForPrintInfo showElapsedTime(startTime, "Printing a prescription with #{nrDrugs} drugs") inhalt = @browser.text.clone - checkGeneralInfo(nrRemarks) + inhalt.should_not match QrCodeError inhalt.scan(/\nBemerkungen\n/).size.should == nrRemarks inhalt.scan(/\nInteraktionen\n/).size.should == 2 + checkGeneralInfo(nrRemarks) end end \ No newline at end of file diff --git a/src/state/drugs/fachinfo_search.rb b/src/state/drugs/fachinfo_search.rb index 4afdb0c..6f70d0e 100644 --- a/src/state/drugs/fachinfo_search.rb +++ b/src/state/drugs/fachinfo_search.rb @@ -19,38 +19,22 @@ class FachinfoSearch < State::Drugs::Global VIEW = View::Drugs::FachinfoSearch @@ean13_form = /^(7680)(\d{5})(\d{3})(\d)$/u def init - if @session.event.to_sym == self.class::DIRECT_EVENT and - drugs = @session.persistent_user_input(:drugs) # init - @session.set_persistent_user_input(:drugs, {}) - end + $stdout.puts "FachinfoSearch #{@session.event.to_sym == self.class::DIRECT_EVENT} drugs #{@session.persistent_user_input(:drugs)}" super end def ajax_add_drug + $stdout.puts "FachinfoSearch.ajax_add_drug #{@session.user_input(:ean)}" check_model - unless error? - if ean13 = @session.user_input(:ean).to_s and - pack = package_for(ean13) - drugs = @session.persistent_user_input(:drugs) || {} - drugs[ean13] = pack unless drugs.has_key?(ean13) - @session.set_persistent_user_input(:drugs, drugs) - end - end FachinfoSearchDrug.new(@session, @model) end def ajax_delete_drug + $stdout.puts "FachinfoSearch.ajax_delete_drug #{@session.user_input(:ean)}" check_model - unless error? - if ean13 = @session.user_input(:ean).to_s - drugs = @session.persistent_user_input(:drugs) || {} - drugs.delete(ean13) - @session.set_persistent_user_input(:drugs, drugs) - end - end FachinfoSearchDrug.new(@session, @model) end def delete_all + $stdout.puts "FachinfoSearch.delete_all request_path #{@session.request_path}" unless error? - @session.set_persistent_user_input(:drugs, {}) @model = [] end self.http_headers = { @@ -85,14 +69,14 @@ class FachinfoSearch < State::Drugs::Global end end def match_term + puts "fachinfo_search.match_term #{@session.request_path} drugsFromUrl: #{@session.drugsFromUrl}" hits = [] - if ean13s = @session.persistent_user_input(:drugs) and - ean13s.is_a? Hash + if @session.drugsFromUrl chapter = @session.user_input(:fachinfo_search_type).to_s.gsub(/^fi_/, '').intern term = @session.user_input(:fachinfo_search_term) is_full = (@session.user_input(:fachinfo_search_full_text) == "1") - ean13s.keys.each do |ean13| - pac = package_for(ean13) + drugsFromUrl.each do |ean13, pac| + $stdout.puts "match_term #{ean13} #{pac}" doc = pac.fachinfo.description(@session.language) if doc.respond_to?(chapter) desc = doc.send(chapter).to_s diff --git a/src/state/drugs/prescription.rb b/src/state/drugs/prescription.rb index 0d0912e..644924a 100644 --- a/src/state/drugs/prescription.rb +++ b/src/state/drugs/prescription.rb @@ -23,46 +23,16 @@ class Prescription < State::Drugs::Global DIRECT_EVENT = :rezept VIEW = View::Drugs::Prescription @@ean13_form = /^(7680)(\d{5})(\d{3})(\d)$/u - def handle_drug_changes(drugs, msg) - path = @session.request_path - @session.set_persistent_user_input(:drugs, drugs) - uri = @session.lookandfeel._event_url(:rezept, []) - first = true - drugs.each{|ean, pack| - if first - first = false - uri += pack.barcode - else - uri += ",#{pack.barcode}" - end - } - end def init + @drugs = @session.drugsFromUrl ean13 = @session.user_input(:search_query) - path = @session.request_path.sub(/(\?|)$/, '') - uri = @session.lookandfeel._event_url(:rezept, []) - search_code = path.split('rezept/ean/')[1] - drugs = {} - if search_code - items = search_code.split(',') - items.each{ - |item| - if item.kind_of?(String) and item.length == 13 - next unless item - pack = package_for(item) - next unless pack - drugs[item] = pack - end - } - handle_drug_changes(drugs, 'init') - else - @session.set_persistent_user_input(:drugs, {}) - end + @drugs[ean13] = package_for(ean13) if ean13 + $stdout.puts "Prescription:init url are #{@drugs} ean13 #{ean13.inspect}" super end def delete_all + $stdout.puts "Prescription:delete_all request_path is #{@session.request_path} -> #{@session.request_path.split('/ean/')[0]} or #{@session.lookandfeel._event_url(:home_interactions, [])}" unless error? - handle_drug_changes({}, 'delete_all') @model = [] end self.http_headers = { @@ -75,24 +45,21 @@ class Prescription < State::Drugs::Global PrescriptionCsvExport.new(@session, @model) end def ajax_add_drug(ean13 = @session.user_input(:ean)) + $stdout.puts "Prescription.ajax_add_drug #{ean13}" check_model(ean13) unless error? - if ean13 and pack = package_for(ean13) - drugs = @session.persistent_user_input(:drugs) || {} - drugs[ean13] = pack unless drugs.has_key?(ean13) - handle_drug_changes(drugs, 'ajax_add_drug') - end + @drugs[ean13] = package_for(ean13) if ean13 end AjaxDrug.new(@session, @model) end def ajax_delete_drug(ean13 = @session.user_input(:ean)) + $stdout.puts "Prescription.ajax_delete_drug #{ean13}" check_model unless error? if ean13 and pack = package_for(ean13) - drugs = @session.persistent_user_input(:drugs) || {} - drugs.delete(ean13) - return handle_drug_changes(drugs, 'ajax_delete_drug') + @drugs.delete(ean13) + return end end AjaxEmpty.new(@session, @model) diff --git a/src/state/global.rb b/src/state/global.rb index 6cd4e22..9746327 100644 --- a/src/state/global.rb +++ b/src/state/global.rb @@ -518,7 +518,6 @@ module ODDB end def print state = self.search - drugs = @session.persistent_user_input(:drugs) if @session.request_path.index("/print/rezept/") State::Drugs::PrescriptionPrint.new(@session, nil) elsif @session.user_input(:pointer) diff --git a/src/state/interactions/interaction_chooser.rb b/src/state/interactions/interaction_chooser.rb index 799c720..faee0f6 100644 --- a/src/state/interactions/interaction_chooser.rb +++ b/src/state/interactions/interaction_chooser.rb @@ -20,6 +20,7 @@ class InteractionChooser < State::Interactions::Global @@ean13_form = /^(7680)(\d{5})(\d{3})(\d)$/u def handle_drug_changes(drugs, msg) + $stdout.puts "handle_drug_changes #{drugs}" path = @session.request_path @session.set_persistent_user_input(:drugs, drugs) uri = @session.lookandfeel._event_url(:home_interactions, []) @@ -71,11 +72,12 @@ class InteractionChooser < State::Interactions::Global super end def ajax_add_drug + $stdout.puts "InteractionChooser.ajax_add_drug #{@session.user_input(:ean)}" check_model unless error? if ean13 = @session.user_input(:ean).to_s and pack = package_for(ean13) - drugs = @session.persistent_user_input(:drugs) || {} + drugs = @session.drugsFromUrl drugs[ean13] = pack unless drugs.has_key?(ean13) return handle_drug_changes(drugs, 'ajax_add_drug') end @@ -83,10 +85,11 @@ class InteractionChooser < State::Interactions::Global InteractionChooserDrug.new(@session, @model) end def ajax_delete_drug + $stdout.puts "InteractionChooser.ajax_delete_drug #{@session.user_input(:ean)}" check_model unless error? if ean13 = @session.user_input(:ean).to_s - drugs = @session.persistent_user_input(:drugs) || {} + drugs = @session.drugsFromUrl drugs.delete(ean13) return handle_drug_changes(drugs, 'ajax_delete_drug') end @@ -94,6 +97,7 @@ class InteractionChooser < State::Interactions::Global InteractionChooserDrug.new(@session, @model) end def delete_all + $stdout.puts "InteractionChooser.delete_all #{@session.user_input(:ean)} request_path #{@session.request_path}" unless error? handle_drug_changes({}, 'delete_all') @model = [] diff --git a/src/util/session.rb b/src/util/session.rb index 422630c..ed38d73 100644 --- a/src/util/session.rb +++ b/src/util/session.rb @@ -230,5 +230,18 @@ module ODDB def sponsor @app.sponsor(flavor) end + def drugsFromUrl + m = /\/(ean|home_interactions)\/+([^\\?].+)/.match(request_path) + return {} unless m + ean13s = m[2].split(/[,?\/]/) + drugs = {} + ean13s.each { + |ean13| + pack = @app.package_by_ean13(ean13) + drugs[ean13] = pack if pack + } + # $stdout.puts "drugsFromUrl for #{request_path} returns #{drugs}" + drugs + end end end diff --git a/src/view/drugs/fachinfo_search.rb b/src/view/drugs/fachinfo_search.rb index 6665b45..1ca6b05 100644 --- a/src/view/drugs/fachinfo_search.rb +++ b/src/view/drugs/fachinfo_search.rb @@ -29,7 +29,7 @@ class FachinfoSearchDrugHeader < HtmlGrid::Composite [2,0] => 'small', } def init - @drugs = @session.persistent_user_input(:drugs) + @drugs = @session.drugsFromUrl @index = (@drugs ? @drugs.length : 0).to_s super end @@ -99,7 +99,7 @@ class FachinfoSearchDrugDiv < HtmlGrid::Div def init super @value = [] - @drugs = @session.persistent_user_input(:drugs) + @drugs = @session.drugsFromUrl if @drugs and !@drugs.empty? @drugs.values.each do |pac| @value << FachinfoSearchDrug.new(pac, @session, self) @@ -242,7 +242,7 @@ class FachinfoSearchTermHitList < HtmlGrid::List BACKGROUND_SUFFIX = '' LEGACY_INTERFACE = false def drug(model, session=@session) - drugs = @session.persistent_user_input(:drugs) + drugs = @session.drugsFromUrl if pac = drugs[model[:ean13]] FachinfoSearchDrugHeader.new(pac, session, self) end @@ -344,7 +344,7 @@ class FachinfoSearchCsv < HtmlGrid::Component 'Search Match', ], ] - drugs = @session.persistent_user_input(:drugs) + drugs = @session.drugsFromUrl @model.each do |model| if pac = drugs[model[:ean13]] if model[:text].is_a? FachinfoDocument diff --git a/src/view/drugs/prescription.rb b/src/view/drugs/prescription.rb index 8fbd2a6..8fe36c8 100644 --- a/src/view/drugs/prescription.rb +++ b/src/view/drugs/prescription.rb @@ -53,7 +53,7 @@ class PrescriptionInteractionDrugDiv < HtmlGrid::Div def init super @value = [] - @drugs = @session.persistent_user_input(:drugs) + @drugs = @session.drugsFromUrl if @drugs and !@drugs.empty? @value << View::Interactions::InteractionChooserDrug.new(@model, @session, self) end @@ -73,7 +73,7 @@ class PrescriptionDrugHeader < HtmlGrid::Composite [2,0] => 'small', } def init - @drugs = @session.persistent_user_input(:drugs) + @drugs = @session.drugsFromUrl if @model and @model.barcode and @model.barcode.length == 13 @index = @drugs.keys.index(@model.barcode) else @@ -156,7 +156,7 @@ class PrescriptionDrug < HtmlGrid::Composite } CSS_CLASS = 'composite' def init - @drugs = @session.persistent_user_input(:drugs) + @drugs = @session.drugsFromUrl @index = -1 if @model and @drugs and !@drugs.empty? @index = @drugs.keys.index(@model.barcode) @@ -192,7 +192,7 @@ class PrescriptionDrug < HtmlGrid::Composite end class PrescriptionDrugDiv < HtmlGrid::Div def init - @drugs = @session.persistent_user_input(:drugs) + @drugs = @session.drugsFromUrl super # must come first or it will overwrite @value @value = [] ODDB::View::Interactions.calculate_atc_codes(@drugs) @@ -321,7 +321,7 @@ class PrescriptionForm < View::Form def buttons(model, session) buttons = [] print = post_event_button(:print) - drugs = @session.persistent_user_input(:drugs) + drugs = @session.drugsFromUrl new_url = @lookandfeel._event_url(:print, [:rezept, :ean, drugs.keys].flatten) print.onclick = "window.open('#{new_url}');" @@ -332,7 +332,7 @@ class PrescriptionForm < View::Form buttons end def delete_all(model, session=@session) - @drugs = @session.persistent_user_input(:drugs) + @drugs = @session.drugsFromUrl delete_all_link = HtmlGrid::Link.new(:delete, @model, @session, self) delete_all_link.href = @lookandfeel._event_url(:rezept, [:ean] ) delete_all_link.value = @lookandfeel.lookup(:interaction_chooser_delete_all) @@ -388,12 +388,14 @@ class PrescriptionPrintInnerComposite < HtmlGrid::Composite CSS_CLASS = 'compose' DEFAULT_CLASS = HtmlGrid::Value def init - @drugs = @session.persistent_user_input(:drugs) - @index = -1 + @drugs = @session.drugsFromUrl + @index = nil + # /de/gcc/print/rezept/ean/7680516801112/7680576730063 if @model and @drugs and !@drugs.empty? @index = @drugs.keys.index(@model.barcode) end - if @drugs and !@drugs.empty? + $stdout.puts "PrescriptionPrintInnerComposite #{@session.request_path} #{@drugs} index #{@index.inspect}" + if @index and @drugs and !@drugs.empty? @model = @drugs.values[@index] end @prescription_comment = @lookandfeel.lookup(:prescription_comment) @@ -472,7 +474,7 @@ class PrescriptionPrintComposite < HtmlGrid::DivComposite [0,10] => 'print-big', } def init - @drugs = @session.persistent_user_input(:drugs) + @drugs = @session.drugsFromUrl super self.onload = %(require(["dojo/domReady!"], function(){ print_composite_init('#{@lookandfeel.lookup(:prescription_comment)}'); @@ -541,7 +543,7 @@ class PrescriptionPrint < View:: PrintTemplate CONTENT = View::Drugs::PrescriptionPrintComposite JAVASCRIPTS = ['qrcode', 'prescription'] def init - @drugs = @session.persistent_user_input(:drugs) + @drugs = @session.drugsFromUrl @index = (@drugs ? @drugs.length : 0).to_s if @model and @drugs and !@drugs.empty? @index = @drugs.keys.index(@model.barcode).to_s @@ -550,7 +552,7 @@ class PrescriptionPrint < View:: PrintTemplate end def head(model, session=@session) span = HtmlGrid::Span.new(model, session, self) - drugs = @session.persistent_user_input(:drugs) + drugs = @session.drugsFromUrl span.value = @lookandfeel.lookup(:print_of) + @lookandfeel._event_url(:print, [:rezept, :ean, drugs ? drugs.keys : [] ].flatten) span @@ -621,7 +623,7 @@ class PrescriptionCsv < HtmlGrid::Component insert_blank @lines << date insert_blank - if drugs = @session.persistent_user_input(:drugs) + if drugs = @session.drugsFromUrl @packages = drugs.values.unshift(model) else @packages = [model] diff --git a/src/view/interactions/interaction_chooser.rb b/src/view/interactions/interaction_chooser.rb index 6b308fc..73488eb 100644 --- a/src/view/interactions/interaction_chooser.rb +++ b/src/view/interactions/interaction_chooser.rb @@ -142,7 +142,7 @@ class InteractionChooserDrugHeader < HtmlGrid::Composite if model args = [:ean, model.barcode] if model url = @session.request_path.sub(model.barcode.to_s, '').sub('/,', '/').sub(/,$/, '') - if @session.persistent_user_input(:drugs).size == 0 + if @session.drugsFromUrl.size == 0 ODDB::View::Interactions.calculate_atc_codes({}) end link.onclick = %( @@ -177,7 +177,7 @@ class InteractionChooserDrug < HtmlGrid::Composite @interactions = ODDB::View::Interactions.get_interactions(model.atc_class.code, @session) ean13 = @session.user_input(:search_query) path = @session.request_path - @drugs = @session.persistent_user_input(:drugs) + @drugs = @session.drugsFromUrl if @model.is_a? ODDB::Package nextRow = 0 unless @hide_interaction_headers @@ -259,7 +259,7 @@ class InteractionChooserDrugList < HtmlGrid::List CSS_CLASS = 'composite' SORT_HEADER = false def initialize(model, session=@session, arg_self=nil) - @drugs = session.persistent_user_input(:drugs) + @drugs = session.drugsFromUrl super # must come first or it will overwrite @value @value = [] ODDB::View::Interactions.calculate_atc_codes(@drugs) @@ -275,7 +275,7 @@ class InteractionChooserDrugDiv < HtmlGrid::Div def init super @value = [] - @drugs = @session.persistent_user_input(:drugs) + @drugs = @session.drugsFromUrl if @drugs and !@drugs.empty? @value << InteractionChooserDrugList.new(@drugs, @session, self) end @@ -406,6 +406,7 @@ class InteractionChooserForm < View::Form LABELS = true private def init + $stdout.puts "InteractionChooserForm.init #{@session.request_path}" super self.onload = %(require(["dojo/domReady!"], function(){ if (document.getElementById('interaction_searchbar') != null) document.getElementById('interaction_searchbar').focus(); @@ -423,7 +424,8 @@ class InteractionChooserForm < View::Form link end def delete_all(model, session=@session) - @drugs = @session.persistent_user_input(:drugs) + $stdout.puts "InteractionChooserForm.delete_all #{@session.request_path}" + @drugs = @session.drugsFromUrl if @drugs and !@drugs.empty? delete_all_link = HtmlGrid::Link.new(:delete, @model, @session, self) delete_all_link.href = @lookandfeel._event_url(:delete_all, []) diff --git a/src/view/searchbar.rb b/src/view/searchbar.rb index 0f0ef60..d197e39 100644 --- a/src/view/searchbar.rb +++ b/src/view/searchbar.rb @@ -55,9 +55,10 @@ module InstantSearchBarMethods def xhr_request_init(keyword) target = keyword.intern id = "#{target}_searchbar" - drugs = @session.persistent_user_input(:drugs) + drugs = @session.drugsFromUrl drugs = drugs.keys if drugs ean13 = @session.persistent_user_input(:ean) + $stdout.puts "InstantSearchBarMethods #{@session.request_path}: #{drugs} ean13 #{ean13}" base_url = @lookandfeel.base_url splitted = @session.request_path.split(/#{base_url}\/(home_interactions|rezept\/ean)\/*/) url = @lookandfeel._event_url(target == 'prescription' ? 'rezept/ean' : 'home_interactions', []) diff --git a/test/test_util/session.rb b/test/test_util/session.rb index 7e8bdca..aa88b5e 100644 --- a/test/test_util/session.rb +++ b/test/test_util/session.rb @@ -22,7 +22,8 @@ module ODDB @app = flexmock('app', :unknown_user => @unknown_user, :sorted_fachinfos => [], - :sorted_feedbacks => []) + :sorted_feedbacks => [], + :package_by_ean13 => 'package',) @validator = flexmock('validator', :reset_errors => 'reset_errors', :validate => 'validate') @@ -196,5 +197,31 @@ module ODDB assert_equal({}, ODDB::Session.reset_query_limit) assert_equal(nil, ODDB::Session.reset_query_limit('ip')) end + ThreePackages = { '7680576730049' => 'package', + '7680193950301' => 'package', + '7680353520153' => 'package'} + UrlForThreePackages = '7680576730049,7680193950301,7680353520153' + def test_drugsFromUrl_for_home_interaction + @session = ODDB::Session.new('key', @app, @validator) + @session.instance_eval("@request_path = '/de/gcc/home_interactions/#{UrlForThreePackages}'") + assert_equal(ThreePackages, @session.drugsFromUrl) + end + def test_drugsFromUrl_for_rezept + @session = ODDB::Session.new('key', @app, @validator) + @session.instance_eval("@request_path = '/de/gcc/rezept/ean/#{UrlForThreePackages}'") + assert_equal(ThreePackages, @session.drugsFromUrl) + end + def test_drugsFromUrl_for_rezept_print + @session = ODDB::Session.new('key', @app, @validator) + @session.instance_eval("@request_path = '/de/gcc/print/rezept/ean/#{UrlForThreePackages}'") + assert_equal(ThreePackages, @session.drugsFromUrl) + @session.instance_eval("@request_path = '/de/gcc/print/rezept/ean/#{UrlForThreePackages}?'") + assert_equal(ThreePackages, @session.drugsFromUrl) + end + def test_drugsFromUrl_for_rezept_print_with_slashes + @session = ODDB::Session.new('key', @app, @validator) + @session.instance_eval("@request_path = '/de/gcc/print/rezept/ean/#{UrlForThreePackages.gsub(',','/')}'") + assert_equal(ThreePackages, @session.drugsFromUrl) + end end end # ODDB -- 2.0.1