require "rails_helper"

RSpec.describe BulkTaggingsController, type: :controller do
  render_views

  let(:user) { create(:user) }
  let(:project) { create(:project, account: user.primary_account) }
  let(:acquired_media_releases) { create_list(:acquired_media_release, 5, project: project) }

  before do
    sign_in user
  end

  describe "#new" do
    it "responds successfully" do
      tagged_ids = acquired_media_releases.map(&:id).sample(3).to_s
      get :new, params: { releasable_ids: tagged_ids, releasable_name: "acquired_media_releases", project_id: project.id }, xhr: true

      expect(response).to be_successful
    end
  end

  describe "#create" do
    it "tags multiple releases" do
      tagged_ids = acquired_media_releases.map(&:id).sample(3).to_s
      post :create, params: acquired_media_release_params(tagged_ids), xhr: true
  
      expect(response.body).to have_content('Approved', count: 3)
    end
  end

  private

  def acquired_media_release_params(tagged_ids)
    { name: "Approved", releasable_ids: tagged_ids, releasable_name: "acquired_media_releases", project_id: project.id }
  end
end
