diff options
author | Claudio Maradonna <penguyman@stronzi.org> | 2022-06-09 19:24:13 +0200 |
---|---|---|
committer | Claudio Maradonna <penguyman@stronzi.org> | 2022-07-07 06:29:15 +0200 |
commit | 98f268e5ecc5bab98c98270a582f8b3f0e3be4e8 (patch) | |
tree | d654efc3acc4f1b37678b1fd90c57d259e889d3a /test | |
parent | 7c1af86f979ecebcd38995e5278fe2d59a36eda5 (diff) | |
download | pleroma-98f268e5ecc5bab98c98270a582f8b3f0e3be4e8.tar.gz pleroma-98f268e5ecc5bab98c98270a582f8b3f0e3be4e8.zip |
ipfs: small refactor and more tests
Diffstat (limited to 'test')
-rw-r--r-- | test/pleroma/uploaders/ipfs_test.exs | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/test/pleroma/uploaders/ipfs_test.exs b/test/pleroma/uploaders/ipfs_test.exs index d567272d2..f2b880d9f 100644 --- a/test/pleroma/uploaders/ipfs_test.exs +++ b/test/pleroma/uploaders/ipfs_test.exs @@ -25,11 +25,11 @@ defmodule Pleroma.Uploaders.IPFSTest do describe "get_final_url" do test "it returns the final url for put_file" do - assert IPFS.get_final_url("/api/v0/add") == "http://localhost:5001/api/v0/add" + assert IPFS.put_file_endpoint() == "http://localhost:5001/api/v0/add" end test "it returns the final url for delete_file" do - assert IPFS.get_final_url("/api/v0/files/rm") == "http://localhost:5001/api/v0/files/rm" + assert IPFS.delete_file_endpoint() == "http://localhost:5001/api/v0/files/rm" end end @@ -88,6 +88,26 @@ defmodule Pleroma.Uploaders.IPFSTest do end) =~ "Elixir.Pleroma.Uploaders.IPFS: {:error, \"IPFS Gateway upload failed\"}" end end + + test "returns error if JSON decode fails", %{file_upload: file_upload} do + with_mocks([ + {Pleroma.HTTP, [], [post: fn _, _, _, _ -> {:ok, %Tesla.Env{status: 200, body: ''}} end]}, + {Jason, [], [decode: fn _ -> {:error, "JSON decode failed"} end]} + ]) do + assert capture_log(fn -> + assert IPFS.put_file(file_upload) == {:error, "JSON decode failed"} + end) =~ "Elixir.Pleroma.Uploaders.IPFS: {:error, \"JSON decode failed\"}" + end + end + + test "returns error if JSON body doesn't contain Hash key", %{file_upload: file_upload} do + with_mocks([ + {Pleroma.HTTP, [], [post: fn _, _, _, _ -> {:ok, %Tesla.Env{status: 200, body: ''}} end]}, + {Jason, [], [decode: fn _ -> {:ok, %{}} end]} + ]) do + assert IPFS.put_file(file_upload) == {:error, "JSON doesn't contain Hash key"} + end + end end describe "delete_file/1" do |