Skip to content

Commit

Permalink
Added tests for video download worker
Browse files Browse the repository at this point in the history
  • Loading branch information
kieraneglin committed Jan 30, 2024
1 parent 777ccb7 commit 95a766f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/pinchflat/workers/video_download_worker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ defmodule Pinchflat.Workers.VideoDownloadWorker do

@impl Oban.Worker
@doc """
TODO: test
For a given media item, download the video and save the metadata.
Returns {:ok, %MediaItem{}} | {:error, any, ...any}
"""
def perform(%Oban.Job{args: %{"id" => media_item_id}}) do
media_item = Media.get_media_item!(media_item_id)
Expand Down
42 changes: 42 additions & 0 deletions test/pinchflat/workers/video_download_worker_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
defmodule Pinchflat.Workers.VideoDownloadWorkerTest do
use Pinchflat.DataCase

import Mox
import Pinchflat.MediaFixtures

alias Pinchflat.Workers.VideoDownloadWorker

setup :verify_on_exit!

setup do
media_item =
Repo.preload(
media_item_fixture(%{video_filepath: nil}),
[:metadata, channel: :media_profile]
)

{:ok, %{media_item: media_item}}
end

describe "perform/1" do
test "it saves attributes to the media_item", %{media_item: media_item} do
expect(YtDlpRunnerMock, :run, fn _url, _opts, _ot ->
{:ok, render_metadata(:media_metadata)}
end)

assert media_item.video_filepath == nil
perform_job(VideoDownloadWorker, %{id: media_item.id})
assert Repo.reload(media_item).video_filepath != nil
end

test "it saves the metadata to the media_item", %{media_item: media_item} do
expect(YtDlpRunnerMock, :run, fn _url, _opts, _ot ->
{:ok, render_metadata(:media_metadata)}
end)

assert media_item.metadata == nil
perform_job(VideoDownloadWorker, %{id: media_item.id})
assert Repo.reload(media_item).metadata != nil
end
end
end

0 comments on commit 95a766f

Please sign in to comment.