summaryrefslogtreecommitdiff
path: root/test/http/request_builder_test.exs
diff options
context:
space:
mode:
authorIvan Tashkinov <ivant.business@gmail.com>2019-07-09 21:46:16 +0300
committerIvan Tashkinov <ivant.business@gmail.com>2019-07-09 21:46:16 +0300
commit829e99722396c2372770f50d9fc7cfa40c441005 (patch)
tree6b72aa4ac5e049eb8bf444ade64e8da4499ef023 /test/http/request_builder_test.exs
parent46cf81a544edd91f4c3893897fbe2db053f5f6d5 (diff)
parent2bb945cb70751bc8e72c036040130bb54c32f391 (diff)
downloadpleroma-829e99722396c2372770f50d9fc7cfa40c441005.tar.gz
pleroma-829e99722396c2372770f50d9fc7cfa40c441005.zip
[#878] Merge remote-tracking branch 'remotes/upstream/develop' into 878-activity-object-decoupling-in-tests
# Conflicts: # lib/pleroma/object.ex # test/web/activity_pub/transmogrifier_test.exs # test/web/ostatus/ostatus_test.exs
Diffstat (limited to 'test/http/request_builder_test.exs')
-rw-r--r--test/http/request_builder_test.exs91
1 files changed, 91 insertions, 0 deletions
diff --git a/test/http/request_builder_test.exs b/test/http/request_builder_test.exs
new file mode 100644
index 000000000..a368999ff
--- /dev/null
+++ b/test/http/request_builder_test.exs
@@ -0,0 +1,91 @@
+defmodule Pleroma.HTTP.RequestBuilderTest do
+ use ExUnit.Case, async: true
+ alias Pleroma.HTTP.RequestBuilder
+
+ describe "headers/2" do
+ test "don't send pleroma user agent" do
+ assert RequestBuilder.headers(%{}, []) == %{headers: []}
+ end
+
+ test "send pleroma user agent" do
+ send = Pleroma.Config.get([:http, :send_user_agent])
+ Pleroma.Config.put([:http, :send_user_agent], true)
+
+ on_exit(fn ->
+ Pleroma.Config.put([:http, :send_user_agent], send)
+ end)
+
+ assert RequestBuilder.headers(%{}, []) == %{
+ headers: [{"User-Agent", Pleroma.Application.user_agent()}]
+ }
+ end
+ end
+
+ describe "add_optional_params/3" do
+ test "don't add if keyword is empty" do
+ assert RequestBuilder.add_optional_params(%{}, %{}, []) == %{}
+ end
+
+ test "add query parameter" do
+ assert RequestBuilder.add_optional_params(
+ %{},
+ %{query: :query, body: :body, another: :val},
+ [
+ {:query, "param1=val1&param2=val2"},
+ {:body, "some body"}
+ ]
+ ) == %{query: "param1=val1&param2=val2", body: "some body"}
+ end
+ end
+
+ describe "add_param/4" do
+ test "add file parameter" do
+ %{
+ body: %Tesla.Multipart{
+ boundary: _,
+ content_type_params: [],
+ parts: [
+ %Tesla.Multipart.Part{
+ body: %File.Stream{
+ line_or_bytes: 2048,
+ modes: [:raw, :read_ahead, :read, :binary],
+ path: "some-path/filename.png",
+ raw: true
+ },
+ dispositions: [name: "filename.png", filename: "filename.png"],
+ headers: []
+ }
+ ]
+ }
+ } = RequestBuilder.add_param(%{}, :file, "filename.png", "some-path/filename.png")
+ end
+
+ test "add key to body" do
+ %{
+ body: %Tesla.Multipart{
+ boundary: _,
+ content_type_params: [],
+ parts: [
+ %Tesla.Multipart.Part{
+ body: "\"someval\"",
+ dispositions: [name: "somekey"],
+ headers: ["Content-Type": "application/json"]
+ }
+ ]
+ }
+ } = RequestBuilder.add_param(%{}, :body, "somekey", "someval")
+ end
+
+ test "add form parameter" do
+ assert RequestBuilder.add_param(%{}, :form, "somename", "someval") == %{
+ body: %{"somename" => "someval"}
+ }
+ end
+
+ test "add for location" do
+ assert RequestBuilder.add_param(%{}, :some_location, "somekey", "someval") == %{
+ some_location: [{"somekey", "someval"}]
+ }
+ end
+ end
+end