From 879a94c7558f8b8c82b4e68e428265a127ca58a7 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Thu, 12 Nov 2020 10:11:20 -0600 Subject: Make tests a bit more legible --- .../activity_pub/mrf/auto_subject_policy_test.exs | 71 +++++++++++++++------- 1 file changed, 48 insertions(+), 23 deletions(-) diff --git a/test/pleroma/web/activity_pub/mrf/auto_subject_policy_test.exs b/test/pleroma/web/activity_pub/mrf/auto_subject_policy_test.exs index ed7fa9385..a71835825 100644 --- a/test/pleroma/web/activity_pub/mrf/auto_subject_policy_test.exs +++ b/test/pleroma/web/activity_pub/mrf/auto_subject_policy_test.exs @@ -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 -- cgit v1.2.3