Fix MRF policies to also work with Update
[akkoma] / test / pleroma / web / uploader_controller_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.UploaderControllerTest do
6 use Pleroma.Web.ConnCase, async: true
7 alias Pleroma.Uploaders.Uploader
8
9 describe "callback/2" do
10 test "it returns 400 response when process callback isn't alive", %{conn: conn} do
11 res =
12 conn
13 |> post(uploader_path(conn, :callback, "test-path"))
14
15 assert res.status == 400
16 assert res.resp_body == "{\"error\":\"bad request\"}"
17 end
18
19 test "it returns success result", %{conn: conn} do
20 task =
21 Task.async(fn ->
22 receive do
23 {Uploader, pid, conn, _params} ->
24 conn =
25 conn
26 |> put_status(:ok)
27 |> Phoenix.Controller.json(%{upload_path: "test-path"})
28
29 send(pid, {Uploader, conn})
30 end
31 end)
32
33 :global.register_name({Uploader, "test-path"}, task.pid)
34
35 res =
36 conn
37 |> post(uploader_path(conn, :callback, "test-path"))
38 |> json_response(200)
39
40 assert res == %{"upload_path" => "test-path"}
41 end
42 end
43 end