Merge branch 'develop' into dtluna/pleroma-feature/unfollow-activity
[akkoma] / test / support / httpoison_mock.ex
1 defmodule HTTPoisonMock do
2 alias HTTPoison.Response
3
4 def get(url, body \\ [], headers \\ [])
5
6 def get("https://social.heldscal.la/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "nonexistant@social.heldscal.la"]]) do
7 {:ok, %Response{
8 status_code: 500,
9 body: File.read!("test/fixtures/httpoison_mock/nonexistant@social.heldscal.la.xml")
10 }}
11 end
12
13 def get("https://social.heldscal.la/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "shp@social.heldscal.la"]]) do
14 {:ok, %Response{
15 status_code: 200,
16 body: File.read!("test/fixtures/httpoison_mock/shp@social.heldscal.la.xml")
17 }}
18 end
19
20 def get("https://social.heldscal.la/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "https://social.heldscal.la/user/23211"]]) do
21 {:ok, %Response{
22 status_code: 200,
23 body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_23211.xml")
24 }}
25 end
26
27 def get("https://social.heldscal.la/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "https://social.heldscal.la/user/29191"]]) do
28 {:ok, %Response{
29 status_code: 200,
30 body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_user_29191.xml")
31 }}
32 end
33
34 def get("https://mastodon.social/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "https://mastodon.social/users/lambadalambda"]]) do
35 {:ok, %Response{
36 status_code: 200,
37 body: File.read!("test/fixtures/httpoison_mock/https___mastodon.social_users_lambadalambda.xml")
38 }}
39 end
40
41 def get("https://shitposter.club/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "https://shitposter.club/user/1"]]) do
42 {:ok, %Response{
43 status_code: 200,
44 body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_user_1.xml")
45 }}
46 end
47
48 def get("http://gs.example.org/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "http://gs.example.org:4040/index.php/user/1"], follow_redirect: true]) do
49 {:ok, %Response{
50 status_code: 200,
51 body: File.read!("test/fixtures/httpoison_mock/http___gs.example.org_4040_index.php_user_1.xml")
52 }}
53 end
54
55 def get("https://pleroma.soykaf.com/.well-known/webfinger", [Accept: "application/xrd+xml"], [params: [resource: "https://pleroma.soykaf.com/users/lain"]]) do
56 {:ok, %Response{
57 status_code: 200,
58 body: File.read!("test/fixtures/httpoison_mock/https___pleroma.soykaf.com_users_lain.xml")
59 }}
60 end
61
62 def get("https://social.heldscal.la/api/statuses/user_timeline/29191.atom", _body, _headers) do
63 {:ok, %Response{
64 status_code: 200,
65 body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_api_statuses_user_timeline_29191.atom.xml")
66 }}
67 end
68
69 def get("https://social.heldscal.la/api/statuses/user_timeline/23211.atom", _body, _headers) do
70 {:ok, %Response{
71 status_code: 200,
72 body: File.read!("test/fixtures/httpoison_mock/https___social.heldscal.la_api_statuses_user_timeline_23211.atom.xml")
73 }}
74 end
75
76 def get("https://mastodon.social/users/lambadalambda.atom", _body, _headers) do
77 {:ok, %Response{
78 status_code: 200,
79 body: File.read!("test/fixtures/httpoison_mock/https___mastodon.social_users_lambadalambda.atom")
80 }}
81 end
82
83 def get("https://pleroma.soykaf.com/users/lain/feed.atom", _body, _headers) do
84 {:ok, %Response{
85 status_code: 200,
86 body: File.read!("test/fixtures/httpoison_mock/https___pleroma.soykaf.com_users_lain_feed.atom.xml")
87 }}
88 end
89
90 def get("http://gs.example.org/index.php/api/statuses/user_timeline/1.atom", _body, _headers) do
91 {:ok, %Response{
92 status_code: 200,
93 body: File.read!("test/fixtures/httpoison_mock/http__gs.example.org_index.php_api_statuses_user_timeline_1.atom.xml")
94 }}
95 end
96
97 def get("https://shitposter.club/notice/2827873", _body, _headers) do
98 {:ok, %Response{
99 status_code: 200,
100 body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_notice_2827873.html")
101 }}
102 end
103
104 def get("https://shitposter.club/api/statuses/show/2827873.atom", _body, _headers) do
105 {:ok, %Response{
106 status_code: 200,
107 body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_api_statuses_show_2827873.atom.xml")
108 }}
109 end
110
111 def get("https://shitposter.club/api/statuses/user_timeline/1.atom", _body, _headers) do
112 {:ok, %Response{
113 status_code: 200,
114 body: File.read!("test/fixtures/httpoison_mock/https___shitposter.club_api_statuses_user_timeline_1.atom.xml")
115 }}
116 end
117
118 def get(url, body, headers) do
119 {:error, "Not implemented the mock response for get #{inspect(url)}"}
120 end
121
122 def post(url, body, headers) do
123 {:error, "Not implemented the mock response for post #{inspect(url)}"}
124 end
125 end