logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

mdii_test.exs (1488B)


      1 # Pleroma: A lightweight social networking server
      2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
      3 # SPDX-License-Identifier: AGPL-3.0-only
      4 
      5 defmodule Pleroma.Uploaders.MDIITest do
      6   use Pleroma.DataCase
      7   alias Pleroma.Uploaders.MDII
      8   import Tesla.Mock
      9 
     10   describe "get_file/1" do
     11     test "it returns path to local folder for files" do
     12       assert MDII.get_file("") == {:ok, {:static_dir, "test/uploads"}}
     13     end
     14   end
     15 
     16   describe "put_file/1" do
     17     setup do
     18       file_upload = %Pleroma.Upload{
     19         name: "mdii-image.jpg",
     20         content_type: "image/jpg",
     21         path: "test_folder/mdii-image.jpg",
     22         tempfile: Path.absname("test/fixtures/image_tmp.jpg")
     23       }
     24 
     25       [file_upload: file_upload]
     26     end
     27 
     28     test "save file", %{file_upload: file_upload} do
     29       mock(fn
     30         %{method: :post, url: "https://mdii.sakura.ne.jp/mdii-post.cgi?jpg"} ->
     31           %Tesla.Env{status: 200, body: "mdii-image"}
     32       end)
     33 
     34       assert MDII.put_file(file_upload) ==
     35                {:ok, {:url, "https://mdii.sakura.ne.jp/mdii-image.jpg"}}
     36     end
     37 
     38     test "save file to local if MDII  isn`t available", %{file_upload: file_upload} do
     39       mock(fn
     40         %{method: :post, url: "https://mdii.sakura.ne.jp/mdii-post.cgi?jpg"} ->
     41           %Tesla.Env{status: 500}
     42       end)
     43 
     44       assert MDII.put_file(file_upload) == :ok
     45 
     46       assert Path.join([Pleroma.Uploaders.Local.upload_path(), file_upload.path])
     47              |> File.exists?()
     48     end
     49   end
     50 end