1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Mix.Tasks.Pleroma.AppTest do
6 use Pleroma.DataCase, async: true
9 Mix.shell(Mix.Shell.Process)
12 Mix.shell(Mix.Shell.IO)
16 describe "creates new app" do
17 test "with default scopes" do
19 redirect = "https://example.com"
20 Mix.Tasks.Pleroma.App.run(["create", "-n", name, "-r", redirect])
22 assert_app(name, redirect, ["read", "write", "follow", "push"])
25 test "with custom scopes" do
27 redirect = "https://example.com"
29 Mix.Tasks.Pleroma.App.run([
36 "read,write,follow,push,admin"
39 assert_app(name, redirect, ["read", "write", "follow", "push", "admin"])
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"]}
50 defp assert_app(name, redirect, scopes) do
51 app = Repo.get_by(Pleroma.Web.OAuth.App, client_name: name)
53 assert_received {:mix_shell, :info, [message]}
54 assert message == "#{name} successfully created:"
56 assert_received {:mix_shell, :info, [message]}
57 assert message == "App client_id: #{app.client_id}"
59 assert_received {:mix_shell, :info, [message]}
60 assert message == "App client_secret: #{app.client_secret}"
62 assert app.scopes == scopes
63 assert app.redirect_uris == redirect