summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/pleroma/uploaders/ipfs_test.exs51
-rw-r--r--test/pleroma/web/activity_pub/activity_pub_test.exs30
2 files changed, 48 insertions, 33 deletions
diff --git a/test/pleroma/uploaders/ipfs_test.exs b/test/pleroma/uploaders/ipfs_test.exs
index cf325b54f..bdf2933ac 100644
--- a/test/pleroma/uploaders/ipfs_test.exs
+++ b/test/pleroma/uploaders/ipfs_test.exs
@@ -14,25 +14,6 @@ defmodule Pleroma.Uploaders.IPFSTest do
alias Pleroma.UnstubbedConfigMock, as: Config
- describe "get_final_url" do
- setup do
- Config
- |> expect(:get, fn [Pleroma.Uploaders.IPFS] ->
- [post_gateway_url: "http://localhost:5001"]
- end)
-
- :ok
- end
-
- test "it returns the final url for put_file" do
- assert IPFS.put_file_endpoint() == "http://localhost:5001/api/v0/add"
- end
-
- test "it returns the final url for delete_file" do
- assert IPFS.delete_file_endpoint() == "http://localhost:5001/api/v0/files/rm"
- end
- end
-
describe "get_file/1" do
setup do
Config
@@ -71,8 +52,8 @@ defmodule Pleroma.Uploaders.IPFSTest do
describe "put_file/1" do
setup do
Config
- |> expect(:get, fn [Pleroma.Uploaders.IPFS] ->
- [post_gateway_url: "http://localhost:5001"]
+ |> expect(:get, fn [Pleroma.Uploaders.IPFS, :post_gateway_url] ->
+ "http://localhost:5001"
end)
file_upload = %Pleroma.Upload{
@@ -92,7 +73,11 @@ defmodule Pleroma.Uploaders.IPFSTest do
test "save file", %{file_upload: file_upload} do
with_mock Pleroma.HTTP,
- post: fn "http://localhost:5001/api/v0/add", _mp, [], params: ["cid-version": "1"] ->
+ post: fn "http://localhost:5001/api/v0/add",
+ _mp,
+ [],
+ params: ["cid-version": "1"],
+ pool: :upload ->
{:ok,
%Tesla.Env{
status: 200,
@@ -107,7 +92,11 @@ defmodule Pleroma.Uploaders.IPFSTest do
test "returns error", %{file_upload: file_upload} do
with_mock Pleroma.HTTP,
- post: fn "http://localhost:5001/api/v0/add", _mp, [], params: ["cid-version": "1"] ->
+ post: fn "http://localhost:5001/api/v0/add",
+ _mp,
+ [],
+ params: ["cid-version": "1"],
+ pool: :upload ->
{:error, "IPFS Gateway upload failed"}
end do
assert capture_log(fn ->
@@ -118,7 +107,11 @@ defmodule Pleroma.Uploaders.IPFSTest do
test "returns error if JSON decode fails", %{file_upload: file_upload} do
with_mock Pleroma.HTTP, [],
- post: fn "http://localhost:5001/api/v0/add", _mp, [], params: ["cid-version": "1"] ->
+ post: fn "http://localhost:5001/api/v0/add",
+ _mp,
+ [],
+ params: ["cid-version": "1"],
+ pool: :upload ->
{:ok, %Tesla.Env{status: 200, body: "invalid"}}
end do
assert capture_log(fn ->
@@ -130,7 +123,11 @@ defmodule Pleroma.Uploaders.IPFSTest do
test "returns error if JSON body doesn't contain Hash key", %{file_upload: file_upload} do
with_mock Pleroma.HTTP, [],
- post: fn "http://localhost:5001/api/v0/add", _mp, [], params: ["cid-version": "1"] ->
+ post: fn "http://localhost:5001/api/v0/add",
+ _mp,
+ [],
+ params: ["cid-version": "1"],
+ pool: :upload ->
{:ok, %Tesla.Env{status: 200, body: "{\"key\": \"value\"}"}}
end do
assert IPFS.put_file(file_upload) == {:error, "JSON doesn't contain Hash key"}
@@ -141,8 +138,8 @@ defmodule Pleroma.Uploaders.IPFSTest do
describe "delete_file/1" do
setup do
Config
- |> expect(:get, fn [Pleroma.Uploaders.IPFS] ->
- [post_gateway_url: "http://localhost:5001"]
+ |> expect(:get, fn [Pleroma.Uploaders.IPFS, :post_gateway_url] ->
+ "http://localhost:5001"
end)
:ok
diff --git a/test/pleroma/web/activity_pub/activity_pub_test.exs b/test/pleroma/web/activity_pub/activity_pub_test.exs
index 524294385..d278125ee 100644
--- a/test/pleroma/web/activity_pub/activity_pub_test.exs
+++ b/test/pleroma/web/activity_pub/activity_pub_test.exs
@@ -291,9 +291,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
body: featured_data,
headers: [{"content-type", "application/activity+json"}]
}
- end)
- Tesla.Mock.mock_global(fn
%{
method: :get,
url: ^object_url
@@ -306,7 +304,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
end)
{:ok, user} = ActivityPub.make_user_from_ap_id(ap_id)
- Process.sleep(50)
+
+ assert_enqueued(
+ worker: Pleroma.Workers.RemoteFetcherWorker,
+ args: %{
+ "op" => "fetch_remote",
+ "id" => object_url,
+ "depth" => 1
+ }
+ )
+
+ # wait for oban
+ Pleroma.Tests.ObanHelpers.perform_all()
assert user.featured_address == featured_url
assert Map.has_key?(user.pinned_objects, object_url)
@@ -368,9 +377,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
body: featured_data,
headers: [{"content-type", "application/activity+json"}]
}
- end)
- Tesla.Mock.mock_global(fn
%{
method: :get,
url: ^object_url
@@ -383,7 +390,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
end)
{:ok, user} = ActivityPub.make_user_from_ap_id(ap_id)
- Process.sleep(50)
+
+ assert_enqueued(
+ worker: Pleroma.Workers.RemoteFetcherWorker,
+ args: %{
+ "op" => "fetch_remote",
+ "id" => object_url,
+ "depth" => 1
+ }
+ )
+
+ # wait for oban
+ Pleroma.Tests.ObanHelpers.perform_all()
assert user.featured_address == featured_url
assert Map.has_key?(user.pinned_objects, object_url)