Merge pull request 'docs: fedora install errata' (#398) from acuteaura/akkoma:acuteau...
[akkoma] / test / pleroma / http_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.HTTPTest do
6 use ExUnit.Case, async: true
7 use Pleroma.Tests.Helpers
8 import Tesla.Mock
9 alias Pleroma.HTTP
10
11 setup do
12 clear_config([:http, :send_user_agent], false)
13
14 mock(fn
15 %{
16 method: :get,
17 url: "http://example.com/hello",
18 headers: [{"content-type", "application/json"}]
19 } ->
20 json(%{"my" => "data"})
21
22 %{method: :head, url: "http://example.com/hello"} ->
23 %Tesla.Env{status: 200, body: ""}
24
25 %{method: :get, url: "http://example.com/hello"} ->
26 %Tesla.Env{status: 200, body: "hello"}
27
28 %{method: :post, url: "http://example.com/world"} ->
29 %Tesla.Env{status: 200, body: "world"}
30 end)
31
32 :ok
33 end
34
35 describe "head/1" do
36 test "returns successfully result" do
37 assert HTTP.head("http://example.com/hello") == {:ok, %Tesla.Env{status: 200, body: ""}}
38 end
39 end
40
41 describe "get/1" do
42 test "returns successfully result" do
43 assert HTTP.get("http://example.com/hello") == {
44 :ok,
45 %Tesla.Env{status: 200, body: "hello"}
46 }
47 end
48 end
49
50 describe "get/2 (with headers)" do
51 test "returns successfully result for json content-type" do
52 assert HTTP.get("http://example.com/hello", [{"content-type", "application/json"}]) ==
53 {
54 :ok,
55 %Tesla.Env{
56 status: 200,
57 body: "{\"my\":\"data\"}",
58 headers: [{"content-type", "application/json"}]
59 }
60 }
61 end
62 end
63
64 describe "post/2" do
65 test "returns successfully result" do
66 assert HTTP.post("http://example.com/world", "") == {
67 :ok,
68 %Tesla.Env{status: 200, body: "world"}
69 }
70 end
71 end
72 end