Initial commit

This commit is contained in:
Senad Uka
2020-05-31 22:38:19 +02:00
commit 858fafc3c5
1280 changed files with 65918 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
require "rails_helper"
module AudioConfirmations
RSpec.describe AudioConfirmationsPresenter do
describe "#present" do
describe "audio_confirmations" do
it "returns audio_confirmations sorted by appears_at" do
audio_confirmations = [
build(:audio_confirmation, time_elapsed: 0),
build(:audio_confirmation, time_elapsed: 50),
build(:audio_confirmation, time_elapsed: 10),
]
results = subject.present(audio_confirmations).audio_confirmations
expect(results.map(&:appears_at)).to eq ["00:00:00:00", "00:00:10:00", "00:00:50:00"]
end
end
end
end
end

View File

@@ -0,0 +1,118 @@
require "rails_helper"
RSpec.describe EdlEventsPresenter do
let(:edl_gateway) { instance_double(EdlEventGateway) }
describe "#present" do
it "returns hash of edl_events, edl_attributes, info_message" do
allow(edl_gateway).to receive(:edl_events).and_return(build_list(:edl_event, 1))
expect(described_class.new(edl_gateway).present).to eq({
edl_events: build_list(:edl_event, 1),
edl_attributes: {
timecode_in: "timecode_in",
timecode_out: "timecode_out",
duration: "duration",
source_file_name: "source_file_name",
clip_name: "clip_name",
description: "description",
channel: "V",
},
info_message: "An EDL event was found. Data is shown below",
})
end
describe "edl_attributes" do
context "when 1 edl event" do
before :each do
allow(edl_gateway).to receive(:edl_events).and_return(build_list(:edl_event, 1))
end
it "returns edl attributes from that event" do
expect(described_class.new(edl_gateway).present[:edl_attributes]).to eq({
timecode_in: "timecode_in",
timecode_out: "timecode_out",
duration: "duration",
source_file_name: "source_file_name",
clip_name: "clip_name",
description: "description",
channel: "V",
})
end
end
context "when multiple edl events" do
before :each do
allow(edl_gateway).to receive(:edl_events).and_return(
[
build(:edl_event),
build(:edl_event, timecode_in: "NOT__timecode_in")
]
)
end
it "returns edl attributes from first event" do
expect(described_class.new(edl_gateway).present[:edl_attributes]).to eq({
timecode_in: "timecode_in",
timecode_out: "timecode_out",
duration: "duration",
source_file_name: "source_file_name",
clip_name: "clip_name",
description: "description",
channel: "V",
})
end
end
context "when no edl events" do
before :each do
allow(edl_gateway).to receive(:edl_events).and_return([])
end
it "returns nil attributes from edl event" do
expect(described_class.new(edl_gateway).present[:edl_attributes]).to eq({
timecode_in: nil,
timecode_out: nil,
duration: nil,
source_file_name: nil,
clip_name: nil,
description: nil,
channel: nil,
})
end
end
end
describe "info_message" do
context "when 1 edl event" do
before :each do
allow(edl_gateway).to receive(:edl_events).and_return(build_list(:edl_event, 1))
end
it "returns 'An EDL event was found. Data is shown below'" do
expect(described_class.new(edl_gateway).present[:info_message]).to eq "An EDL event was found. Data is shown below"
end
end
context "when multiple edl events" do
before :each do
allow(edl_gateway).to receive(:edl_events).and_return(build_list(:edl_event, 2))
end
it "returns 'Multiple EDL events were found. Data for the first is shown below'" do
expect(described_class.new(edl_gateway).present[:info_message]).to eq "Multiple EDL events were found. Data for the first is shown below"
end
end
context "when no edl events" do
before :each do
allow(edl_gateway).to receive(:edl_events).and_return([])
end
it "returns 'No EDL events were found. Please enter manually'" do
expect(described_class.new(edl_gateway).present[:info_message]).to eq "No EDL events were found. Please enter manually"
end
end
end
end
end

View File

