<commit_before># frozen_string_literal: true

require 'rails_helper'

RSpec.describe Api::V1::PlantingsController, type: :controller do
  subject { JSON.parse response.body }

  let!(:member) { FactoryBot.create :member }

  describe '#index' do
    let(:matching_planting) { subject['data'].select { |planting| planting['id'] == my_planting.id.to_s }.first }

    describe 'GET #index' do
      context 'basic planting' do
        let!(:my_planting) { FactoryBot.create(:planting, owner: member, planted_at: '2000-01-01') }
        let(:expected_attributes) do
          {
            'crop-name'           => my_planting.crop.name,
            'crop-slug'           => my_planting.crop.slug,
            'description'         => my_planting.description,
            'expected-lifespan'   => nil,
            'finish-predicted-at' => nil,
            'finished'            => my_planting.finished,
            'finished-at'         => my_planting.finished_at,
            'first-harvest-date'  => nil,
            'last-harvest-date'   => nil,
            'latitude'            => my_planting.garden.latitude,
            'longitude'           => my_planting.garden.longitude,
            'location'            => my_planting.garden.location,
            'percentage-grown'    => nil,
            'planted-at'          => '2000-01-01',
            'planted-from'        => my_planting.planted_from,
            'quantity'            => my_planting.quantity,
            'slug'                => my_planting.slug,
            'sunniness'           => nil,
            'thumbnail'           => nil
          }
        end

        before { get :index, format: :json }

        it { expect(matching_planting).to include('id' => my_planting.id.to_s) }
        it { expect(matching_planting['attributes']).to eq expected_attributes }
        it { expect(response.status).to eq 200 }
      end

      context 'with photo' do
        let!(:my_planting) { FactoryBot.create(:planting, owner: member, planted_at: '2000-01-01') }

        let(:expected_attributes) do
          {
            'crop-name'           => my_planting.crop.name,
            'description'         => my_planting.description,
            'expected-lifespan'   => nil,
            'finish-predicted-at' => nil,
            'finished'            => my_planting.finished,
            'finished-at'         => my_planting.finished_at,
            'first-harvest-date'  => nil,
            'last-harvest-date'   => nil,
            'percentage-grown'    => nil,
            'planted-at'          => '2000-01-01',
            'planted-from'        => my_planting.planted_from,
            'quantity'            => my_planting.quantity,
            'slug'                => my_planting.slug,
            'sunniness'           => nil,
            'thumbnail'           => photo.thumbnail_url
          }
        end
        let(:photo) { FactoryBot.create(:photo, owner: my_planting.owner) }
<commit_msg>Add new planting api attributes to test<commit_after># frozen_string_literal: true

require 'rails_helper'

RSpec.describe Api::V1::PlantingsController, type: :controller do
  subject { JSON.parse response.body }

  let!(:member) { FactoryBot.create :member }

  describe '#index' do
    let(:matching_planting) { subject['data'].select { |planting| planting['id'] == my_planting.id.to_s }.first }

    describe 'GET #index' do
      context 'basic planting' do
        let!(:my_planting) { FactoryBot.create(:planting, owner: member, planted_at: '2000-01-01') }
        let(:expected_attributes) do
          {
            'crop-name'           => my_planting.crop.name,
            'crop-slug'           => my_planting.crop.slug,
            'description'         => my_planting.description,
            'expected-lifespan'   => nil,
            'finish-predicted-at' => nil,
            'finished'            => my_planting.finished,
            'finished-at'         => my_planting.finished_at,
            'first-harvest-date'  => nil,
            'last-harvest-date'   => nil,
            'latitude'            => my_planting.garden.latitude,
            'longitude'           => my_planting.garden.longitude,
            'location'            => my_planting.garden.location,
            'percentage-grown'    => nil,
            'planted-at'          => '2000-01-01',
            'planted-from'        => my_planting.planted_from,
            'quantity'            => my_planting.quantity,
            'slug'                => my_planting.slug,
            'sunniness'           => nil,
            'thumbnail'           => nil
          }
        end

        before { get :index, format: :json }

        it { expect(matching_planting).to include('id' => my_planting.id.to_s) }
        it { expect(matching_planting['attributes']).to eq expected_attributes }
        it { expect(response.status).to eq 200 }
      end

      context 'with photo' do
        let!(:my_planting) { FactoryBot.create(:planting, owner: member, planted_at: '2000-01-01') }

        let(:expected_attributes) do
          {
            'crop-name'           => my_planting.crop.name,
            'crop-slug'           => my_planting.crop.slug,
            'description'         => my_planting.description,
            'expected-lifespan'   => nil,
            'finish-predicted-at' => nil,
            'finished'            => my_planting.finished,
            'finished-at'         => my_planting.finished_at,
            'first-harvest-date'  => nil,
            'last-harvest-date'   => nil,
            'latitude'            => my_planting.garden.latitude,
            'longitude'           => my_planting.garden.longitude,
            'location'            => my_planting.garden.location,
            'percentage-grown'    => nil,
            'planted-at'          => '2000-01-01',
            'planted-from'        => my_planting.planted_from,
            'quantity'            => my_planting.quantity,
            'slug'                => my_planting.slug,
            'sunniness'           => nil,
            'thumbnail'           => photo.thumbnail_url
          }
        end
        let(:photo) { FactoryBot.create(:photo, owner: my_planting.owner) }

{'fraction_non_alphanumeric': 0.12638866527129286, 'fraction_numerical': 0.011592336177749154, 'mean_word_length': 1.645655877342419, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 77, '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': '1211836', 'n_tokens_mistral': 1905, 'n_tokens_neox': 1833, 'n_words': 304}