<commit_before># encoding: UTF-8

Given(/^at det finnes en materialtype for "(.*?)" med kode "(.*?)"$/) do |name, code|
  step "jeg legger til en materialtype \"#{name}\" med kode \"#{code}\""
end

Given(/^at det finnes en bok$/) do
  step "jeg legger til en materialtype \"Bok\" med kode \"L\""
  step "at det finnes en avdeling"
  step "jeg legger inn \"Fargelegg byen!\" som ny bok"
end

Given(/^at "Fargelegg byen!" er ei bok som finnes i biblioteket$/) do
  step "jeg legger til en materialtype \"Bok\" med kode \"L\""
  step "at det finnes en avdeling"
  step "jeg legger inn \"Fargelegg byen!\" som ny bok"
end

When(/^jeg legger inn "(.*?)" som ny bok$/) do |book|
  @http = Net::HTTP.new(host, 8081)
  res = @http.get("/cgi-bin/koha/svc/authentication?userid=#{SETTINGS['koha']['adminuser']}&password=#{SETTINGS['<PASSWORD>']['<PASSWORD>']}")
  res.body.should_not include("failed")
  @context[:svc_cookie] = res.response['set-cookie']
  data = File.read("features/upload-files/#{book}.normarc")
  headers = {
    'Cookie' => @context[:svc_cookie],
    'Content-Type' => 'text/xml'
  }
  res, data = @http.post("/cgi-bin/koha/svc/new_bib?items=1&import_mode=direct", data, headers)
  res.body.should include("<status>ok</status>")
  @context[:book_id] = res.body.match(/<biblionumber>(\d+)<\/biblionumber>/)[1]
  # force rebuild zebra bibliographic index
  `ssh -i ~/.ssh/insecure_private_key vagrant@192.168.50.10 \
    -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no \
    'sudo koha-rebuild-zebra -v -b name' 2> /dev/null`
end

When(/^jeg legger til en materialtype "(.*?)" med kode "(.*?)"$/) do |name, code|
  @browser.goto intranet(:item_types)
  @browser.a(:id => "newitemtype").click
  form = @browser.form(:id => "itemtypeentry")
  form.text_field(:id => "itemtype").set code
  form.text_field(:id => "description").set name
  @context[:item_type_name] = name
  @context[:item_type_code] = code
  form.submit
end

Then(/^kan jeg se materialtypen i listen over materialtyper$/) do
  @browser.goto intranet(:item_types)
  table = @browser.table(:id => "table_item_type")
  table.should be_present
  table.text.should include(@context[:item_type_name])
  table.text.should include(@context[:item_type_code])
end

Then(/^viser systemet at "(.*?)" er en bok som kan lånes ut$/) do |book|
  @browser.goto "http://#{host}:8081/cgi-bin/koha/catalogue/detail.pl?biblionumber=#{@context[:book_id]}"
  @browser.div(:id => "catalogue_detail_biblio").text.should include(book)
  holdings = @browser.div(:id => "holdings")
  holdings.text.should include("Available")<commit_msg>Force restart of zebra after reindex.<commit_after># encoding: UTF-8

Given(/^at det finnes en materialtype for "(.*?)" med kode "(.*?)"$/) do |name, code|
  step "jeg legger til en materialtype \"#{name}\" med kode \"#{code}\""
end

Given(/^at det finnes en bok$/) do
  step "jeg legger til en materialtype \"Bok\" med kode \"L\""
  step "at det finnes en avdeling"
  step "jeg legger inn \"Fargelegg byen!\" som ny bok"
end

Given(/^at "Fargelegg byen!" er ei bok som finnes i biblioteket$/) do
  step "jeg legger til en materialtype \"Bok\" med kode \"L\""
  step "at det finnes en avdeling"
  step "jeg legger inn \"Fargelegg byen!\" som ny bok"
end

When(/^jeg legger inn "(.*?)" som ny bok$/) do |book|
  @http = Net::HTTP.new(host, 8081)
  res = @http.get("/cgi-bin/koha/svc/authentication?userid=#{SETTINGS['koha']['adminuser']}&password=#{SETTINGS['koha']['adminpass']}")
  res.body.should_not include("failed")
  @context[:svc_cookie] = res.response['set-cookie']
  data = File.read("features/upload-files/#{book}.normarc")
  headers = {
    'Cookie' => @context[:svc_cookie],
    'Content-Type' => 'text/xml'
  }
  res, data = @http.post("/cgi-bin/koha/svc/new_bib?items=1", data, headers)
  res.body.should include("<status>ok</status>")
  @context[:book_id] = res.body.match(/<biblionumber>(\d+)<\/biblionumber>/)[1]
  # force rebuild and restart zebra bibliographic index
  `ssh -i ~/.ssh/insecure_private_key vagrant@192.168.50.10 \
    -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no \
    'sudo koha-rebuild-zebra name -b -v \
    && sudo koha-stop-zebra name \
    && sudo koha-start-zebra name' > /dev/null 2>&1`
end

When(/^jeg legger til en materialtype "(.*?)" med kode "(.*?)"$/) do |name, code|
  @browser.goto intranet(:item_types)
  @browser.a(:id => "newitemtype").click
  form = @browser.form(:id => "itemtypeentry")
  form.text_field(:id => "itemtype").set code
  form.text_field(:id => "description").set name
  @context[:item_type_name] = name
  @context[:item_type_code] = code
  form.submit
end

Then(/^kan jeg se materialtypen i listen over materialtyper$/) do
  @browser.goto intranet(:item_types)
  table = @browser.table(:id => "table_item_type")
  table.should be_present
  table.text.should include(@context[:item_type_name])
  table.text.should include(@context[:item_type_code])
end

Then(/^viser systemet at "(.*?)" er en bok som kan lånes ut$/) do |book|
  @browser.goto "http://#{host}:8081/cgi-bin/koha/catalogue/detail.pl?biblionumber=#{@context[:book_id]}"
  @browser.div(:id => "catalogue_detail_biblio").text.should include(book)
  holdings = @browser.div(:id => "holdings")
  holdings.text.should include("Available")
{'fraction_non_alphanumeric': 0.18338706618623174, 'fraction_numerical': 0.008534041342689171, 'mean_word_length': 4.448347107438017, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '124147', 'n_tokens_mistral': 2032, 'n_tokens_neox': 1948, 'n_words': 452}