require "rails_helper"

RSpec.describe GraphicsFilesForRequest do
  let(:video) do
   create(:video, :with_graphics_only_edl_file, analysis_uid: "analysis_uid") do |video|
      video.file.key = "awesome"
      video.graphics_only_edl_file.key = "sauce"
    end
  end

  subject { described_class.new(video, "offset") }

  describe "#start_timecode_offset" do
    it "returns given start_timecode_offset" do
      expect(subject.start_timecode_offset).to eq "offset"
    end
  end

  describe "#file_object_name" do
    it "returns file key" do
      expect(subject.file_object_name).to eq "awesome"
    end

    it "returns nil when no video file attached" do
      video.file.purge
      expect(subject.file_object_name).to be_nil
    end
  end

  describe "#edl_file_object_name" do
    it "returns graphics edl file key" do
      expect(subject.edl_file_object_name).to eq "sauce"
    end

    it "returns nil when no video file attached" do
      video.graphics_only_edl_file.purge
      expect(subject.edl_file_object_name).to be_nil
    end
  end

  describe "#aws_bucket_name" do
    it "returns AWS bucket name" do
      allow(ENV).to receive(:[])
      allow(ENV).to receive(:[]).with("AWS_BUCKET").and_return("bucket")
      expect(subject.aws_bucket_name).to eq "bucket"
    end
  end

  describe "#job_id" do
    it "returns the analysis uid of the video" do
      expect(subject.job_id).to eq "analysis_uid"
    end
  end
end
