Ensured download worker always returns a 2-member tuple

This commit is contained in:
Kieran Eglin 2024-03-29 17:27:25 -07:00
parent 8c6901cf81
commit 84edf1902f
No known key found for this signature in database
GPG key ID: 193984967FCF432D
3 changed files with 10 additions and 3 deletions

View file

@ -32,8 +32,7 @@ config :pinchflat, Pinchflat.Mailer, adapter: Swoosh.Adapters.Test
# Disable swoosh api client as it is only required for production adapters.
config :swoosh, :api_client, false
# Print only warnings and errors during test
config :logger, level: :warning
config :logger, level: :critical
# Initialize plugs at runtime for faster test compilation
config :phoenix, :plug_init_mode, :runtime

View file

@ -57,7 +57,9 @@ defmodule Pinchflat.Downloading.MediaDownloadWorker do
{:ok, updated_media_item}
err ->
err
Logger.error("Failed to download media for media item #{media_item.id}: #{inspect(err)}")
{:error, :download_failed}
end
end

View file

@ -74,6 +74,12 @@ defmodule Pinchflat.Downloading.MediaDownloadWorkerTest do
end)
end
test "it ensures error are returned in a 2-item tuple", %{media_item: media_item} do
expect(YtDlpRunnerMock, :run, fn _url, _opts, _ot -> {:error, "error", 1} end)
assert {:error, :download_failed} = perform_job(MediaDownloadWorker, %{id: media_item.id})
end
test "it does not download if the source is set to not download", %{media_item: media_item} do
expect(YtDlpRunnerMock, :run, 0, fn _url, _opts, _ot -> :ok end)