move to 2.5.5
[anni] / test / pleroma / upload / filter / mogrify_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Upload.Filter.MogrifyTest do
6   use Pleroma.DataCase
7   import Mock
8
9   alias Pleroma.Upload.Filter
10
11   test "apply mogrify filter" do
12     clear_config(Filter.Mogrify, args: [{"tint", "40"}])
13
14     File.cp!(
15       "test/fixtures/image.jpg",
16       "test/fixtures/image_tmp.jpg"
17     )
18
19     upload = %Pleroma.Upload{
20       name: "an… image.jpg",
21       content_type: "image/jpeg",
22       path: Path.absname("test/fixtures/image_tmp.jpg"),
23       tempfile: Path.absname("test/fixtures/image_tmp.jpg")
24     }
25
26     task =
27       Task.async(fn ->
28         assert_receive {:apply_filter, {_, "tint", "40"}}, 4_000
29       end)
30
31     with_mock Mogrify,
32       open: fn _f -> %Mogrify.Image{} end,
33       custom: fn _m, _a -> :ok end,
34       custom: fn m, a, o -> send(task.pid, {:apply_filter, {m, a, o}}) end,
35       save: fn _f, _o -> :ok end do
36       assert Filter.Mogrify.filter(upload) == {:ok, :filtered}
37     end
38
39     Task.await(task)
40   end
41 end