From 9745340bee106a0f07681878ec757bb032dcd9ac Mon Sep 17 00:00:00 2001 From: Kieran Eglin Date: Tue, 26 Nov 2024 11:44:06 -0800 Subject: [PATCH] Added tests to download worker modeule --- .../downloading/media_download_worker.ex | 1 - .../downloading/media_download_worker_test.exs | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/pinchflat/downloading/media_download_worker.ex b/lib/pinchflat/downloading/media_download_worker.ex index 6b9f942..ff1459b 100644 --- a/lib/pinchflat/downloading/media_download_worker.ex +++ b/lib/pinchflat/downloading/media_download_worker.ex @@ -94,7 +94,6 @@ defmodule Pinchflat.Downloading.MediaDownloadWorker do {:recovered, _} -> {:error, :retry} - # TODO: test {:error, :unsuitable_for_download} -> {:ok, :non_retry} diff --git a/test/pinchflat/downloading/media_download_worker_test.exs b/test/pinchflat/downloading/media_download_worker_test.exs index a34adfb..76dc1a3 100644 --- a/test/pinchflat/downloading/media_download_worker_test.exs +++ b/test/pinchflat/downloading/media_download_worker_test.exs @@ -9,6 +9,7 @@ defmodule Pinchflat.Downloading.MediaDownloadWorkerTest do alias Pinchflat.Downloading.MediaDownloadWorker setup do + stub(YtDlpRunnerMock, :run, fn _url, _opts, _ot -> {:ok, "{}"} end) stub(YtDlpRunnerMock, :run, fn _url, _opts, _ot, _addl -> {:ok, ""} end) stub(UserScriptRunnerMock, :run, fn _event_type, _data -> {:ok, "", 0} end) stub(HTTPClientMock, :get, fn _url, _headers, _opts -> {:ok, ""} end) @@ -186,6 +187,20 @@ defmodule Pinchflat.Downloading.MediaDownloadWorkerTest do end end + describe "perform/1 when testing non-downloadable media" do + test "does not retry the job if the media is currently not downloadable", %{media_item: media_item} do + expect(YtDlpRunnerMock, :run, fn _url, _opts, _ot -> + {:ok, Phoenix.json_library().encode!(%{"live_status" => "is_live"})} + end) + + Oban.Testing.with_testing_mode(:inline, fn -> + {:ok, job} = Oban.insert(MediaDownloadWorker.new(%{id: media_item.id})) + + assert job.state == "completed" + end) + end + end + describe "perform/1 when testing forced downloads" do test "ignores 'prevent_download' if forced", %{media_item: media_item} do expect(YtDlpRunnerMock, :run, fn _url, _opts, _ot, _addl -> :ok end)