Merge remote-tracking branch 'MAIN/develop' into feature/jobs
[akkoma] / test / support / http_request_mock.ex
index 4a4566e848899d93ccad5667a062ecbbc4a1824a..3043d2be6953b31686f04ceb2f5ebbf920829c37 100644 (file)
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
 defmodule HttpRequestMock do
   require Logger
 
@@ -13,8 +17,8 @@ defmodule HttpRequestMock do
     with {:ok, res} <- apply(__MODULE__, method, [url, query, body, headers]) do
       res
     else
-      {_, r} = error ->
-        Logger.warn(r)
+      {_, _r} = error ->
+        Logger.warn(r)
         error
     end
   end
@@ -23,6 +27,142 @@ defmodule HttpRequestMock do
   #
   def get(url, query \\ [], body \\ [], headers \\ [])
 
+  def get("https://osada.macgirvin.com/channel/mike", _, _, _) do
+    {:ok,
+     %Tesla.Env{
+       status: 200,
+       body:
+         File.read!("test/fixtures/httpoison_mock/https___osada.macgirvin.com_channel_mike.json")
+     }}
+  end
+
+  def get(
+        "https://osada.macgirvin.com/.well-known/webfinger?resource=acct:mike@osada.macgirvin.com",
+        _,
+        _,
+        Accept: "application/xrd+xml,application/jrd+json"
+      ) do
+    {:ok,
+     %Tesla.Env{
+       status: 200,
+       body: File.read!("test/fixtures/httpoison_mock/mike@osada.macgirvin.com.json")
+     }}
+  end
+
+  def get(
+        "https://social.heldscal.la/.well-known/webfinger?resource=https://social.heldscal.la/user/29191",
+        _,
+        _,
+        Accept: "application/xrd+xml,application/jrd+json"
+      ) do
+    {:ok,
+     %Tesla.Env{
+       status: 200,
+       body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_29191.xml")
+     }}
+  end
+
+  def get("https://pawoo.net/users/pekorino.atom", _, _, _) do
+    {:ok,
+     %Tesla.Env{
+       status: 200,
+       body: File.read!("test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.atom")
+     }}
+  end
+
+  def get(
+        "https://pawoo.net/.well-known/webfinger?resource=acct:https://pawoo.net/users/pekorino",
+        _,
+        _,
+        Accept: "application/xrd+xml,application/jrd+json"
+      ) do
+    {:ok,
+     %Tesla.Env{
+       status: 200,
+       body: File.read!("test/fixtures/httpoison_mock/https___pawoo.net_users_pekorino.xml")
+     }}
+  end
+
+  def get(
+        "https://social.stopwatchingus-heidelberg.de/api/statuses/user_timeline/18330.atom",
+        _,
+        _,
+        _
+      ) do
+    {:ok,
+     %Tesla.Env{
+       status: 200,
+       body: File.read!("test/fixtures/httpoison_mock/atarifrosch_feed.xml")
+     }}
+  end
+
+  def get(
+        "https://social.stopwatchingus-heidelberg.de/.well-known/webfinger?resource=acct:https://social.stopwatchingus-heidelberg.de/user/18330",
+        _,
+        _,
+        Accept: "application/xrd+xml,application/jrd+json"
+      ) do
+    {:ok,
+     %Tesla.Env{
+       status: 200,
+       body: File.read!("test/fixtures/httpoison_mock/atarifrosch_webfinger.xml")
+     }}
+  end
+
+  def get("https://mamot.fr/users/Skruyb.atom", _, _, _) do
+    {:ok,
+     %Tesla.Env{
+       status: 200,
+       body: File.read!("test/fixtures/httpoison_mock/https___mamot.fr_users_Skruyb.atom")
+     }}
+  end
+
+  def get(
+        "https://mamot.fr/.well-known/webfinger?resource=acct:https://mamot.fr/users/Skruyb",
+        _,
+        _,
+        Accept: "application/xrd+xml,application/jrd+json"
+      ) do
+    {:ok,
+     %Tesla.Env{
+       status: 200,
+       body: File.read!("test/fixtures/httpoison_mock/skruyb@mamot.fr.atom")
+     }}
+  end
+
+  def get(
+        "https://social.heldscal.la/.well-known/webfinger?resource=nonexistant@social.heldscal.la",
+        _,
+        _,
+        Accept: "application/xrd+xml,application/jrd+json"
+      ) do
+    {:ok,
+     %Tesla.Env{
+       status: 200,
+       body: File.read!("test/fixtures/httpoison_mock/nonexistant@social.heldscal.la.xml")
+     }}
+  end
+
+  def get("https://squeet.me/xrd/?uri=lain@squeet.me", _, _,
+        Accept: "application/xrd+xml,application/jrd+json"
+      ) do
+    {:ok,
+     %Tesla.Env{
+       status: 200,
+       body: File.read!("test/fixtures/httpoison_mock/lain_squeet.me_webfinger.xml")
+     }}
+  end
+
+  def get("https://mst3k.interlinked.me/users/luciferMysticus", _, _,
+        Accept: "application/activity+json"
+      ) do
+    {:ok,
+     %Tesla.Env{
+       status: 200,
+       body: File.read!("test/fixtures/httpoison_mock/lucifermysticus.json")
+     }}
+  end
+
   def get("https://prismo.news/@mxb", _, _, _) do
     {:ok,
      %Tesla.Env{
@@ -31,8 +171,9 @@ defmodule HttpRequestMock do
      }}
   end
 
