1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.MastodonAPI.DomainBlockControllerTest do
6 use Pleroma.Web.ConnCase
10 import Pleroma.Factory
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"})
18 |> put_req_header("content-type", "application/json")
19 |> post("/api/v1/domain_blocks", %{"domain" => "dogwhistle.zone"})
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)
27 |> put_req_header("content-type", "application/json")
28 |> delete("/api/v1/domain_blocks", %{"domain" => "dogwhistle.zone"})
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)
35 test "getting a list of domain blocks" do
36 %{user: user, conn: conn} = oauth_access(["read:blocks"])
38 {:ok, user} = User.block_domain(user, "bad.site")
39 {:ok, user} = User.block_domain(user, "even.worse.site")
41 assert ["even.worse.site", "bad.site"] ==
43 |> assign(:user, user)
44 |> get("/api/v1/domain_blocks")
45 |> json_response_and_validate_schema(200)