require 'rails_helper'

RSpec.describe CsvTransformer do

  describe '#transform' do
    context 'with good data' do
      context 'headers in csv' do
        # Return a File.read string just like the CsvDownloader class does:
        let!(:file) { File.read("#{Rails.root}/spec/fixtures/fake_behavior_export.txt") }

        let(:transformer) { CsvTransformer.new }
        let(:output) { transformer.transform(file) }
        it 'returns a CSV' do
          expect(output).to be_a_kind_of CSV::Table
        end
        it 'has the correct headers' do
          expect(output.headers).to match_array([
            :event_date, :incident_code, :incident_description, :incident_location, :incident_time, :local_id, :school_local_id
          ])
        end
      end
    end
  end
end

require 'rails_helper'

RSpec.describe CsvTransformer do

  describe '#transform' do
    context 'with good data' do
      context 'headers in csv' do
        # Return a File.read string just like the CsvDownloader class does:
        let!(:file) { File.read("#{Rails.root}/spec/fixtures/fake_behavior_export.txt") }

        let(:transformer) { CsvTransformer.new }
        let(:output) { transformer.transform(file) }
        it 'returns a CSV' do
          expect(output).to be_a_kind_of CSV::Table
        end
        it 'has the correct headers' do
          expect(output.headers).to match_array([
            :event_date, :incident_code, :incident_description, :incident_location, :incident_time, :local_id, :school_local_id
          ])
        end
      end
      context 'headers not in csv' do
        # Return a File.read string just like the CsvDownloader class does:
        let!(:file) { File.read("#{Rails.root}/spec/fixtures/fake_no_headers.csv") }

        let(:headers) {["section_number","student_local_id","school_local_id","course_number","term_local_id","grade"]}
        let(:headers_symbols) {[:section_number,:student_local_id,:school_local_id,:course_number,:term_local_id,:grade]}
        let(:transformer) { CsvTransformer.new(headers:headers) }
        let(:output) { transformer.transform(file) }
        it 'returns a CSV' do
          expect(output).to be_a_kind_of CSV::Table
        end
        it 'has the correct headers' do
          expect(output.headers).to match_array(headers_symbols)
        end
      end
    end
  end
end

Revert "Remove spec for scenario that doesn't exist in the project (no headers in CSV export file)"
Revert "Remove spec for scenario that doesn't exist in the project (no headers in CSV export file)"

This reverts commit d2c16d9d8bf849a459900e6bc6e4b6b1a3fd27a8.
