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