Merge branch 'develop' into improve-move-notificaions-api
[akkoma] / test / http_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.HTTPTest do
6 use Pleroma.DataCase
7 import Tesla.Mock
8
9 setup do
10 mock(fn
11 %{
12 method: :get,
13 url: "http://example.com/hello",
14 headers: [{"content-type", "application/json"}]
15 } ->
16 json(%{"my" => "data"})
17
18 %{method: :get, url: "http://example.com/hello"} ->
19 %Tesla.Env{status: 200, body: "hello"}
20
21 %{method: :post, url: "http://example.com/world"} ->
22 %Tesla.Env{status: 200, body: "world"}
23 end)
24
25 :ok
26 end
27
28 describe "get/1" do
29 test "returns successfully result" do
30 assert Pleroma.HTTP.get("http://example.com/hello") == {
31 :ok,
32 %Tesla.Env{status: 200, body: "hello"}
33 }
34 end
35 end
36
37 describe "get/2 (with headers)" do
38 test "returns successfully result for json content-type" do
39 assert Pleroma.HTTP.get("http://example.com/hello", [{"content-type", "application/json"}]) ==
40 {
41 :ok,
42 %Tesla.Env{
43 status: 200,
44 body: "{\"my\":\"data\"}",
45 headers: [{"content-type", "application/json"}]
46 }
47 }
48 end
49 end
50
51 describe "post/2" do
52 test "returns successfully result" do
53 assert Pleroma.HTTP.post("http://example.com/world", "") == {
54 :ok,
55 %Tesla.Env{status: 200, body: "world"}
56 }
57 end
58 end
59 end