e236ccbbb8701a2e23074f28f10720faa9bca768
[akkoma] / test / tasks / pleroma_test.exs
1 defmodule Mix.PleromaTest do
2 use ExUnit.Case, async: true
3 import Mix.Pleroma
4
5 setup_all do
6 Mix.shell(Mix.Shell.Process)
7
8 on_exit(fn ->
9 Mix.shell(Mix.Shell.IO)
10 end)
11
12 :ok
13 end
14
15 describe "shell_prompt/1" do
16 test "input" do
17 send(self(), {:mix_shell_input, :prompt, "Yes"})
18
19 answer = shell_prompt("Do you want this?")
20 assert_received {:mix_shell, :prompt, [message]}
21 assert message =~ "Do you want this?"
22 assert answer == "Yes"
23 end
24
25 test "with defval" do
26 send(self(), {:mix_shell_input, :prompt, "\n"})
27
28 answer = shell_prompt("Do you want this?", "defval")
29
30 assert_received {:mix_shell, :prompt, [message]}
31 assert message =~ "Do you want this? [defval]"
32 assert answer == "defval"
33 end
34 end
35
36 describe "get_option/3" do
37 test "get from options" do
38 assert get_option([domain: "some-domain.com"], :domain, "Promt") == "some-domain.com"
39 end
40
41 test "get from prompt" do
42 send(self(), {:mix_shell_input, :prompt, "another-domain.com"})
43 assert get_option([], :domain, "Prompt") == "another-domain.com"
44 end
45 end
46 end