# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Api::MiscReleasesController, type: :controller do
  let(:current_user) { create(:user) }
  let(:project) { create(:project, name: 'first', account: current_user.primary_account) }

  describe '#index' do
    it 'returns a succesful response' do
      create(:misc_release, person_first_name: 'John', person_last_name: 'Lee', project_id: project.id)
      create(:misc_release, person_first_name: 'Jane', person_last_name: 'Lee', project_id: project.id)

      sign_in_to_api(current_user)
      get :index, params: { project_id: project.id }

      expect(response).to be_successful
      expect(response.body).to include 'John'
      expect(response.body).to include 'Jane'
    end
  end

  describe '#show' do
    it 'returns a succesful response' do
      release1 = create(:misc_release, person_first_name: 'John', person_last_name: 'Lee', project_id: project.id)
      release2 = create(:misc_release, person_first_name: 'Jane', person_last_name: 'Lee', project_id: project.id)

      sign_in_to_api(current_user)
      get :show, params: { id: release1 }

      expect(response).to be_successful
      expect(response.body).to include 'John'
      expect(response.body).not_to include 'Jane'

      get :show, params: { id: release2 }

      expect(response).to be_successful
      expect(response.body).not_to include 'John'
      expect(response.body).to include 'Jane'
    end
  end
end
