1 defmodule Pleroma.HTTP.RequestBuilderTest do
2 use ExUnit.Case, async: true
3 alias Pleroma.HTTP.RequestBuilder
5 describe "headers/2" do
6 test "don't send pleroma user agent" do
7 assert RequestBuilder.headers(%{}, []) == %{headers: []}
10 test "send pleroma user agent" do
11 send = Pleroma.Config.get([:http, :send_user_agent])
12 Pleroma.Config.put([:http, :send_user_agent], true)
15 Pleroma.Config.put([:http, :send_user_agent], send)
18 assert RequestBuilder.headers(%{}, []) == %{
19 headers: [{"User-Agent", Pleroma.Application.user_agent()}]
24 describe "add_optional_params/3" do
25 test "don't add if keyword is empty" do
26 assert RequestBuilder.add_optional_params(%{}, %{}, []) == %{}
29 test "add query parameter" do
30 assert RequestBuilder.add_optional_params(
32 %{query: :query, body: :body, another: :val},
34 {:query, "param1=val1¶m2=val2"},
37 ) == %{query: "param1=val1¶m2=val2", body: "some body"}
41 describe "add_param/4" do
42 test "add file parameter" do
44 body: %Tesla.Multipart{
46 content_type_params: [],
48 %Tesla.Multipart.Part{
51 modes: [:raw, :read_ahead, :read, :binary],
52 path: "some-path/filename.png",
55 dispositions: [name: "filename.png", filename: "filename.png"],
60 } = RequestBuilder.add_param(%{}, :file, "filename.png", "some-path/filename.png")
63 test "add key to body" do
65 body: %Tesla.Multipart{
67 content_type_params: [],
69 %Tesla.Multipart.Part{
71 dispositions: [name: "somekey"],
72 headers: ["Content-Type": "application/json"]
76 } = RequestBuilder.add_param(%{}, :body, "somekey", "someval")
79 test "add form parameter" do
80 assert RequestBuilder.add_param(%{}, :form, "somename", "someval") == %{
81 body: %{"somename" => "someval"}
85 test "add for location" do
86 assert RequestBuilder.add_param(%{}, :some_location, "somekey", "someval") == %{
87 some_location: [{"somekey", "someval"}]