diff options
author | Maksim <parallel588@gmail.com> | 2019-07-18 12:30:18 +0000 |
---|---|---|
committer | kaniini <ariadne@dereferenced.org> | 2019-07-18 12:30:18 +0000 |
commit | b6b748d3e7f3383303a2fcccb17b7b0f7054100f (patch) | |
tree | d053d9e529254abc5f1a3b290b9444f3cf31ea6d /test/web/uploader_controller_test.exs | |
parent | e2c39e1cc077c77f3bd8325b99e9a21d42b8133e (diff) | |
download | pleroma-b6b748d3e7f3383303a2fcccb17b7b0f7054100f.tar.gz |
tests for Uploader with webhook
Diffstat (limited to 'test/web/uploader_controller_test.exs')
-rw-r--r-- | test/web/uploader_controller_test.exs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/web/uploader_controller_test.exs b/test/web/uploader_controller_test.exs new file mode 100644 index 000000000..70028df1c --- /dev/null +++ b/test/web/uploader_controller_test.exs @@ -0,0 +1,43 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.UploaderControllerTest do + use Pleroma.Web.ConnCase + alias Pleroma.Uploaders.Uploader + + describe "callback/2" do + test "it returns 400 response when process callback isn't alive", %{conn: conn} do + res = + conn + |> post(uploader_path(conn, :callback, "test-path")) + + assert res.status == 400 + assert res.resp_body == "{\"error\":\"bad request\"}" + end + + test "it returns success result", %{conn: conn} do + task = + Task.async(fn -> + receive do + {Uploader, pid, conn, _params} -> + conn = + conn + |> put_status(:ok) + |> Phoenix.Controller.json(%{upload_path: "test-path"}) + + send(pid, {Uploader, conn}) + end + end) + + :global.register_name({Uploader, "test-path"}, task.pid) + + res = + conn + |> post(uploader_path(conn, :callback, "test-path")) + |> json_response(200) + + assert res == %{"upload_path" => "test-path"} + end + end +end |