<commit_before>require 'rails_helper'

describe CsvTransformer do
  describe 'transform' do
    context 'with no fields' do
      it 'returns an empty hash' do
        data = {
          email: '',
          location: '',
          latitude: '',
          longitude: '',
          organization_name: '',
          phone_number: '',
          tag_names: '',
          website: ''
        }
        raw_input = Fabricate :raw_input, data: data
        attrs = CsvTransformer.transform raw_input
        expect(attrs).to eq({})
      end
    end

    context 'with some fields' do
      it 'returns only those fields that are not empty' do
        data = {
          email: '<EMAIL>',
          organization_name: 'Best Gallery',
          phone_number: '1-800-123-4567',
          website: 'http://example.com'
        }
        raw_input = Fabricate :raw_input, data: data
        attrs = CsvTransformer.transform raw_input
        expected = {
          email: {
            content: data[:email]
          },
          organization_name: {
            content: data[:organization_name]
          },
          phone_number: {
            content: data[:phone_number]
          },
          website: {
            content: data[:website]
          }
        }
        expect(attrs).to eq(expected)
      end
    end

    context 'with all fields' do
      it 'returns attrs for an Organization' do
        data = {
          email: '<EMAIL>',
          location: '123 Main Street, New York, NY 10001',
          latitude: '47.5543105',
          longitude: '7.598538899999999',
          organization_name: 'Best Gallery',
          phone_number: '1-800-123-4567',
          tag_names: 'design,modern',
          website: 'http://example.com'
        }
        raw_input = Fabricate :raw_input, data: data
        attrs = CsvTransformer.transform raw_input
        expected = {
          email: {
            content: data[:email]
          },
          location: {
            content: data[:location],
            latitude: data[:latitude],
            longitude: data[:longitude]
          },
          organization_name: {
            content: data[:organization_name]
          },
          phone_number: {
            content: data[:phone_number]
          },
          tag_names: %w(design modern),
          website: {
            content: data[:website]
          }
        }
        expect(attrs).to eq(expected)
      end
    end
  end
end<commit_msg>Add a few more missing tests<commit_after>require 'rails_helper'

describe CsvTransformer do
  describe 'transform' do
    context 'with no fields' do
      it 'returns an empty hash' do
        data = {
          email: '',
          location: '',
          latitude: '',
          longitude: '',
          organization_name: '',
          phone_number: '',
          tag_names: '',
          website: ''
        }
        raw_input = Fabricate :raw_input, data: data
        attrs = CsvTransformer.transform raw_input
        expect(attrs).to eq({})
      end
    end

    context 'with partial fields' do
      it 'returns only those fields that are not empty' do
        data = {
          email: '<EMAIL>',
          organization_name: 'Best Gallery',
          phone_number: '1-800-123-4567',
          website: 'http://example.com'
        }
        raw_input = Fabricate :raw_input, data: data
        attrs = CsvTransformer.transform raw_input
        expected = {
          email: {
            content: data[:email]
          },
          organization_name: {
            content: data[:organization_name]
          },
          phone_number: {
            content: data[:phone_number]
          },
          website: {
            content: data[:website]
          }
        }
        expect(attrs).to eq(expected)
      end
    end

    context 'with sparse fields' do
      it 'returns only those fields that are not empty' do
        data = {
          email: '',
          location: '123 Main Street, New York, NY 10001',
          latitude: '47.5543105',
          longitude: '7.598538899999999',
          organization_name: '',
          phone_number: '',
          tag_names: '',
          website: 'http://example.com'
        }
        raw_input = Fabricate :raw_input, data: data
        attrs = CsvTransformer.transform raw_input
        expected = {
          location: {
            content: data[:location],
            latitude: data[:latitude],
            longitude: data[:longitude]
          },
          website: {
            content: data[:website]
          }
        }
        expect(attrs).to eq(expected)
      end
    end

    context 'with complete fields' do
      it "returns all attrs for an Organization and it's relationships" do
        data = {
          email: '<EMAIL>',
          location: '123 Main Street, New York, NY 10001',
          latitude: '47.5543105',
          longitude: '7.598538899999999',
          organization_name: 'Best Gallery',
          phone_number: '1-800-123-4567',
          tag_names: 'design,modern',
          website: 'http://example.com'
        }
        raw_input = Fabricate :raw_input, data: data
        attrs = CsvTransformer.transform raw_input
        expected = {
          email: {
            content: data[:email]
          },
          location: {
            content: data[:location],
            latitude: data[:latitude],
            longitude: data[:longitude]
          },
          organization_name: {
            content: data[:organization_name]
          },
          phone_number: {
            content: data[:phone_number]
          },
          tag_names: %w(design modern),
          website: {
            content: data[:website]
          }
        }
        expect(attrs).to eq(expected)
      end
    end

    context 'with bonus fields' do
      it 'returns a hash that ignores those fields' do
        data = {
          emmmmail: '<EMAIL>',
          omglol: 'hahaha',
          organization_name: 'Best Gallery',
          phone_number: '1-800-123-4567',
          website: 'http://example.com'
        }
        raw_input = Fabricate :raw_input, data: data
        attrs = CsvTransformer.transform raw_input
        expected = {
          organization_name: {
            content: data[:organization_name]
          },
          phone_number: {
            content: data[:phone_number]
          },
          website: {
            content: data[:website]
          }
        }
        expect(attrs).to eq(expected)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.10210026061628086, 'fraction_numerical': 0.023608768971332208, 'mean_word_length': 1.5404984423676011, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 3, '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': '2997509', 'n_tokens_mistral': 1864, 'n_tokens_neox': 1748, 'n_words': 439}