Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.6KB

  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: :get, url: "http://example.com/hello"} ->
  18. %Tesla.Env{status: 200, body: "hello"}
  19. %{method: :post, url: "http://example.com/world"} ->
  20. %Tesla.Env{status: 200, body: "world"}
  21. end)
  22. :ok
  23. end
  24. describe "get/1" do
  25. test "returns successfully result" do
  26. assert HTTP.get("http://example.com/hello") == {
  27. :ok,
  28. %Tesla.Env{status: 200, body: "hello"}
  29. }
  30. end
  31. end
  32. describe "get/2 (with headers)" do
  33. test "returns successfully result for json content-type" do
  34. assert HTTP.get("http://example.com/hello", [{"content-type", "application/json"}]) ==
  35. {
  36. :ok,
  37. %Tesla.Env{
  38. status: 200,
  39. body: "{\"my\":\"data\"}",
  40. headers: [{"content-type", "application/json"}]
  41. }
  42. }
  43. end
  44. end
  45. describe "post/2" do
  46. test "returns successfully result" do
  47. assert HTTP.post("http://example.com/world", "") == {
  48. :ok,
  49. %Tesla.Env{status: 200, body: "world"}
  50. }
  51. end
  52. end
  53. end