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