From c5a7b8ad98257f8a00134dabe9f522e809719842 Mon Sep 17 00:00:00 2001 From: Sadposter Date: Tue, 26 Nov 2019 18:26:37 +0000 Subject: [PATCH] add whitelist route tests --- test/user_test.exs | 2 +- .../controllers/account_controller_test.exs | 47 ++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/test/user_test.exs b/test/user_test.exs index 57e4e35da..f70b9efb5 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -925,7 +925,7 @@ defmodule Pleroma.UserTest do refute User.blocks?(user, good_eggo) end - test "takes precidence over domain blocks" do + test "takes precedence over domain blocks" do user = insert(:user) good_eggo = insert(:user, %{ap_id: "https://awful-and-rude-instance.com/user/cuteposter"}) diff --git a/test/web/pleroma_api/controllers/account_controller_test.exs b/test/web/pleroma_api/controllers/account_controller_test.exs index c809f510f..7185f95e3 100644 --- a/test/web/pleroma_api/controllers/account_controller_test.exs +++ b/test/web/pleroma_api/controllers/account_controller_test.exs @@ -391,4 +391,51 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do assert %{"error" => "Record not found"} = json_response(conn, 404) end end + + describe "whitelisting / unwhitelisting" do + test "whitelisting / unwhitelisting to a user", %{conn: conn} do + user = insert(:user) + whitelist_target = insert(:user) + + conn = + conn + |> assign(:user, user) + |> post("/api/v1/pleroma/accounts/#{whitelist_target.id}/whitelist") + + assert %{"id" => _id, "whitelisting" => true} = json_response(conn, 200) + + conn = + build_conn() + |> assign(:user, user) + |> post("/api/v1/pleroma/accounts/#{whitelist_target.id}/unwhitelist") + + assert %{"id" => _id, "whitelisting" => false} = json_response(conn, 200) + end + end + + describe "whitelisting" do + test "returns 404 when whitelist_target not found", %{conn: conn} do + user = insert(:user) + + conn = + conn + |> assign(:user, user) + |> post("/api/v1/pleroma/accounts/target_id/whitelist") + + assert %{"error" => "Record not found"} = json_response(conn, 404) + end + end + + describe "unwhitelisting" do + test "returns 404 when whitelist_target not found", %{conn: conn} do + user = insert(:user) + + conn = + conn + |> assign(:user, user) + |> post("/api/v1/pleroma/accounts/target_id/unwhitelist") + + assert %{"error" => "Record not found"} = json_response(conn, 404) + end + end end