fix emoji tests
[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 mock(fn
14 %{
15 method: :get,
16 url: "http://example.com/hello",
17 headers: [{"content-type", "application/json"}]
18 } ->
19 json(%{"my" => "data"})
20
21 %{method: :head, url: "http://example.com/hello"} ->
22 %Tesla.Env{status: 200, body: ""}
23
24 %{method: :get, url: "http://example.com/hello"} ->
25 %Tesla.Env{status: 200, body: "hello"}
26
27 %{method: :post, url: "http://example.com/world"} ->
28 %Tesla.Env{status: 200, body: "world"}
29 end)
30
31 :ok
32 end
33
34 describe "head/1" do
35 test "returns successfully result" do
36 assert HTTP.head("http://example.com/hello") == {:ok, %Tesla.Env{status: 200, body: ""}}
37 end
38 end
39
40 describe "get/1" do
41 test "returns successfully result" do
42 assert HTTP.get("http://example.com/hello") == {
43 :ok,
44 %Tesla.Env{status: 200, body: "hello"}
45 }
46 end
47 end
48
49 describe "get/2 (with headers)" do
50 test "returns successfully result for json content-type" do
51 assert HTTP.get("http://example.com/hello", [{"content-type", "application/json"}]) ==
52 {
53 :ok,
54 %Tesla.Env{
55 status: 200,
56 body: "{\"my\":\"data\"}",
57 headers: [{"content-type", "application/json"}]
58 }
59 }
60 end
61 end
62
63 describe "post/2" do
64 test "returns successfully result" do
65 assert HTTP.post("http://example.com/world", "") == {
66 :ok,
67 %Tesla.Env{status: 200, body: "world"}
68 }
69 end
70 end
71 end