1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.HTTP.RequestBuilderTest do
7 use Pleroma.Tests.Helpers
8 alias Pleroma.HTTP.Request
9 alias Pleroma.HTTP.RequestBuilder
11 describe "headers/2" do
12 test "don't send pleroma user agent" do
13 assert RequestBuilder.headers(%Request{}, []) == %Request{headers: []}
16 test "send pleroma user agent" do
17 clear_config([:http, :send_user_agent], true)
18 clear_config([:http, :user_agent], :default)
20 assert RequestBuilder.headers(%Request{}, []) == %Request{
21 headers: [{"user-agent", Pleroma.Application.user_agent()}]
25 test "send custom user agent" do
26 clear_config([:http, :send_user_agent], true)
27 clear_config([:http, :user_agent], "totally-not-pleroma")
29 assert RequestBuilder.headers(%Request{}, []) == %Request{
30 headers: [{"user-agent", "totally-not-pleroma"}]
35 describe "add_param/4" do
36 test "add file parameter" do
38 body: %Tesla.Multipart{
40 content_type_params: [],
42 %Tesla.Multipart.Part{
45 modes: [:raw, :read_ahead, :read, :binary],
46 path: "some-path/filename.png",
49 dispositions: [name: "filename.png", filename: "filename.png"],
54 } = RequestBuilder.add_param(%Request{}, :file, "filename.png", "some-path/filename.png")
57 test "add key to body" do
59 body: %Tesla.Multipart{
61 content_type_params: [],
63 %Tesla.Multipart.Part{
65 dispositions: [name: "somekey"],
66 headers: [{"content-type", "application/json"}]
70 } = RequestBuilder.add_param(%{}, :body, "somekey", "someval")
73 test "add form parameter" do
74 assert RequestBuilder.add_param(%{}, :form, "somename", "someval") == %{
75 body: %{"somename" => "someval"}
79 test "add for location" do
80 assert RequestBuilder.add_param(%{}, :some_location, "somekey", "someval") == %{
81 some_location: [{"somekey", "someval"}]