Got all tests working except controller tests
This commit is contained in:
parent
83be9e67e1
commit
039bfdc42c
7 changed files with 30 additions and 30 deletions
|
|
@ -22,7 +22,7 @@ defmodule Pinchflat.Media.MediaItem do
|
|||
# Will very likely revisit because I can't leave well-enough alone.
|
||||
field :subtitle_filepaths, {:array, {:array, :string}}, default: []
|
||||
|
||||
belongs_to :channel, Channel, foreign_key: :source_id
|
||||
belongs_to :source, Channel
|
||||
|
||||
has_one :metadata, MediaMetadata, on_replace: :update
|
||||
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ defmodule Pinchflat.MediaClient.VideoDownloader do
|
|||
Returns {:ok, %MediaItem{}} | {:error, any, ...any}
|
||||
"""
|
||||
def download_for_media_item(%MediaItem{} = media_item, backend \\ :yt_dlp) do
|
||||
item_with_preloads = Repo.preload(media_item, [:metadata, channel: :media_profile])
|
||||
media_profile = item_with_preloads.channel.media_profile
|
||||
item_with_preloads = Repo.preload(media_item, [:metadata, source: :media_profile])
|
||||
media_profile = item_with_preloads.source.media_profile
|
||||
|
||||
case download_for_media_profile(media_item.media_id, media_profile, backend) do
|
||||
{:ok, parsed_json} ->
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ defmodule Pinchflat.Tasks.Task do
|
|||
|
||||
schema "tasks" do
|
||||
belongs_to :job, Oban.Job
|
||||
belongs_to :channel, Channel, foreign_key: :source_id
|
||||
belongs_to :source, Channel
|
||||
belongs_to :media_item, MediaItem
|
||||
|
||||
timestamps(type: :utc_datetime)
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ defmodule Pinchflat.MediaClient.VideoDownloaderTest do
|
|||
media_item =
|
||||
Repo.preload(
|
||||
media_item_fixture(%{title: nil, media_filepath: nil}),
|
||||
[:metadata, channel: :media_profile]
|
||||
[:metadata, source: :media_profile]
|
||||
)
|
||||
|
||||
{:ok, %{media_item: media_item}}
|
||||
|
|
|
|||
|
|
@ -21,11 +21,11 @@ defmodule Pinchflat.TasksTest do
|
|||
end
|
||||
|
||||
test "it does not delete the other record when a job gets deleted" do
|
||||
task = Repo.preload(task_fixture(), [:channel, :job])
|
||||
task = Repo.preload(task_fixture(), [:source, :job])
|
||||
|
||||
{:ok, _} = Repo.delete(task.job)
|
||||
|
||||
assert Repo.reload!(task.channel)
|
||||
assert Repo.reload!(task.source)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -40,14 +40,14 @@ defmodule Pinchflat.TasksTest do
|
|||
test "it lets you specify which record type/ID to join on" do
|
||||
task = task_fixture()
|
||||
|
||||
assert Tasks.list_tasks_for(:channel_id, task.channel_id) == [task]
|
||||
assert Tasks.list_tasks_for(:source_id, task.source_id) == [task]
|
||||
end
|
||||
|
||||
test "it lets you specify which job states to include" do
|
||||
task = task_fixture()
|
||||
|
||||
assert Tasks.list_tasks_for(:channel_id, task.channel_id, [:available]) == [task]
|
||||
assert Tasks.list_tasks_for(:channel_id, task.channel_id, [:cancelled]) == []
|
||||
assert Tasks.list_tasks_for(:source_id, task.source_id, [:available]) == [task]
|
||||
assert Tasks.list_tasks_for(:source_id, task.source_id, [:cancelled]) == []
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -55,14 +55,14 @@ defmodule Pinchflat.TasksTest do
|
|||
test "it lists pending tasks" do
|
||||
task = task_fixture()
|
||||
|
||||
assert Tasks.list_pending_tasks_for(:channel_id, task.channel_id) == [task]
|
||||
assert Tasks.list_pending_tasks_for(:source_id, task.source_id) == [task]
|
||||
end
|
||||
|
||||
test "it does not list non-pending tasks" do
|
||||
task = Repo.preload(task_fixture(), :job)
|
||||
:ok = Oban.cancel_job(task.job)
|
||||
|
||||
assert Tasks.list_pending_tasks_for(:channel_id, task.channel_id) == []
|
||||
assert Tasks.list_pending_tasks_for(:source_id, task.source_id) == []
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -84,14 +84,14 @@ defmodule Pinchflat.TasksTest do
|
|||
assert {:error, %Ecto.Changeset{}} = Tasks.create_task(@invalid_attrs)
|
||||
end
|
||||
|
||||
test "accepts a job and channel" do
|
||||
test "accepts a job and source" do
|
||||
job = job_fixture()
|
||||
source = source_fixture()
|
||||
|
||||
assert {:ok, %Task{} = task} = Tasks.create_task(job, channel)
|
||||
assert {:ok, %Task{} = task} = Tasks.create_task(job, source)
|
||||
|
||||
assert task.job_id == job.id
|
||||
assert task.channel_id == channel.id
|
||||
assert task.source_id == source.id
|
||||
end
|
||||
|
||||
test "accepts a job and media item" do
|
||||
|
|
@ -117,23 +117,23 @@ defmodule Pinchflat.TasksTest do
|
|||
test "it creates a task record if successful" do
|
||||
source = source_fixture()
|
||||
|
||||
assert {:ok, %Task{} = task} = Tasks.create_job_with_task(TestJobWorker.new(%{}), channel)
|
||||
assert {:ok, %Task{} = task} = Tasks.create_job_with_task(TestJobWorker.new(%{}), source)
|
||||
|
||||
assert task.channel_id == channel.id
|
||||
assert task.source_id == source.id
|
||||
end
|
||||
|
||||
test "it returns an error if the job already exists" do
|
||||
source = source_fixture()
|
||||
job = TestJobWorker.new(%{foo: "bar"}, unique: [period: :infinity])
|
||||
|
||||
assert {:ok, %Task{}} = Tasks.create_job_with_task(job, channel)
|
||||
assert {:error, :duplicate_job} = Tasks.create_job_with_task(job, channel)
|
||||
assert {:ok, %Task{}} = Tasks.create_job_with_task(job, source)
|
||||
assert {:error, :duplicate_job} = Tasks.create_job_with_task(job, source)
|
||||
end
|
||||
|
||||
test "it returns an error if the job fails to enqueue" do
|
||||
source = source_fixture()
|
||||
|
||||
assert {:error, %Ecto.Changeset{}} = Tasks.create_job_with_task(%Ecto.Changeset{}, channel)
|
||||
assert {:error, %Ecto.Changeset{}} = Tasks.create_job_with_task(%Ecto.Changeset{}, source)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -155,11 +155,11 @@ defmodule Pinchflat.TasksTest do
|
|||
end
|
||||
|
||||
describe "delete_tasks_for/1" do
|
||||
test "it deletes tasks attached to a channel" do
|
||||
test "it deletes tasks attached to a source" do
|
||||
source = source_fixture()
|
||||
task = task_fixture(channel_id: channel.id)
|
||||
task = task_fixture(source_id: source.id)
|
||||
|
||||
assert :ok = Tasks.delete_tasks_for(channel)
|
||||
assert :ok = Tasks.delete_tasks_for(source)
|
||||
assert_raise Ecto.NoResultsError, fn -> Tasks.get_task!(task.id) end
|
||||
end
|
||||
|
||||
|
|
@ -173,20 +173,20 @@ defmodule Pinchflat.TasksTest do
|
|||
end
|
||||
|
||||
describe "delete_pending_tasks_for/1" do
|
||||
test "it deletes pending tasks attached to a channel" do
|
||||
test "it deletes pending tasks attached to a source" do
|
||||
source = source_fixture()
|
||||
task = task_fixture(channel_id: channel.id)
|
||||
task = task_fixture(source_id: source.id)
|
||||
|
||||
assert :ok = Tasks.delete_pending_tasks_for(channel)
|
||||
assert :ok = Tasks.delete_pending_tasks_for(source)
|
||||
assert_raise Ecto.NoResultsError, fn -> Tasks.get_task!(task.id) end
|
||||
end
|
||||
|
||||
test "it does not delete non-pending tasks" do
|
||||
source = source_fixture()
|
||||
task = Repo.preload(task_fixture(channel_id: channel.id), :job)
|
||||
task = Repo.preload(task_fixture(source_id: source.id), :job)
|
||||
:ok = Oban.cancel_job(task.job)
|
||||
|
||||
assert :ok = Tasks.delete_pending_tasks_for(channel)
|
||||
assert :ok = Tasks.delete_pending_tasks_for(source)
|
||||
assert Tasks.get_task!(task.id)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ defmodule Pinchflat.Workers.VideoDownloadWorkerTest do
|
|||
media_item =
|
||||
Repo.preload(
|
||||
media_item_fixture(%{media_filepath: nil}),
|
||||
[:metadata, channel: :media_profile]
|
||||
[:metadata, source: :media_profile]
|
||||
)
|
||||
|
||||
{:ok, %{media_item: media_item}}
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ defmodule PinchflatWeb.ChannelControllerTest do
|
|||
|
||||
defp create_source(_) do
|
||||
source = source_fixture()
|
||||
%{channel: channel}
|
||||
%{channel: source}
|
||||
end
|
||||
|
||||
defp runner_function_mock(_url, _opts, _ot) do
|
||||
|
|
|
|||
Loading…
Reference in a new issue