# typed: false
require "rails_helper"

RSpec.describe Domain::UserJobEventsController, type: :controller do
  # Create a real user with admin role
  let(:auth_user) { create(:user, :admin) }
  render_views

  before do
    # Sign in the user
    sign_in auth_user
    # Mock authorization to allow all actions
    allow(controller).to receive(:authorize).and_return(true)
  end

  describe "GET #tracked_objects" do
    it "returns a successful response and renders the favs_scans template" do
      user = create(:domain_user_fa_user)
      create(:domain_user_job_event_add_tracked_object, :favs_scan, user:)
      get :tracked_objects,
          params: {
            domain_user_id: user.to_param,
            kind: "favs",
          },
          format: :html

      expect(response).to be_successful
      expect(response).to render_template(:tracked_objects)
      expect(assigns(:tracked_objects).count).to eq(1)
    end
  end

  describe "GET #tracked_objects_kinds" do
    it "returns a successful response and renders the tracked_objects_kinds template" do
      user = create(:domain_user_fa_user)
      create(:domain_user_job_event_add_tracked_object, :favs_scan, user:)
      get :tracked_objects_kinds,
          params: {
            domain_user_id: user.to_param,
          },
          format: :html

      expect(response).to be_successful
      expect(response).to render_template(:tracked_objects_kinds)
      expect(assigns(:kinds)).to eq(%w[favs followed_by following gallery])
      expect(assigns(:kind_counts)).to eq("favs" => 1)
    end
  end
end
