require 'csv'

CSV::Converters[:boolean] = lambda do |value|
  case value.to_s
  when 'true' then true
  when 'false' then false
  else value
  end
end

module UploadedCSVMatcher
  def read_uploaded_csv
    path = FakeSFTP.find_path('*.csv')
    contents = path ? FakeSFTP.read(path) : ''

    CSV.parse(contents, headers: true, converters: [:numeric, :date_time, :boolean],
                        header_converters: :symbol, col_sep: '|')
  end

  def expect_uploaded_csv_to_include(expected)
    rows = read_uploaded_csv
    expect(rows.count).to eq(1), "Expected 1 row, but #{rows.count} rows were found."
    expect(rows.first.to_hash).to include(expected)
  end
end

World(UploadedCSVMatcher)

require 'csv'

CSV::Converters[:boolean] = lambda do |value|
  case value.to_s
  when 'true' then true
  when 'false' then false
  else value
  end
end

module UploadedCSVMatcher
  def read_uploaded_csv
    path = FakeSFTP.find_path('*.csv')
    contents = path ? FakeSFTP.read(path) : ''

    CSV.parse(contents, headers: true, converters: [:date_time, :boolean],
                        header_converters: :symbol, col_sep: '|')
  end

  def expect_uploaded_csv_to_include(expected)
    rows = read_uploaded_csv
    expect(rows.count).to eq(1), "Expected 1 row, but #{rows.count} rows were found."
    expect(rows.first.to_hash).to include(expected)
  end
end

World(UploadedCSVMatcher)

Remove number parsing from FakeCSV reader
Remove number parsing from FakeCSV reader

An appointment type of `50_54` was being coerced as a number
and resulting in `5054`. As we no longer have any numbers in the
CSV, we it is no longer required.
