summaryrefslogtreecommitdiff
path: root/test/web/admin_api/controllers/media_proxy_cache_controller_test.exs
blob: 1b1d6bc36f295c8067c0f71e920f6995fac6a3c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.Web.AdminAPI.MediaProxyCacheControllerTest do
  use Pleroma.Web.ConnCase

  import Pleroma.Factory

  setup do
    admin = insert(:user, is_admin: true)
    token = insert(:oauth_admin_token, user: admin)

    conn =
      build_conn()
      |> assign(:user, admin)
      |> assign(:token, token)

    {:ok, %{admin: admin, token: token, conn: conn}}
  end

  describe "GET /api/pleroma/admin/media_proxy_caches" do
    test "shows banned MediaProxy URLs", %{conn: conn} do
      response =
        conn
        |> get("/api/pleroma/admin/media_proxy_caches")
        |> json_response_and_validate_schema(200)

      assert response["urls"] == []
    end
  end

  describe "DELETE /api/pleroma/admin/media_proxy_caches/delete" do
    test "deleted MediaProxy URLs from banned", %{conn: conn} do
      response =
        conn
        |> put_req_header("content-type", "application/json")
        |> post("/api/pleroma/admin/media_proxy_caches/delete", %{
          urls: ["http://example.com/media/a688346.jpg", "http://example.com/media/fb1f4d.jpg"]
        })
        |> json_response_and_validate_schema(200)

      assert response["urls"] == [
               "http://example.com/media/a688346.jpg",
               "http://example.com/media/fb1f4d.jpg"
             ]
    end
  end

  describe "PURGE /api/pleroma/admin/media_proxy_caches/purge" do
    test "perform invalidates cache of MediaProxy", %{conn: conn} do
      response =
        conn
        |> put_req_header("content-type", "application/json")
        |> post("/api/pleroma/admin/media_proxy_caches/purge", %{
          urls: ["http://example.com/media/a688346.jpg", "http://example.com/media/fb1f4d.jpg"]
        })
        |> json_response_and_validate_schema(200)

      assert response["urls"] == [
               "http://example.com/media/a688346.jpg",
               "http://example.com/media/fb1f4d.jpg"
             ]
    end
  end
end