tests for is_nsfw_live_announcement mk2
This commit is contained in:
parent
719fe79f73
commit
eca005eff5
apps/bright
lib/bright/socials
test
@ -68,7 +68,11 @@ defmodule Bright.Socials.XPost do
|
||||
end
|
||||
|
||||
def authored_by_vtuber?(x_post, vtuber) do
|
||||
x_post.vtuber_id === vtuber.id
|
||||
vtuber_path = URI.parse(vtuber.twitter).path
|
||||
post_path = URI.parse(x_post.url).path
|
||||
Logger.debug("vtuber_path=#{inspect(vtuber_path)} post_path=#{inspect(post_path)}")
|
||||
|
||||
String.starts_with?(post_path, vtuber_path)
|
||||
end
|
||||
|
||||
def get_unprocessed_posts() do
|
||||
@ -149,17 +153,26 @@ defmodule Bright.Socials.XPost do
|
||||
sfw_platforms = Enum.reject(known_platforms, & &1.nsfw)
|
||||
|
||||
conditions = [
|
||||
# {:authored_by_vtuber?, XPost.authored_by_vtuber?(post, vtuber)}, # This one might not make sense. I think we only get posts from the vtuber's feed
|
||||
{:not_vod?, not String.contains?(String.downcase(post.raw), "vod")},
|
||||
{:contains_nsfw_link?, Platforms.contains_platform?(mentioned_platforms, nsfw_platforms)},
|
||||
{:no_sfw_link?, not Platforms.contains_platform?(mentioned_platforms, sfw_platforms)}
|
||||
{:not_rt, XPost.authored_by_vtuber?(post, vtuber)},
|
||||
{:not_vod, not String.contains?(String.downcase(post.raw), "vod")},
|
||||
{:contains_nsfw_link, Platforms.contains_platform?(mentioned_platforms, nsfw_platforms)},
|
||||
{:no_sfw_link, not Platforms.contains_platform?(mentioned_platforms, sfw_platforms)}
|
||||
]
|
||||
|
||||
Enum.reduce_while(conditions, true, fn {label, condition}, _acc ->
|
||||
if condition do
|
||||
{:cont, true}
|
||||
else
|
||||
Logger.debug("NSFW announcement check failed at: #{label}")
|
||||
Logger.debug(">>> NSFW announcement check failed at: #{label}")
|
||||
Logger.debug(">>> NSFW announcement check failed at: #{label}")
|
||||
Logger.debug(">>> NSFW announcement check failed at: #{label}")
|
||||
Logger.debug(">>> NSFW announcement check failed at: #{label}")
|
||||
Logger.debug(">>> NSFW announcement check failed at: #{label}")
|
||||
Logger.debug(">>> NSFW announcement check failed at: #{label}")
|
||||
Logger.debug(">>> NSFW announcement check failed at: #{label}")
|
||||
Logger.debug(">>> NSFW announcement check failed at: #{label}")
|
||||
Logger.debug(">>> NSFW announcement check failed at: #{label}")
|
||||
Logger.debug(">>> NSFW announcement check failed at: #{label}")
|
||||
{:halt, false}
|
||||
end
|
||||
end)
|
||||
|
@ -16,15 +16,15 @@ defmodule Bright.XPostTest do
|
||||
describe "authored_by_vtuber?/2" do
|
||||
@tag :unit
|
||||
test "returns true when the given post is authored by the given vtuber" do
|
||||
vtuber = VtubersFixtures.vtuber_fixture(%{name: "ProjektMelody", slug: "projektmelody"})
|
||||
vtuber = VtubersFixtures.projektmelody_fixture()
|
||||
x_post = SocialsFixtures.x_post_fixture(%{vtuber_id: vtuber.id})
|
||||
assert XPost.authored_by_vtuber?(x_post, vtuber)
|
||||
end
|
||||
|
||||
@tag :unit
|
||||
test "returns false when the given post is NOT authored by the given vtuber" do
|
||||
vtuber = VtubersFixtures.vtuber_fixture(%{name: "ProjektMelody", slug: "projektmelody"})
|
||||
vtuberB = VtubersFixtures.vtuber_fixture(%{name: "Vex", slug: "vex"})
|
||||
vtuber = VtubersFixtures.projektmelody_fixture()
|
||||
vtuberB = VtubersFixtures.el_xox_fixture()
|
||||
|
||||
{:ok, x_post} =
|
||||
Socials.create_x_post(%{
|
||||
@ -365,12 +365,12 @@ defmodule Bright.XPostTest do
|
||||
|
||||
describe "is_nsfw_live_announcement?/3" do
|
||||
setup do
|
||||
vtuber = VtubersFixtures.vtuber_fixture()
|
||||
vtuber = VtubersFixtures.projektmelody_fixture()
|
||||
|
||||
{:ok, x_post} =
|
||||
Socials.create_x_post(%{
|
||||
raw: "I'm going live https://twitch.tv/bigchungus",
|
||||
url: "https://x.com/bigchungus/status/1234",
|
||||
raw: "I'm going live https://chaturbate.com/projektmelody",
|
||||
url: "https://x.com/projektmelody/status/1234",
|
||||
date: DateTime.utc_now(:second),
|
||||
vtuber_id: vtuber.id
|
||||
})
|
||||
@ -429,15 +429,41 @@ defmodule Bright.XPostTest do
|
||||
assert XPost.is_nsfw_live_announcement?(x_post, mentioned_platforms, known_platforms)
|
||||
end
|
||||
|
||||
test "should return false when receiving an XPost with vod/i", %{
|
||||
vtuber: vtuber,
|
||||
test "should return false when the XPost is a retweet", %{
|
||||
known_platforms: known_platforms,
|
||||
mentioned_platforms: mentioned_platforms
|
||||
} do
|
||||
vtuber = VtubersFixtures.el_xox_fixture()
|
||||
|
||||
x_post = %XPost{
|
||||
url: "https://x.com/mangel0399/status/1898602105851506907",
|
||||
raw: "#34_XoX",
|
||||
date: ~U[2025-03-09T05:09:51.000Z],
|
||||
processed_at: nil,
|
||||
vtuber_id: vtuber.id
|
||||
}
|
||||
|
||||
x_post = Repo.preload(x_post, :vtuber)
|
||||
|
||||
assert not XPost.is_nsfw_live_announcement?(x_post, mentioned_platforms, known_platforms)
|
||||
end
|
||||
|
||||
test "should return false when receiving an XPost with `vod/i`", %{
|
||||
known_platforms: known_platforms
|
||||
} do
|
||||
vtuber = VtubersFixtures.el_xox_fixture()
|
||||
|
||||
x_post = %XPost{
|
||||
raw:
|
||||
"IRL JOI handcam stream! Listen to my instructions and stroke your cock for me until you cum 🍆💦\n\nThe rest of the VOD is available here for Tier 1 subscribers or for $10! 💛\n▶️ https://fansly.com/post/755934614"
|
||||
"IRL JOI handcam stream! Listen to my instructions and stroke your cock for me until you cum 🍆💦\n\nThe rest of the VOD is available here for Tier 1 subscribers or for $10! 💛\n▶️ https://fansly.com/post/755934614",
|
||||
url: "https://x.com/el_XoX34/status/1900275678152712493",
|
||||
date: ~U[2025-03-09T05:09:51.000Z],
|
||||
processed_at: nil,
|
||||
vtuber_id: vtuber.id
|
||||
}
|
||||
|
||||
x_post = Repo.preload(x_post, :vtuber)
|
||||
|
||||
mentioned_platforms = [PlatformsFixtures.fansly_fixture()]
|
||||
assert not XPost.is_nsfw_live_announcement?(x_post, mentioned_platforms, known_platforms)
|
||||
end
|
||||
|
@ -12,7 +12,7 @@ defmodule Bright.SocialsFixtures do
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
raw: "some raw text",
|
||||
url: "https://x.com/fakeuser/status/9876",
|
||||
url: "https://x.com/projektmelody/status/9876",
|
||||
processed_at: nil,
|
||||
date: DateTime.utc_now(:second)
|
||||
})
|
||||
|
@ -42,4 +42,32 @@ defmodule Bright.VtubersFixtures do
|
||||
|
||||
vtuber
|
||||
end
|
||||
|
||||
def el_xox_fixture() do
|
||||
{:ok, vtuber} =
|
||||
%{
|
||||
display_name: "el_XoX",
|
||||
slug: "el_xox",
|
||||
twitter: "https://x.com/el_XoX34",
|
||||
theme_color: "#c061cb",
|
||||
image: "https://futureporn-b2.b-cdn.net/el_xox.jpg"
|
||||
}
|
||||
|> Bright.Vtubers.create_vtuber()
|
||||
|
||||
vtuber
|
||||
end
|
||||
|
||||
def projektmelody_fixture() do
|
||||
{:ok, vtuber} =
|
||||
%{
|
||||
display_name: "ProjektMelody",
|
||||
slug: "projektmelody",
|
||||
twitter: "https://x.com/projektmelody",
|
||||
theme_color: "#c061cb",
|
||||
image: "https://futureporn-b2.b-cdn.net/projekt-melody.jpg"
|
||||
}
|
||||
|> Bright.Vtubers.create_vtuber()
|
||||
|
||||
vtuber
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user