1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 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
39 body: %Tesla.Multipart{
41 content_type_params: [],
43 %Tesla.Multipart.Part{
46 modes: [:raw, :read_ahead, :binary],
47 path: "some-path/filename.png",
50 dispositions: [name: "filename.png", filename: "filename.png"],
56 RequestBuilder.add_param(
60 "some-path/filename.png"
65 test "add key to body" do
67 body: %Tesla.Multipart{
69 content_type_params: [],
71 %Tesla.Multipart.Part{
73 dispositions: [name: "somekey"],
74 headers: [{"content-type", "application/json"}]
78 } = RequestBuilder.add_param(%{}, :body, "somekey", "someval")
81 test "add form parameter" do
82 assert RequestBuilder.add_param(%{}, :form, "somename", "someval") == %{
83 body: %{"somename" => "someval"}
87 test "add for location" do
88 assert RequestBuilder.add_param(%{}, :some_location, "somekey", "someval") == %{
89 some_location: [{"somekey", "someval"}]