diff options
author | marcin mikołajczak <git@mkljczk.pl> | 2022-02-07 23:55:20 +0100 |
---|---|---|
committer | marcin mikołajczak <git@mkljczk.pl> | 2022-05-16 14:03:06 +0200 |
commit | bbf3bc2228ca4bc5c209e418538665240e2aa9ed (patch) | |
tree | 0612c85137df3262a9e365e13f2513845ffaf590 | |
parent | 384f8bfa786f51f3abec101e2ab78917f324a4fa (diff) | |
download | pleroma-bbf3bc2228ca4bc5c209e418538665240e2aa9ed.tar.gz pleroma-bbf3bc2228ca4bc5c209e418538665240e2aa9ed.zip |
Add RuleTest
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
-rw-r--r-- | test/pleroma/rule_test.exs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/test/pleroma/rule_test.exs b/test/pleroma/rule_test.exs new file mode 100644 index 000000000..012ac902c --- /dev/null +++ b/test/pleroma/rule_test.exs @@ -0,0 +1,46 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.RuleTest do + use Pleroma.DataCase, async: true + + alias Pleroma.Repo + alias Pleroma.Rule + + test "getting a list of rules sorted by priority" do + %{id: id1} = Rule.create(%{text: "Example rule"}) + %{id: id2} = Rule.create(%{text: "Second rule", priority: 2}) + %{id: id3} = Rule.create(%{text: "Third rule", priority: 1}) + + rules = + Rule.query() + |> Repo.all() + + assert [%{id: ^id1}, %{id: ^id3}, %{id: ^id2}] = rules + end + + test "creating rules" do + %{id: id} = Rule.create(%{text: "Example rule"}) + + assert %{text: "Example rule"} = Rule.get(id) + end + + test "editing rules" do + %{id: id} = Rule.create(%{text: "Example rule"}) + + Rule.update(%{text: "There are no rules", priority: 2}, id) + + assert %{text: "There are no rules", priority: 2} = Rule.get(id) + end + + test "deleting rules" do + %{id: id} = Rule.create(%{text: "Example rule"}) + + Rule.delete(id) + + assert [] = + Rule.query() + |> Pleroma.Repo.all() + end +end |