require "rails_helper"

module IssuesAndConcerns
  RSpec.describe IssuesAndConcernsReportPresenter do
    let(:project) { build(:project, name: "Guardians of the Galaxy") }
    let(:video) { create(:video, project: project) }

    describe "#project_name" do
      it "returns video project name" do
        expect(described_class.new(video).project_name).to eq "Guardians of the Galaxy"
      end
    end

    describe "#video_name" do
      it "returns video file name" do
        expect(described_class.new(video).video_name).to eq "video_file.mp4"
      end
    end

    describe "#date_of_report" do
      it "returns today's date" do
        allow(BigMediaTime).to receive(:time_zone_now).and_return(Time.zone.parse("Mon, 15 Jul 2019 16:09:47 UTC +00:00"))

        expect(described_class.new(video).date_of_report).to eq "07/15/19"
      end
    end

    describe "#unreleased_appearances" do
      let!(:unreleased_appearance) { create(:unreleased_appearance, video: video, time_elapsed: 50.12) }

      it "returns unreleased appearances ordered by time_elapsed" do
        first_record = create(:unreleased_appearance, video: video, time_elapsed: 5.12)
        last_record = create(:unreleased_appearance, video: video, time_elapsed: 150.12)

        expect(described_class.new(video).unreleased_appearances).to eq([
          first_record,
          unreleased_appearance,
          last_record,
        ])
      end

      it "returns only unreleased appearances for provided video" do
        create(:unreleased_appearance, video: create(:video))

        expect(described_class.new(video).unreleased_appearances).to eq([unreleased_appearance])
      end
    end
  end
end
