Sha256: e6d5c9beddca687430c47cf974fa8fcb6c83ed5b276f569c396e547b5d5ac7bd

Contents?: true

Size: 1.42 KB

Versions: 7

Compression:

Stored size: 1.42 KB

Contents

require 'helper'
require 'peddler/flat_file_parser'

class TestPeddlerFlatFileParser < MiniTest::Test
  def setup
    body = "Feed Processing Summary:\n\tNumber of records processed\t\t11006\n\tNumber of records successful\t\t11006\n\noriginal-record-number\tsku\terror-code\terror-type\terror-message\n1822\t85da472e-ba6c-11e3-95af-002590a74356\t5000\tWarning\tThe update for Sku '85da472e-ba6c-11e3-95af-002590a74356' was skipped because it is identical to the update in feed '9518995390'.\n"
    body.encode!('ASCII-8BIT')
    headers = { 'Content-Type' => 'application/octet-stream', 'Content-MD5' => 'SmZIMTs2mCO8u8QzR5LE7Q==' }
    res = OpenStruct.new(body: body, headers: headers)

    @parser = Peddler::FlatFileParser.new(res, 'ISO-8859-1')
  end

  def test_parses_data
    assert_kind_of CSV::Table, @parser.parse
  end

  def test_summarises
    refute_empty @parser.records_count
  end

  def test_validates
    assert @parser.valid?
  end

  def test_handles_reports_without_a_summary
    res = OpenStruct.new(body: "Foo\nBar\n")
    parser = Peddler::FlatFileParser.new(res, 'ISO-8859-1')

    refute_empty parser.content
  end

  def test_handles_japanese_flat_files
    body = "Foo\nこんにちは\n"
    body.encode!('SHIFT_JIS')
    body.force_encoding('ASCII-8BIT')
    res = OpenStruct.new(body: body)
    parser = Peddler::FlatFileParser.new(res, 'SHIFT_JIS')

    assert_equal 'こんにちは', parser.parse[0]['Foo']
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
peddler-0.17.1 test/unit/peddler/test_flat_file_parser.rb
peddler-0.17.0 test/unit/peddler/test_flat_file_parser.rb
peddler-0.16.0 test/unit/peddler/test_flat_file_parser.rb
peddler-0.15.0 test/unit/peddler/test_flat_file_parser.rb
peddler-0.14.0 test/unit/peddler/test_flat_file_parser.rb
peddler-0.13.0 test/unit/peddler/test_flat_file_parser.rb
peddler-0.12.7 test/unit/peddler/test_flat_file_parser.rb