* Made method to getting singular media details; Renamed other related method * Takes a fun and flirty digression to remove abstractions around yt-dlp since I'm 100% committed to using it exclusively * Removed commented test code * Lays the groundwork for fast indexing * Added module for working with youtube RSS feed * Added methods to kick off indexing workers from RSS response * Improve short detection (#59) * Made media attribute-related yt-dlp calls return a struct * Added shorts attribute to media items * Added ability to discern a short from yt-dlp response * Updated search to use new shorts attribute * Fast index UI (#63) * Added fast_index field and adds it to source form * Added fast indexing to source changeset operations * Added fast indexing worker and updated other modules to start using it * Handled fast index worker on source update * Add support modals (#65) * Added fast indexing upgrade modal * Improved modal on smaller screens * Updated links to work again * Added donation modal * Reverted source fast index to 15 minutes * Removed unneeded HTML attributes from old alpine approach
79 lines
2.5 KiB
Elixir
79 lines
2.5 KiB
Elixir
defmodule Pinchflat.Api.YoutubeRssTest do
|
|
use Pinchflat.DataCase
|
|
import Mox
|
|
import Pinchflat.SourcesFixtures
|
|
|
|
alias Pinchflat.Api.YoutubeRss
|
|
|
|
setup :verify_on_exit!
|
|
|
|
setup do
|
|
source = source_fixture()
|
|
|
|
{:ok, source: source}
|
|
end
|
|
|
|
describe "get_recent_media_ids_from_rss/1" do
|
|
test "calls the expected URL for channel sources" do
|
|
source = source_fixture(collection_type: :channel, collection_id: "channel_id")
|
|
|
|
expect(HTTPClientMock, :get, fn url ->
|
|
assert url =~ "https://www.youtube.com/feeds/videos.xml?channel_id=#{source.collection_id}"
|
|
|
|
{:ok, ""}
|
|
end)
|
|
|
|
assert {:ok, _} = YoutubeRss.get_recent_media_ids_from_rss(source)
|
|
end
|
|
|
|
test "calls the expected URL for playlist sources" do
|
|
source = source_fixture(collection_type: :playlist, collection_id: "playlist_id")
|
|
|
|
expect(HTTPClientMock, :get, fn url ->
|
|
assert url =~ "https://www.youtube.com/feeds/videos.xml?playlist_id=#{source.collection_id}"
|
|
|
|
{:ok, ""}
|
|
end)
|
|
|
|
assert {:ok, _} = YoutubeRss.get_recent_media_ids_from_rss(source)
|
|
end
|
|
|
|
test "returns an error if the HTTP request fails", %{source: source} do
|
|
expect(HTTPClientMock, :get, fn _url -> {:error, ""} end)
|
|
|
|
assert {:error, "Failed to fetch RSS feed"} = YoutubeRss.get_recent_media_ids_from_rss(source)
|
|
end
|
|
|
|
test "returns the media IDs from the RSS feed", %{source: source} do
|
|
expect(HTTPClientMock, :get, fn _url ->
|
|
{:ok, "<yt:videoId>test_1</yt:videoId><yt:videoId>test_2</yt:videoId>"}
|
|
end)
|
|
|
|
assert {:ok, ["test_1", "test_2"]} = YoutubeRss.get_recent_media_ids_from_rss(source)
|
|
end
|
|
|
|
test "strips whitespace from media IDs", %{source: source} do
|
|
expect(HTTPClientMock, :get, fn _url ->
|
|
{:ok, "<yt:videoId> test_1 </yt:videoId><yt:videoId> test_2 </yt:videoId>"}
|
|
end)
|
|
|
|
assert {:ok, ["test_1", "test_2"]} = YoutubeRss.get_recent_media_ids_from_rss(source)
|
|
end
|
|
|
|
test "removes empty media IDs", %{source: source} do
|
|
expect(HTTPClientMock, :get, fn _url ->
|
|
{:ok, "<yt:videoId>test_1</yt:videoId><yt:videoId></yt:videoId>"}
|
|
end)
|
|
|
|
assert {:ok, ["test_1"]} = YoutubeRss.get_recent_media_ids_from_rss(source)
|
|
end
|
|
|
|
test "removes duplicate media IDs", %{source: source} do
|
|
expect(HTTPClientMock, :get, fn _url ->
|
|
{:ok, "<yt:videoId>test_1</yt:videoId><yt:videoId>test_1</yt:videoId>"}
|
|
end)
|
|
|
|
assert {:ok, ["test_1"]} = YoutubeRss.get_recent_media_ids_from_rss(source)
|
|
end
|
|
end
|
|
end
|