<commit_before>require File.expand_path('../test_helper', __FILE__)

require 'rest'
require 'hpricot'

describe "AbnAmro::Internetkassa, when remote testing" do
  before do
    @valid_attributes = {
      :order_id => 123,
      :amount => 1000,
      :description => "HappyHardcore vol. 123 - the ballads"
    }
    @instance = AbnAmro::Internetkassa.new(@valid_attributes)
  end
  
  it "should have the right data to make a successful POST request" do
    response = post(AbnAmro::Internetkassa.service_url, @instance.data)
    response.should.be.success
    
    parse_response(response).should == {
      :beneficiary => 'Fingertips BV',
      :order_id =>    '123',
      :amount =>      '10.00 EUR'
    }
  end
  
  private
  
  def post(uri, values)
    body = values.map { |k,v| "#{k}=#{v.to_s.gsub(' ', '%20')}" }.join('&')
    REST.post(uri, body)
  end
  
  def parse_response(response)
    results = {}
    doc = Hpricot(response.body)
    
    (doc / '#ncol_ref' / 'tr').each do |row|
      cols = (row / 'td')
      
      key = case cols.first.inner_text
      when /Ordernummer/
        :order_id
      when /Totaalbedrag/
        :amount
      when /Begunstigde/
        :beneficiary
      end
      
      results[key] = cols.last.inner_text.strip
    end
    
    results
  end
end<commit_msg>Test that the optional TITLE value is send as well.<commit_after>require File.expand_path('../test_helper', __FILE__)

require 'rest'
require 'hpricot'

describe "AbnAmro::Internetkassa, when remote testing" do
  before do
    @instance = AbnAmro::Internetkassa.new(
      :order_id => 123,
      :amount => 1000,
      :description => "HappyHardcore vol. 123 - the ballads",
      :TITLE => 'HappyHardcore vol. 123 - the ballads'
    )
  end
  
  it "should have the right data to make a successful POST request" do
    response = post(AbnAmro::Internetkassa.service_url, @instance.data)
    response.should.be.success
    
    parse_response(response).should == {
      :beneficiary => '<NAME>',
      :order_id =>    '123',
      :amount =>      '10.00 EUR',
      :title =>       'HappyHardcore vol. 123 - the ballads'
    }
  end
  
  private
  
  def post(uri, values)
    body = values.map { |k,v| "#{k}=#{v.to_s.gsub(' ', '%20')}" }.join('&')
    REST.post(uri, body)
  end
  
  def parse_response(response)
    results = {}
    
    doc = Hpricot(response.body)
    (doc / '#ncol_ref' / 'tr').each do |row|
      cols = (row / 'td')
      
      key = case cols.first.inner_text
      when /Ordernummer/
        :order_id
      when /Totaalbedrag/
        :amount
      when /Begunstigde/
        :beneficiary
      end
      
      results[key] = cols.last.inner_text.strip
    end
    
    results[:title] = (doc / 'title').inner_text.strip
    results
  end
end
{'fraction_non_alphanumeric': 0.13173007896625988, 'fraction_numerical': 0.015793251974156496, 'mean_word_length': 2.3537906137184117, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '227063', 'n_tokens_mistral': 1030, 'n_tokens_neox': 959, 'n_words': 223}