252 lines
7.1 KiB
Elixir
252 lines
7.1 KiB
Elixir
defmodule Bright.XPostTest do
|
|
use Bright.DataCase
|
|
|
|
alias Bright.Socials.XPost
|
|
alias Bright.Vtubers.Vtuber
|
|
alias Bright.XPostsFixtures
|
|
alias Bright.Platforms.{Platform, PlatformAlias}
|
|
alias Bright.Platforms
|
|
alias Bright.VultrAI
|
|
|
|
@sample_feed "https://rss.app/feeds/FhPetvUY036xiFau.xml"
|
|
|
|
describe "get_new_posts" do
|
|
@tag :integration
|
|
test "get_new_posts/1 with URL" do
|
|
{:ok, posts} = XPost.get_new_posts(@sample_feed)
|
|
assert length(posts) > 0
|
|
end
|
|
|
|
@tag :integration
|
|
test "get_new_posts/1 with %Vtuber{}" do
|
|
vtuber = %Vtuber{twitter_rss: @sample_feed}
|
|
{:ok, posts} = XPost.get_new_posts(vtuber)
|
|
assert length(posts) > 0
|
|
end
|
|
end
|
|
|
|
describe "extract_hostname/1" do
|
|
@tag :unit
|
|
test "gets the hostname" do
|
|
assert XPost.extract_hostname("https://chaturbate.com") === "chaturbate.com"
|
|
assert XPost.extract_hostname("https://twitch.tv") === "twitch.tv"
|
|
assert XPost.extract_hostname("https://google.com") === "google.com"
|
|
end
|
|
end
|
|
|
|
describe "includes_alias?/2" do
|
|
@tag :unit
|
|
test "returns true when a platform alias url is found in XPost raw content" do
|
|
platform = %Platform{
|
|
url: "https://blueballfixed.ytmnd.com",
|
|
slug: "ytmnd",
|
|
name: "You're The Man Now Dog",
|
|
nsfw: false
|
|
}
|
|
|
|
platform_alias = %PlatformAlias{url: "https://shorturl.at/lZ3NM", platform_id: platform.id}
|
|
x_post = %XPost{raw: "Hello World please join my stream rn https://shorturl.at/lZ3NM"}
|
|
assert XPost.includes_alias?(x_post, platform)
|
|
end
|
|
|
|
@tag :unit
|
|
test "returns false when no platform alias url is present in XPost raw content" do
|
|
end
|
|
|
|
@tag :unit
|
|
test "returns true when a platform alias url is found in raw_text" do
|
|
end
|
|
|
|
@tag :unit
|
|
test "returns false when no platform alias url is present in raw_text" do
|
|
end
|
|
end
|
|
|
|
describe "includes_platform?" do
|
|
@tag :unit
|
|
test "includes_platform? with raw text" do
|
|
raw_text = "hello world check out my stream: twitch.tv/sexyman42"
|
|
platform = %Platform{name: "Twitch", slug: "twitch", url: "https://twitch.tv", nsfw: false}
|
|
XPost.includes_platform?(raw_text, platform)
|
|
end
|
|
|
|
@tag :unit
|
|
test "includes_platform? with x_post" do
|
|
x_post = %XPost{raw: "LIVE NOW https://chaturbate.com"}
|
|
|
|
platform = %Platform{
|
|
name: "Chaturbate",
|
|
slug: "chaturbate",
|
|
url: "https://chaturbate.com",
|
|
nsfw: true
|
|
}
|
|
|
|
XPost.includes_platform?(x_post, platform)
|
|
end
|
|
end
|
|
|
|
describe "get_platforms_mentioned" do
|
|
setup %{} do
|
|
assert {:ok, %Platform{}} =
|
|
Platforms.create_platform(%{
|
|
name: "Chaturbate",
|
|
slug: "chaturbate",
|
|
url: "https://chaturbate.com"
|
|
})
|
|
|
|
assert {:ok, %Platform{}} =
|
|
Platforms.create_platform(%{
|
|
name: "OnlyFans",
|
|
slug: "onlyfans",
|
|
url: "https://onlyfans.com"
|
|
})
|
|
|
|
# seed the test db with some platforms
|
|
assert {:ok, %Platform{} = fanslyPlatform} =
|
|
Platforms.create_platform(%{
|
|
name: "Fansly",
|
|
slug: "fansly",
|
|
url: "https://fansly.com"
|
|
})
|
|
|
|
assert {:ok, %Platform{}} =
|
|
Platforms.create_platform(%{
|
|
name: "Twitch",
|
|
slug: "twitch",
|
|
url: "https://twitch.tv"
|
|
})
|
|
|
|
IO.puts("fanslyPlatform=#{inspect(fanslyPlatform)} id=#{fanslyPlatform.id}")
|
|
|
|
assert {:ok, %PlatformAlias{} = platAlias} =
|
|
Platforms.create_platform_alias(%{
|
|
url: "https://melody.buzz",
|
|
platform_id: fanslyPlatform.id
|
|
})
|
|
|
|
IO.puts("platAlias=#{inspect(platAlias)}")
|
|
|
|
:ok
|
|
end
|
|
|
|
@tag :unit
|
|
test "post with no links" do
|
|
platforms = Platforms.list_platforms()
|
|
|
|
expected_platform_names = []
|
|
|
|
actual_platform_names =
|
|
XPost.get_platforms_mentioned(
|
|
XPostsFixtures.fixture_offline_1() |> Map.get(:raw),
|
|
platforms
|
|
)
|
|
# Extract only names
|
|
|> Enum.map(& &1.name)
|
|
|
|
assert Enum.sort(actual_platform_names) == Enum.sort(expected_platform_names)
|
|
end
|
|
|
|
@tag :unit
|
|
test "post with non-invite links" do
|
|
platforms = Platforms.list_platforms()
|
|
|
|
expected_platform_names = []
|
|
|
|
actual_platform_names =
|
|
XPost.get_platforms_mentioned(
|
|
XPostsFixtures.fixture_offline_2() |> Map.get(:raw),
|
|
platforms
|
|
)
|
|
# Extract only names
|
|
|> Enum.map(& &1.name)
|
|
|
|
assert Enum.sort(actual_platform_names) == Enum.sort(expected_platform_names)
|
|
end
|
|
|
|
@tag :unit
|
|
test "post with only SFW invite links" do
|
|
platforms = Platforms.list_platforms()
|
|
|
|
expected_platform_names = ["Fansly", "Twitch"]
|
|
|
|
actual_platform_names =
|
|
XPost.get_platforms_mentioned(
|
|
XPostsFixtures.fixture_offline_3() |> Map.get(:raw),
|
|
platforms
|
|
)
|
|
# Extract only names
|
|
|> Enum.map(& &1.name)
|
|
|
|
assert Enum.sort(actual_platform_names) == Enum.sort(expected_platform_names)
|
|
end
|
|
|
|
@tag :unit
|
|
test "another post with only SFW invite links" do
|
|
platforms = Platforms.list_platforms()
|
|
|
|
expected_platform_names = ["Fansly", "Twitch"]
|
|
|
|
actual_platform_names =
|
|
XPost.get_platforms_mentioned(
|
|
XPostsFixtures.fixture_offline_4() |> Map.get(:raw),
|
|
platforms
|
|
)
|
|
# Extract only names
|
|
|> Enum.map(& &1.name)
|
|
|
|
assert Enum.sort(actual_platform_names) == Enum.sort(expected_platform_names)
|
|
end
|
|
|
|
@tag :unit
|
|
test "post with 3 platform invites 1" do
|
|
platforms = Platforms.list_platforms()
|
|
|
|
expected_platform_names = ["Fansly", "OnlyFans", "Chaturbate"]
|
|
|
|
actual_platform_names =
|
|
XPost.get_platforms_mentioned(
|
|
XPostsFixtures.fixture_live_1() |> Map.get(:raw),
|
|
platforms
|
|
)
|
|
# Extract only names
|
|
|> Enum.map(& &1.name)
|
|
|
|
assert Enum.sort(actual_platform_names) == Enum.sort(expected_platform_names)
|
|
end
|
|
|
|
@tag :unit
|
|
test "post with 3 platform invites 2" do
|
|
platforms = Platforms.list_platforms()
|
|
|
|
expected_platform_names = ["Fansly", "OnlyFans", "Chaturbate"]
|
|
|
|
actual_platform_names =
|
|
XPost.get_platforms_mentioned(
|
|
XPostsFixtures.fixture_live_2() |> Map.get(:raw),
|
|
platforms
|
|
)
|
|
# Extract only names
|
|
|> Enum.map(& &1.name)
|
|
|
|
assert Enum.sort(actual_platform_names) == Enum.sort(expected_platform_names)
|
|
end
|
|
|
|
@tag :unit
|
|
test "post with 3 platform invites 3" do
|
|
platforms = Platforms.list_platforms()
|
|
|
|
expected_platform_names = ["Fansly", "OnlyFans", "Chaturbate"]
|
|
|
|
actual_platform_names =
|
|
XPost.get_platforms_mentioned(
|
|
XPostsFixtures.fixture_live_3() |> Map.get(:raw),
|
|
platforms
|
|
)
|
|
# Extract only names
|
|
|> Enum.map(& &1.name)
|
|
|
|
assert Enum.sort(actual_platform_names) == Enum.sort(expected_platform_names)
|
|
end
|
|
end
|
|
end
|