1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.HTTPTest do
6 use ExUnit.Case, async: true
7 use Pleroma.Tests.Helpers
15 url: "http://example.com/hello",
16 headers: [{"content-type", "application/json"}]
18 json(%{"my" => "data"})
20 %{method: :head, url: "http://example.com/hello"} ->
21 %Tesla.Env{status: 200, body: ""}
23 %{method: :get, url: "http://example.com/hello"} ->
24 %Tesla.Env{status: 200, body: "hello"}
26 %{method: :post, url: "http://example.com/world"} ->
27 %Tesla.Env{status: 200, body: "world"}
34 test "returns successfully result" do
35 assert HTTP.head("http://example.com/hello") == {:ok, %Tesla.Env{status: 200, body: ""}}
40 test "returns successfully result" do
41 assert HTTP.get("http://example.com/hello") == {
43 %Tesla.Env{status: 200, body: "hello"}
48 describe "get/2 (with headers)" do
49 test "returns successfully result for json content-type" do
50 assert HTTP.get("http://example.com/hello", [{"content-type", "application/json"}]) ==
55 body: "{\"my\":\"data\"}",
56 headers: [{"content-type", "application/json"}]
63 test "returns successfully result" do
64 assert HTTP.post("http://example.com/world", "") == {
66 %Tesla.Env{status: 200, body: "world"}