logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

uploader_controller_test.exs (1202B)


  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. defmodule Pleroma.Web.UploaderControllerTest do
  5. use Pleroma.Web.ConnCase
  6. alias Pleroma.Uploaders.Uploader
  7. describe "callback/2" do
  8. test "it returns 400 response when process callback isn't alive", %{conn: conn} do
  9. res =
  10. conn
  11. |> post(uploader_path(conn, :callback, "test-path"))
  12. assert res.status == 400
  13. assert res.resp_body == "{\"error\":\"bad request\"}"
  14. end
  15. test "it returns success result", %{conn: conn} do
  16. task =
  17. Task.async(fn ->
  18. receive do
  19. {Uploader, pid, conn, _params} ->
  20. conn =
  21. conn
  22. |> put_status(:ok)
  23. |> Phoenix.Controller.json(%{upload_path: "test-path"})
  24. send(pid, {Uploader, conn})
  25. end
  26. end)
  27. :global.register_name({Uploader, "test-path"}, task.pid)
  28. res =
  29. conn
  30. |> post(uploader_path(conn, :callback, "test-path"))
  31. |> json_response(200)
  32. assert res == %{"upload_path" => "test-path"}
  33. end
  34. end
  35. end