aboutsummaryrefslogtreecommitdiff
path: root/test/tasks/uploads_test.exs
blob: a76e96df50d2038656a21bf09bd21f8de4634858 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
defmodule Mix.Tasks.Pleroma.UploadsTest do
  alias Pleroma.Upload
  use Pleroma.DataCase

  import Mock

  setup_all do
    Mix.shell(Mix.Shell.Process)

    on_exit(fn ->
      Mix.shell(Mix.Shell.IO)
    end)

    :ok
  end

  describe "running migrate_local" do
    test "uploads migrated" do
      with_mock Upload,
        store: fn %Upload{name: _file, path: _path}, _opts -> {:ok, %{}} end do
        Mix.Tasks.Pleroma.Uploads.run(["migrate_local", "S3"])

        assert_received {:mix_shell, :info, [message]}
        assert message =~ "Migrating files from local"

        assert_received {:mix_shell, :info, [message]}

        assert %{"total_count" => total_count} =
                 Regex.named_captures(~r"^Found (?<total_count>\d+) uploads$", message)

        assert_received {:mix_shell, :info, [message]}

        assert %{"count" => ^total_count, "total_count" => ^total_count} =
                 Regex.named_captures(
                   ~r"^Uploaded (?<count>\d+)/(?<total_count>\d+) files$",
                   message
                 )
      end
    end

    test "nonexistent uploader" do
      assert_raise RuntimeError, ~r/The uploader .* is not an existing/, fn ->
        Mix.Tasks.Pleroma.Uploads.run(["migrate_local", "nonexistent"])
      end
    end
  end
end