[Enhancement] Redownload new media after a delay (#173)
* Added redownload-related columns * Added methods for fetching re-downloadable media items * Filled out redownload worker + tests * Added redownload worker to config.exs cron * Added to UI and README
This commit is contained in:
@@ -130,6 +130,131 @@ defmodule Pinchflat.MediaTest do
|
||||
end
|
||||
end
|
||||
|
||||
describe "list_redownloadable_media_items/0" do
|
||||
setup do
|
||||
media_profile = media_profile_fixture(%{redownload_delay_days: 4})
|
||||
source = source_fixture(%{media_profile_id: media_profile.id, inserted_at: now_minus(10, :days)})
|
||||
|
||||
{:ok, %{media_profile: media_profile, source: source}}
|
||||
end
|
||||
|
||||
test "returns media eligible for redownload", %{source: source} do
|
||||
media_item =
|
||||
media_item_fixture(%{
|
||||
source_id: source.id,
|
||||
upload_date: now_minus(6, :days),
|
||||
media_downloaded_at: now_minus(5, :days)
|
||||
})
|
||||
|
||||
assert Media.list_redownloadable_media_items() == [media_item]
|
||||
end
|
||||
|
||||
test "returns media items that were downloaded in past but still meet redownload delay", %{source: source} do
|
||||
media_item =
|
||||
media_item_fixture(%{
|
||||
source_id: source.id,
|
||||
upload_date: now_minus(20, :days),
|
||||
media_downloaded_at: now_minus(19, :days)
|
||||
})
|
||||
|
||||
assert Media.list_redownloadable_media_items() == [media_item]
|
||||
end
|
||||
|
||||
test "does not return media items without a media_downloaded_at", %{source: source} do
|
||||
_media_item =
|
||||
media_item_fixture(%{
|
||||
source_id: source.id,
|
||||
upload_date: now_minus(5, :days),
|
||||
media_downloaded_at: nil
|
||||
})
|
||||
|
||||
assert Media.list_redownloadable_media_items() == []
|
||||
end
|
||||
|
||||
test "does not return media items that are set to prevent download", %{source: source} do
|
||||
_media_item =
|
||||
media_item_fixture(%{
|
||||
source_id: source.id,
|
||||
upload_date: now_minus(5, :days),
|
||||
media_downloaded_at: now(),
|
||||
prevent_download: true
|
||||
})
|
||||
|
||||
assert Media.list_redownloadable_media_items() == []
|
||||
end
|
||||
|
||||
test "does not return media items that have been culled", %{source: source} do
|
||||
_media_item =
|
||||
media_item_fixture(%{
|
||||
source_id: source.id,
|
||||
upload_date: now_minus(5, :days),
|
||||
media_downloaded_at: now(),
|
||||
culled_at: now()
|
||||
})
|
||||
|
||||
assert Media.list_redownloadable_media_items() == []
|
||||
end
|
||||
|
||||
test "does not return media items before the download delay", %{source: source} do
|
||||
_media_item =
|
||||
media_item_fixture(%{
|
||||
source_id: source.id,
|
||||
upload_date: now_minus(3, :days),
|
||||
media_downloaded_at: now_minus(3, :days)
|
||||
})
|
||||
|
||||
assert Media.list_redownloadable_media_items() == []
|
||||
end
|
||||
|
||||
test "does not return media items that have already been redownloaded", %{source: source} do
|
||||
_media_item =
|
||||
media_item_fixture(%{
|
||||
source_id: source.id,
|
||||
upload_date: now_minus(5, :days),
|
||||
media_downloaded_at: now(),
|
||||
media_redownloaded_at: now()
|
||||
})
|
||||
|
||||
assert Media.list_redownloadable_media_items() == []
|
||||
end
|
||||
|
||||
test "does not return media items that were first downloaded well after the upload_date", %{source: source} do
|
||||
_media_item =
|
||||
media_item_fixture(%{
|
||||
source_id: source.id,
|
||||
media_downloaded_at: now(),
|
||||
upload_date: now_minus(20, :days)
|
||||
})
|
||||
|
||||
assert Media.list_redownloadable_media_items() == []
|
||||
end
|
||||
|
||||
test "does not return media items that were recently uploaded", %{source: source} do
|
||||
_media_item =
|
||||
media_item_fixture(%{
|
||||
source_id: source.id,
|
||||
media_downloaded_at: now(),
|
||||
upload_date: now_minus(2, :days)
|
||||
})
|
||||
|
||||
assert Media.list_redownloadable_media_items() == []
|
||||
end
|
||||
|
||||
test "does not return media items without a redownload delay" do
|
||||
media_profile = media_profile_fixture(%{redownload_delay_days: nil})
|
||||
source = source_fixture(%{media_profile_id: media_profile.id})
|
||||
|
||||
_media_item =
|
||||
media_item_fixture(%{
|
||||
source_id: source.id,
|
||||
upload_date: now_minus(6, :days),
|
||||
media_downloaded_at: now_minus(5, :days)
|
||||
})
|
||||
|
||||
assert Media.list_redownloadable_media_items() == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "list_pending_media_items_for/1" do
|
||||
test "it returns pending without a filepath for a given source" do
|
||||
source = source_fixture()
|
||||
|
||||
Reference in New Issue
Block a user