01a24afcf2225a35589b65b1c7aff63dd49648a4
[akkoma] / test / web / mastodon_api / controllers / domain_block_controller_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.MastodonAPI.DomainBlockControllerTest do
6 use Pleroma.Web.ConnCase
7
8 alias Pleroma.User
9
10 import Pleroma.Factory
11
12 test "blocking / unblocking a domain" do
13 %{user: user, conn: conn} = oauth_access(["write:blocks"])
14 other_user = insert(:user, %{ap_id: "https://dogwhistle.zone/@pundit"})
15
16 ret_conn =
17 conn
18 |> put_req_header("content-type", "application/json")
19 |> post("/api/v1/domain_blocks", %{"domain" => "dogwhistle.zone"})
20
21 assert %{} == json_response_and_validate_schema(ret_conn, 200)
22 user = User.get_cached_by_ap_id(user.ap_id)
23 assert User.blocks?(user, other_user)
24
25 ret_conn =
26 conn
27 |> put_req_header("content-type", "application/json")
28 |> delete("/api/v1/domain_blocks", %{"domain" => "dogwhistle.zone"})
29
30 assert %{} == json_response_and_validate_schema(ret_conn, 200)
31 user = User.get_cached_by_ap_id(user.ap_id)
32 refute User.blocks?(user, other_user)
33 end
34
35 test "getting a list of domain blocks" do
36 %{user: user, conn: conn} = oauth_access(["read:blocks"])
37
38 {:ok, user} = User.block_domain(user, "bad.site")
39 {:ok, user} = User.block_domain(user, "even.worse.site")
40
41 assert ["even.worse.site", "bad.site"] ==
42 conn
43 |> assign(:user, user)
44 |> get("/api/v1/domain_blocks")
45 |> json_response_and_validate_schema(200)
46 end
47 end