@@ -0,0 +1,21 @@
require "rails_helper"
module GraphicsElements
RSpec.describe GraphicsElementsPresenter do
describe "#present" do
describe "graphics_elements" do
it "returns graphics_elements sorted by appears_at" do
graphics_elements = [
build(:graphics_element, time_elapsed: 0),
build(:graphics_element, time_elapsed: 50),
build(:graphics_element, time_elapsed: 10),
]
results = subject.present(graphics_elements).graphics_elements
expect(results.map(&:appears_at)).to eq ["00:00:00:00", "00:00:10:00", "00:00:50:00"]
end
end
end
end
end

View File

@@ -0,0 +1,49 @@
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

View File

@@ -0,0 +1,400 @@
require "rails_helper"
RSpec.describe MatchesPresenter do
let(:project) { build(:project) }
let(:video_analysis) { instance_double(VideoAnalysis) }
let(:audio_analysis) { instance_double(AudioAnalysis) }
describe "#build_chronological_matches" do
context "when video analysis success" do
let(:video) { create(:video, project: project, analysis_status: :success) }
it "returns suggested_matches sorted by most recent first" do
appearance_release = create(:appearance_release, project: project)
appearance = BrayniacAI::FacialRecognitionResult.new(external_image_id: "appearance_release_#{appearance_release.id}", start_time: 100)
allow(video_analysis).to receive(:first_appearances).and_return([appearance])
edl_event_response = build(:edl_event,
channel: "V",
start_time: 0,
timecode_in: "00:00:00:00",
timecode_out: "00:00:01:00",
matches: [1, 2],
)
results = described_class.new(video, video_analysis, audio_analysis, [edl_event_response], []).build_chronological_matches
expect(results.count).to eq 1
expect(results.first.elapsed_time_until_appearance).to eq 0.12
expect(results.first.photo.name).to eq "person_photo"
expect(results.first.name).to eq "Jane Doe"
expect(results.first.appears_at_timecode).to eq Timecode.new("00:00:00:03")
end
end
context "when video analysis not success" do
let(:video) { create(:video, project: project, analysis_status: :pending) }
it "returns empty array" do
expect(described_class.new(video, video_analysis, audio_analysis, [], []).build_chronological_matches).to eq []
end
end
end
describe "#build_graphics_matches" do
context "when video analysis success" do
let(:video) do
create(:video,
project: project,
analysis_status: :success,
graphics_elements: build_list(:graphics_element, 1, source_file_name: "my_file.mp4", timecode_in: "00:00:00:00")
)
end
it "returns graphics elements matches sorted by most recent first" do
earlier_edl_event_response = build(:edl_event,
start_time: 0,
timecode_in: "00:00:00:00",
timecode_out: "00:00:01:00",
source_file_name: "my_file.mp4",
)
later_edl_event_response = build(:edl_event,
start_time: 100,
timecode_in: "00:00:10:00",
timecode_out: "00:00:11:00",
source_file_name: "another_file.mp4",
)
results = described_class.new(
video,
video_analysis,
audio_analysis,
[],
[earlier_edl_event_response, later_edl_event_response],
).build_graphics_matches
expect(results.count).to eq 2
expect(results.first.start_time).to eq 100
expect(results.first.elapsed_time_until_appearance).to eq 0.12
expect(results.first.filename).to eq "another_file.mp4"
expect(results.first.appears_at_timecode).to eq Timecode.new("00:00:00:03")
expect(results.first.confirmed).to be false
expect(results.first.timecode_in).to eq "00:00:10:00"
expect(results.second.start_time).to eq 0
expect(results.second.elapsed_time_until_appearance).to eq 0.0
expect(results.second.appears_at_timecode).to eq Timecode.new("00:00:00:00")
expect(results.second.filename).to eq "my_file.mp4"
expect(results.second.confirmed).to be true
expect(results.second.timecode_in).to eq "00:00:00:00"
end
it "does not return graphics elements matches that have empty source_file_name" do
null_source_file_edl_event_response = build(:edl_event,
source_file_name: nil,
)
empty_source_file_edl_event_response = build(:edl_event,
source_file_name: "",
)
results = described_class.new(
video,
video_analysis,
[],
[
null_source_file_edl_event_response,
empty_source_file_edl_event_response,
],
[],
).build_graphics_matches
expect(results).to eq []
end
end
context "when video analysis not success" do
let(:video) { create(:video, project: project, analysis_status: :pending) }
it "returns empty array" do
expect(described_class.new(video, video_analysis, [], [], []).build_graphics_matches).to eq []
end
end
end
describe "#build_chronological_audio_matches" do
context "when audio analysis success" do
let(:video) { create(:video, project: project, audio_analysis_status: :success) }
it "returns audio_matches sorted by most recent first" do
acquired_media_release = create(:acquired_media_release,
project: project,
file_infos: [
build(:file_info, id: 3, filename: "acquired_media_1")
]
)
music_release = create(:music_release,
project: project,
file_infos: [
build(:file_info, id: 1, filename: "original_music_1"),
build(:file_info, id: 2, filename: "original_music_2"),
]
)
audio_confirmation = create(:audio_confirmation,
video: video,
source_file_name: "original_music_2",
timecode_in: "00:00:00:00",
)
audio_analysis = OpenStruct.new(
results: [
OpenStruct.new(
uid: "2",
requested_filename: "original_music_2",
type: "original_music",
audio_data: OpenStruct.new(
filename: "original_music_2",
composers: [],
publishers: [],
catalog: "",
title: "",
),
edl: [
OpenStruct.new(
start_time: 0,
timecode_in: "00:00:00:00",
),
]
),
OpenStruct.new(
uid: "1",
requested_filename: "original_music_1",
type: "original_music",
audio_data: OpenStruct.new(
filename: "original_music_1",
composers: [],
publishers: [],
catalog: "",
title: "",
),
edl: [
OpenStruct.new(
start_time: 5000,
timecode_in: "00:00:05:00",
),
]
),
OpenStruct.new(
uid: "3",
requested_filename: "acquired_media_1",
type: "acquired_media",
audio_data: OpenStruct.new(
filename: "acquired_media_1",
composers: [],
publishers: [],
catalog: "",
title: "",
),
edl: [
OpenStruct.new(
start_time: 1000,
timecode_in: "00:00:01:00",
),
]
),
OpenStruct.new(
uid: nil,
requested_filename: "library_music_1",
type: "library_music",
audio_data: OpenStruct.new(
filename: "library_music_1",
composers: [OpenStruct.new(name: "Beethoven", affiliation: "Affiliation", percentage: "100.0%")],
publishers: [OpenStruct.new(name: "Jingle Punks", affiliation: "Affiliation", percentage: "100.0%")],
catalog: "MIBE",
title: "Library Music",
),
edl: [
OpenStruct.new(
start_time: 2000,
timecode_in: "00:00:02:00",
),
]
),
]
)
results = described_class.new(
video,
video_analysis,
audio_analysis,
[],
[],
).build_chronological_audio_matches
expect(results.count).to eq 4
expect(results.first).to have_attributes(
elapsed_time_until_appearance: 5.0,
filename: "original_music_1",
appears_at_timecode: Timecode.new("00:00:05:00"),
timecode_in: "00:00:05:00",
confirmed: false,
composer_info: "Beethoven, Affiliation, 100.0%",
publisher_info: "Jingle Punks, Affiliation, 100.0%",
catalog: "",
title: "",
confirmation_type: "original_music",
edl_type: "all_tracks",
)
expect(results.second).to have_attributes(
elapsed_time_until_appearance: 2.0,
filename: "library_music_1",
appears_at_timecode: Timecode.new("00:00:02:00"),
timecode_in: "00:00:02:00",
confirmed: false,
composer_info: "Beethoven, Affiliation, 100.0%",
publisher_info: "Jingle Punks, Affiliation, 100.0%",
catalog: "MIBE",
title: "Library Music",
confirmation_type: "library_music",
edl_type: "all_tracks",
)
expect(results.third).to have_attributes(
elapsed_time_until_appearance: 1.0,
filename: "acquired_media_1",
appears_at_timecode: Timecode.new("00:00:01:00"),
timecode_in: "00:00:01:00",
confirmed: false,
composer_info: "",
publisher_info: "",
catalog: "",
title: "",
confirmation_type: "acquired_media",
edl_type: "all_tracks",
)
expect(results.fourth).to have_attributes(
elapsed_time_until_appearance: 0.0,
filename: "original_music_2",
appears_at_timecode: Timecode.new("00:00:00:00"),
timecode_in: "00:00:00:00",
confirmed: true,
composer_info: "Beethoven, Affiliation, 100.0%",
publisher_info: "Jingle Punks, Affiliation, 100.0%",
catalog: "",
title: "",
confirmation_type: "original_music",
edl_type: "all_tracks",
)
end
context "when audio_only_edl attached" do
it "returns audio_matches with edl_type " do
video = create(:video, :with_audio_only_edl_file, project: project, audio_analysis_status: :success)
audio_analysis = OpenStruct.new(
results: [
OpenStruct.new(
uid: "2",
requested_filename: "source_file_name",
type: "acquired_media",
audio_data: OpenStruct.new(
filename: "source_file_name",
composers: [],
publishers: [],
catalog: "",
title: "",
),
edl: [
OpenStruct.new(
source_file_name: "source_file_name",
start_time: 0,
timecode_in: "00:00:00:00",
),
]
),
]
)
results = described_class.new(
video,
video_analysis,
audio_analysis,
[],
[],
).build_chronological_audio_matches
expect(results.first).to have_attributes(
edl_type: "audio",
)
end
end
end
context "when video analysis not success" do
let(:video) { create(:video, project: project, audio_analysis_status: :pending) }
it "returns empty array" do
expect(described_class.new(video, video_analysis, audio_analysis, [], []).build_chronological_audio_matches).to eq []
end
end
end
describe "#all_tracks_edl_events" do
let(:video) { create(:video, project: project, analysis_status: :pending) }
it "returns edl events sorted by start time ascending" do
earlier_edl_event_response = build(:edl_event,
channel: "V",
start_time: 0,
timecode_in: "00:00:00:00",
timecode_out: "00:00:01:00",
duration: 1,
source_file_name: "my_file.mp4",
clip_name: "my_clip.mp4",
description: "This is a great clip",
matches: [],
)
later_edl_event_response = build(:edl_event,
channel: "A1",
start_time: 100,
timecode_in: "00:00:10:00",
timecode_out: "00:00:11:00",
duration: 1,
source_file_name: "another_file.mp4",
clip_name: "another_clip.mp4",
description: "This is a great clip",
matches: [],
)
results = described_class.new(
video,
video_analysis,
audio_analysis,
[earlier_edl_event_response, later_edl_event_response],
[],
).all_tracks_edl_events
expect(results).to eq [
EdlEvent.new(
channel: "V",
start_time: 0,
timecode_in: "00:00:00:00",
timecode_out: "00:00:01:00",
duration: 1,
source_file_name: "my_file.mp4",
clip_name: "my_clip.mp4",
description: "This is a great clip",
matches: [],
),
EdlEvent.new(
channel: "A1",
start_time: 100,
timecode_in: "00:00:10:00",
timecode_out: "00:00:11:00",
duration: 1,
source_file_name: "another_file.mp4",
clip_name: "another_clip.mp4",
description: "This is a great clip",
matches: [],
),
]
end
end
end

