Merge remote-tracking branch 'origin' into follower-hiding
[akkoma] / test / http_test.exs
1 defmodule Pleroma.HTTPTest do
2 use Pleroma.DataCase
3 import Tesla.Mock
4
5 setup do
6 mock(fn
7 %{
8 method: :get,
9 url: "http://example.com/hello",
10 headers: [{"content-type", "application/json"}]
11 } ->
12 json(%{"my" => "data"})
13
14 %{method: :get, url: "http://example.com/hello"} ->
15 %Tesla.Env{status: 200, body: "hello"}
16
17 %{method: :post, url: "http://example.com/world"} ->
18 %Tesla.Env{status: 200, body: "world"}
19 end)
20
21 :ok
22 end
23
24 describe "get/1" do
25 test "returns successfully result" do
26 assert Pleroma.HTTP.get("http://example.com/hello") == {
27 :ok,
28 %Tesla.Env{status: 200, body: "hello"}
29 }
30 end
31 end
32
33 describe "get/2 (with headers)" do
34 test "returns successfully result for json content-type" do
35 assert Pleroma.HTTP.get("http://example.com/hello", [{"content-type", "application/json"}]) ==
36 {
37 :ok,
38 %Tesla.Env{
39 status: 200,
40 body: "{\"my\":\"data\"}",
41 headers: [{"content-type", "application/json"}]
42 }
43 }
44 end
45 end
46
47 describe "post/2" do
48 test "returns successfully result" do
49 assert Pleroma.HTTP.post("http://example.com/world", "") == {
50 :ok,
51 %Tesla.Env{status: 200, body: "world"}
52 }
53 end
54 end
55 end