logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

http_test.exs (1912B)


  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. defmodule Pleroma.HTTPTest do
  5. use ExUnit.Case, async: true
  6. use Pleroma.Tests.Helpers
  7. import Tesla.Mock
  8. alias Pleroma.HTTP
  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. %{method: :head, url: "http://example.com/hello"} ->
  18. %Tesla.Env{status: 200, body: ""}
  19. %{method: :get, url: "http://example.com/hello"} ->
  20. %Tesla.Env{status: 200, body: "hello"}
  21. %{method: :post, url: "http://example.com/world"} ->
  22. %Tesla.Env{status: 200, body: "world"}
  23. end)
  24. :ok
  25. end
  26. describe "head/1" do
  27. test "returns successfully result" do
  28. assert HTTP.head("http://example.com/hello") == {:ok, %Tesla.Env{status: 200, body: ""}}
  29. end
  30. end
  31. describe "get/1" do
  32. test "returns successfully result" do
  33. assert HTTP.get("http://example.com/hello") == {
  34. :ok,
  35. %Tesla.Env{status: 200, body: "hello"}
  36. }
  37. end
  38. end
  39. describe "get/2 (with headers)" do
  40. test "returns successfully result for json content-type" do
  41. assert HTTP.get("http://example.com/hello", [{"content-type", "application/json"}]) ==
  42. {
  43. :ok,
  44. %Tesla.Env{
  45. status: 200,
  46. body: "{\"my\":\"data\"}",
  47. headers: [{"content-type", "application/json"}]
  48. }
  49. }
  50. end
  51. end
  52. describe "post/2" do
  53. test "returns successfully result" do
  54. assert HTTP.post("http://example.com/world", "") == {
  55. :ok,
  56. %Tesla.Env{status: 200, body: "world"}
  57. }
  58. end
  59. end
  60. end