View File

@@ -0,0 +1,120 @@
require "rails_helper"
RSpec.describe VideoAnalysisPresenter do
let(:project) { build(:project) }
let(:video_analysis) { instance_double(VideoAnalysis) }
let(:matches_presenter) { instance_double(MatchesPresenter) }
describe "#stale?" do
it "returns true if appearance releases have been uploaded since the last analysis date" do
appearance_release = create(:appearance_release, project: project, created_at: Time.zone.now)
video = create(:video, project: project, analysis_started_at: 1.day.ago)
video_analysis_presenter = described_class.new(video, video_analysis, matches_presenter)
expect(video_analysis_presenter).to be_stale
end
it "returns false if appearance releases have not been uploaded since the last analysis date" do
appearance_release = create(:appearance_release, project: project, created_at: 1.day.ago)
video = create(:video, project: project, analysis_started_at: Time.zone.now)
video_analysis_presenter = described_class.new(video, video_analysis, matches_presenter)
expect(video_analysis_presenter).not_to be_stale
end
it "includes talent releases" do
talent_release = create(:talent_release, project: project, created_at: 1.hour.ago)
video = create(:video, project: project, analysis_started_at: 2.hours.ago)
video_analysis_presenter = described_class.new(video, video_analysis, matches_presenter)
expect(video_analysis_presenter).to be_stale
end
it "includes acquired media releases" do
acquired_media_release = create(:acquired_media_release, project: project, created_at: 1.hour.ago)
video = create(:video, project: project, analysis_started_at: 2.hours.ago)
video_analysis_presenter = described_class.new(video, video_analysis, matches_presenter)
expect(video_analysis_presenter).to be_stale
end
end
describe "#bookmarks" do
it "returns bookmarks from video" do
video = create(:video, project: project)
bookmark = create(:bookmark, video: video, notes: "Test notes")
expect(described_class.new(video, video_analysis, matches_presenter).bookmarks).to eq [bookmark]
end
end
describe "#video_url" do
context "when video analysis is not successful" do
let(:video) { create(:video, project: project, analysis_status: :pending) }
it "returns video url from video" do
expect(described_class.new(video, video_analysis, matches_presenter).video_url).to match /http:\/\/#{AppHost.new.domain_with_port}\/rails\/active_storage\/blobs\/.*--.*\/video_file.mp4/
end
end
context "when video analysis is successful" do
let(:video) { create(:video, project: project, analysis_status: :success) }
it "returns video url from overlay" do
allow(video_analysis).to receive(:overlay_video_url).and_return("www.google.com")
expect(described_class.new(video, video_analysis, matches_presenter).video_url).to eq "www.google.com"
end
end
end
describe "#unreleased_appearances" do
let(:video) { create(:video, project: project) }
it "returns unreleased_appearances from video" do
unreleased_appearance = create(:unreleased_appearance, video: video)
expect(described_class.new(video, video_analysis, matches_presenter).unreleased_appearances).to eq [unreleased_appearance]
end
end
describe "#chronological_appearances" do
let(:video) { create(:video, project: project) }
it "returns matches" do
allow(matches_presenter).to receive(:build_chronological_matches).and_return(["matches"])
expect(described_class.new(video, video_analysis, matches_presenter).chronological_appearances).to eq ["matches"]
end
end
describe "#chronological_graphics_matches" do
let(:video) { create(:video, project: project) }
it "returns matches" do
allow(matches_presenter).to receive(:build_graphics_matches).and_return(["matches"])
expect(described_class.new(video, video_analysis, matches_presenter).chronological_graphics_matches).to eq ["matches"]
end
end
describe "#all_tracks_edl_events" do
let(:video) { create(:video, project: project) }
it "returns all_tracks_edl_events" do
allow(matches_presenter).to receive(:all_tracks_edl_events).and_return(["edl event"])
expect(described_class.new(video, video_analysis, matches_presenter).all_tracks_edl_events).to eq ["edl event"]
end
end
describe "#chronological_audio_matches" do
let(:video) { create(:video, project: project) }
it "returns matches" do
allow(matches_presenter).to receive(:build_chronological_audio_matches).and_return(["matches"])
expect(described_class.new(video, video_analysis, matches_presenter).chronological_audio_matches).to eq ["matches"]
end
end
end