-  def get("https://hubzilla.example.org/channel/kaniini",
-    _, _, [Accept: "application/activity+json"]) do
+  def get("https://hubzilla.example.org/channel/kaniini", _, _,
+        Accept: "application/activity+json"
+      ) do
     {:ok,
      %Tesla.Env{
        status: 200,
@@ -40,7 +181,7 @@ defmodule HttpRequestMock do
      }}
   end
 
-  def get("https://niu.moe/users/rye", _, _, [Accept: "application/activity+json"]) do
+  def get("https://niu.moe/users/rye", _, _, Accept: "application/activity+json") do
     {:ok,
      %Tesla.Env{
        status: 200,
@@ -52,13 +193,14 @@ defmodule HttpRequestMock do
     {:ok,
      %Tesla.Env{
        status: 200,
-       body: File.read!(
-         "test/fixtures/httpoison_mock/http___mastodon.example.org_users_admin_status_1234.json"
-       )
+       body:
+         File.read!(
+           "test/fixtures/httpoison_mock/http___mastodon.example.org_users_admin_status_1234.json"
+         )
      }}
   end
 
-  def get("https://puckipedia.com/", _, _, [Accept: "application/activity+json"]) do
+  def get("https://puckipedia.com/", _, _, Accept: "application/activity+json") do
     {:ok,
      %Tesla.Env{
        status: 200,
@@ -66,7 +208,6 @@ defmodule HttpRequestMock do
      }}
   end
 
-
   def get("https://peertube.moe/accounts/7even", _, _, _) do
     {:ok,
      %Tesla.Env{
@@ -99,8 +240,7 @@ defmodule HttpRequestMock do
      }}
   end
 
-
-  def get("http://mastodon.example.org/users/admin", _, _, [Accept: "application/activity+json"]) do
+  def get("http://mastodon.example.org/users/admin", _, _, Accept: "application/activity+json") do
     {:ok,
      %Tesla.Env{
        status: 200,
@@ -108,8 +248,9 @@ defmodule HttpRequestMock do
      }}
   end
 
-  def get("http://mastodon.example.org/@admin/99541947525187367",
-    _, _, [Accept: "application/activity+json"]) do
+  def get("http://mastodon.example.org/@admin/99541947525187367", _, _,
+        Accept: "application/activity+json"
+      ) do
     {:ok,
      %Tesla.Env{
        status: 200,
@@ -125,7 +266,7 @@ defmodule HttpRequestMock do
      }}
   end
 
-  def get("https://mstdn.io/users/mayuutann", _, _, [Accept: "application/activity+json"]) do
+  def get("https://mstdn.io/users/mayuutann", _, _, Accept: "application/activity+json") do
     {:ok,
      %Tesla.Env{
        status: 200,
@@ -133,8 +274,9 @@ defmodule HttpRequestMock do
      }}
   end
 
-  def get("https://mstdn.io/users/mayuutann/statuses/99568293732299394",
-    _, _, [Accept: "application/activity+json"]) do
+  def get("https://mstdn.io/users/mayuutann/statuses/99568293732299394", _, _,
+        Accept: "application/activity+json"
+      ) do
     {:ok,
      %Tesla.Env{
        status: 200,
@@ -142,7 +284,6 @@ defmodule HttpRequestMock do
      }}
   end
 
-
   def get("https://pleroma.soykaf.com/users/lain/feed.atom", _, _, _) do
     {:ok,
      %Tesla.Env{
@@ -512,6 +653,14 @@ defmodule HttpRequestMock do
     {:ok, Tesla.Mock.json(%{"id" => "https://social.heldscal.la/user/23211"}, status: 200)}
   end
 
+  def get("http://example.com/ogp", _, _, _) do
+    {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
+  end
+
+  def get("http://example.com/empty", _, _, _) do
+    {:ok, %Tesla.Env{status: 200, body: "hello"}}
+  end
+
   def get(url, query, body, headers) do
     {:error,
      "Not implemented the mock response for get #{inspect(url)}, #{query}, #{inspect(body)}, #{