Merge remote-tracking branch 'upstream/develop' into registration-workflow
[akkoma] / test / mix / tasks / pleroma / app_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 Mix.Tasks.Pleroma.AppTest do
6 use Pleroma.DataCase, async: true
7
8 setup_all do
9 Mix.shell(Mix.Shell.Process)
10
11 on_exit(fn ->
12 Mix.shell(Mix.Shell.IO)
13 end)
14 end
15
16 describe "creates new app" do
17 test "with default scopes" do
18 name = "Some name"
19 redirect = "https://example.com"
20 Mix.Tasks.Pleroma.App.run(["create", "-n", name, "-r", redirect])
21
22 assert_app(name, redirect, ["read", "write", "follow", "push"])
23 end
24
25 test "with custom scopes" do
26 name = "Another name"
27 redirect = "https://example.com"
28
29 Mix.Tasks.Pleroma.App.run([
30 "create",
31 "-n",
32 name,
33 "-r",
34 redirect,
35 "-s",
36 "read,write,follow,push,admin"
37 ])
38
39 assert_app(name, redirect, ["read", "write", "follow", "push", "admin"])
40 end
41 end
42
43 test "with errors" do
44 Mix.Tasks.Pleroma.App.run(["create"])
45 {:mix_shell, :error, ["Creating failed:"]}
46 {:mix_shell, :error, ["name: can't be blank"]}
47 {:mix_shell, :error, ["redirect_uris: can't be blank"]}
48 end
49
50 defp assert_app(name, redirect, scopes) do
51 app = Repo.get_by(Pleroma.Web.OAuth.App, client_name: name)
52
53 assert_receive {:mix_shell, :info, [message]}
54 assert message == "#{name} successfully created:"
55
56 assert_receive {:mix_shell, :info, [message]}
57 assert message == "App client_id: #{app.client_id}"
58
59 assert_receive {:mix_shell, :info, [message]}
60 assert message == "App client_secret: #{app.client_secret}"
61
62 assert app.scopes == scopes
63 assert app.redirect_uris == redirect
64 end
65 end