Make tests a bit more legible

This commit is contained in:
Mark Felder 2020-11-12 10:11:20 -06:00 committed by Mark Felder
parent 2b231eeaf9
commit 879a94c755

View file

@ -11,82 +11,107 @@ defmodule Pleroma.Web.ActivityPub.MRF.AutoSubjectPolicyTest do
[user: user]
end
test "pattern as string", %{user: user} do
clear_config([:mrf_auto_subject, :match], [{"yes", "no"}])
test "pattern as string, matches case insensitive", %{user: user} do
clear_config([:mrf_auto_subject, :match], [{"senate", "uspol"}])
assert {:ok, %{"object" => %{"content" => "yes & no", "summary" => "no"}}} =
assert {:ok,
%{"object" => %{"content" => "The Senate is now in recess.", "summary" => "uspol"}}} =
AutoSubjectPolicy.filter(%{
"type" => "Create",
"actor" => user.ap_id,
"object" => %{"content" => "yes & no", "summary" => ""}
"object" => %{"content" => "The Senate is now in recess.", "summary" => ""}
})
end
test "pattern as list", %{user: user} do
clear_config([:mrf_auto_subject, :match], [{["yes", "yep"], "no"}])
clear_config([:mrf_auto_subject, :match], [{["dinner", "sandwich"], "food"}])
assert {:ok, %{"object" => %{"content" => "yes & no & yep", "summary" => "no"}}} =
assert {:ok,
%{
"object" => %{
"content" => "I decided to eat leftovers for dinner again.",
"summary" => "food"
}
}} =
AutoSubjectPolicy.filter(%{
"type" => "Create",
"actor" => user.ap_id,
"object" => %{"content" => "yes & no & yep"}
"object" => %{"content" => "I decided to eat leftovers for dinner again."}
})
end
test "multiple matches", %{user: user} do
clear_config([:mrf_auto_subject, :match], [{["yes", "yep"], "no"}, {"cat", "dog"}])
test "multiple matches and punctuation trimming", %{user: user} do
clear_config([:mrf_auto_subject, :match], [{["dog", "cat"], "pets"}, {"Torvalds", "Linux"}])
assert {:ok, %{"object" => %{"content" => "yes & no & cat", "summary" => "dog, no"}}} =
assert {:ok,
%{
"object" => %{
"content" => "A long time ago I named my dog after Linus Torvalds.",
"summary" => "Linux, pets"
}
}} =
AutoSubjectPolicy.filter(%{
"type" => "Create",
"actor" => user.ap_id,
"object" => %{"content" => "yes & no & cat"}
"object" => %{
"content" => "A long time ago I named my dog after Linus Torvalds."
}
})
end
test "with no match", %{user: user} do
clear_config([:mrf_auto_subject, :match], [{"yes", "no"}])
clear_config([:mrf_auto_subject, :match], [{"puppy", "pets"}])
assert {:ok, %{"object" => %{"content" => "only no", "summary" => ""}}} =
assert {:ok, %{"object" => %{"content" => "I have a kitten", "summary" => ""}}} =
AutoSubjectPolicy.filter(%{
"type" => "Create",
"actor" => user.ap_id,
"object" => %{"content" => "only no", "summary" => ""}
"object" => %{"content" => "I have a kitten", "summary" => ""}
})
end
test "user is not local" do
user = insert(:user, local: false)
clear_config([:mrf_auto_subject, :match], [{"yes", "no"}])
clear_config([:mrf_auto_subject, :match], [{"puppy", "pets"}])
assert {:ok, %{"object" => %{"content" => "yes & no", "summary" => ""}}} =
assert {:ok, %{"object" => %{"content" => "We just got a puppy", "summary" => ""}}} =
AutoSubjectPolicy.filter(%{
"type" => "Create",
"actor" => user.ap_id,
"object" => %{"content" => "yes & no", "summary" => ""}
"object" => %{"content" => "We just got a puppy", "summary" => ""}
})
end
test "object contains summary", %{user: user} do
clear_config([:mrf_auto_subject, :match], [{"yes", "no"}])
test "subject is already set", %{user: user} do
clear_config([:mrf_auto_subject, :match], [{"election", "politics"}])
assert {:ok, %{"object" => %{"content" => "yes & no", "summary" => "subject"}}} =
assert {:ok,
%{
"object" => %{
"content" => "If your election lasts more than 4 hours you should see a doctor",
"summary" => "uspol, humor"
}
}} =
AutoSubjectPolicy.filter(%{
"type" => "Create",
"actor" => user.ap_id,
"object" => %{"content" => "yes & no", "summary" => "subject"}
"object" => %{
"content" =>
"If your election lasts more than 4 hours you should see a doctor",
"summary" => "uspol, humor"
}
})
end
end
test "describe/0" do
clear_config([:mrf_auto_subject, :match], [{"yes", "no"}])
clear_config([:mrf_auto_subject, :match], [{"dog", "pets"}])
assert AutoSubjectPolicy.describe() ==
{:ok,
%{
mrf_auto_subject: %{
match: [{"yes", "no"}]
match: [{"dog", "pets"}]
}
}}
end