diff options
| author | Mark Felder <feld@FreeBSD.org> | 2019-07-15 17:10:27 -0500 | 
|---|---|---|
| committer | Mark Felder <feld@FreeBSD.org> | 2019-07-15 17:10:27 -0500 | 
| commit | ffb4eb9779ddd28ecee84c06e8dc58f4a4daaa38 (patch) | |
| tree | b397d1192c69a7d089c86d41b6e09e89954ea798 /test/http | |
| parent | e912f81c828cc7e1d2c0dff8daed3ad52f407a61 (diff) | |
| parent | 03bcb40883dafa2886110e2b625c4cc5c21106f1 (diff) | |
| download | pleroma-ffb4eb9779ddd28ecee84c06e8dc58f4a4daaa38.tar.gz pleroma-ffb4eb9779ddd28ecee84c06e8dc58f4a4daaa38.zip  | |
Merge branch 'develop' into feature/matstodon-statuses-by-name
Diffstat (limited to 'test/http')
| -rw-r--r-- | test/http/request_builder_test.exs | 95 | 
1 files changed, 95 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..7febe84c5 --- /dev/null +++ b/test/http/request_builder_test.exs @@ -0,0 +1,95 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +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¶m2=val2"}, +                 {:body, "some body"} +               ] +             ) == %{query: "param1=val1¶m2=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  | 
