Merge remote-tracking branch 'remotes/origin/develop' into 1364-no-pushes-from-blocke...
[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 alias Pleroma.Web.ApiSpec
10 alias Pleroma.Web.ApiSpec.Schemas.DomainBlocksResponse
11
12 import Pleroma.Factory
13 import OpenApiSpex.TestAssertions
14
15 test "blocking / unblocking a domain" do
16 %{user: user, conn: conn} = oauth_access(["write:blocks"])
17 other_user = insert(:user, %{ap_id: "https://dogwhistle.zone/@pundit"})
18
19 ret_conn =
20 conn
21 |> put_req_header("content-type", "application/json")
22 |> post("/api/v1/domain_blocks", %{"domain" => "dogwhistle.zone"})
23
24 assert %{} = json_response(ret_conn, 200)
25 user = User.get_cached_by_ap_id(user.ap_id)
26 assert User.blocks?(user, other_user)
27
28 ret_conn =
29 conn
30 |> put_req_header("content-type", "application/json")
31 |> delete("/api/v1/domain_blocks", %{"domain" => "dogwhistle.zone"})
32
33 assert %{} = json_response(ret_conn, 200)
34 user = User.get_cached_by_ap_id(user.ap_id)
35 refute User.blocks?(user, other_user)
36 end
37
38 test "getting a list of domain blocks" do
39 %{user: user, conn: conn} = oauth_access(["read:blocks"])
40
41 {:ok, user} = User.block_domain(user, "bad.site")
42 {:ok, user} = User.block_domain(user, "even.worse.site")
43
44 conn =
45 conn
46 |> assign(:user, user)
47 |> get("/api/v1/domain_blocks")
48
49 domain_blocks = json_response(conn, 200)
50
51 assert "bad.site" in domain_blocks
52 assert "even.worse.site" in domain_blocks
53 assert_schema(domain_blocks, "DomainBlocksResponse", ApiSpec.spec())
54 end
55
56 test "DomainBlocksResponse example matches schema" do
57 api_spec = ApiSpec.spec()
58 schema = DomainBlocksResponse.schema()
59 assert_schema(schema.example, "DomainBlocksResponse", api_spec)
60 end
61 end