possibility to run rollback in test env
[akkoma] / test / pleroma / web / o_auth / 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 Pleroma.Web.OAuth.AppTest do
6 use Pleroma.DataCase
7
8 alias Pleroma.Web.OAuth.App
9 import Pleroma.Factory
10
11 describe "get_or_make/2" do
12 test "gets exist app" do
13 attrs = %{client_name: "Mastodon-Local", redirect_uris: "."}
14 app = insert(:oauth_app, Map.merge(attrs, %{scopes: ["read", "write"]}))
15 {:ok, %App{} = exist_app} = App.get_or_make(attrs, [])
16 assert exist_app == app
17 end
18
19 test "make app" do
20 attrs = %{client_name: "Mastodon-Local", redirect_uris: "."}
21 {:ok, %App{} = app} = App.get_or_make(attrs, ["write"])
22 assert app.scopes == ["write"]
23 end
24
25 test "gets exist app and updates scopes" do
26 attrs = %{client_name: "Mastodon-Local", redirect_uris: "."}
27 app = insert(:oauth_app, Map.merge(attrs, %{scopes: ["read", "write"]}))
28 {:ok, %App{} = exist_app} = App.get_or_make(attrs, ["read", "write", "follow", "push"])
29 assert exist_app.id == app.id
30 assert exist_app.scopes == ["read", "write", "follow", "push"]
31 end
32
33 test "has unique client_id" do
34 insert(:oauth_app, client_name: "", redirect_uris: "", client_id: "boop")
35
36 error =
37 catch_error(insert(:oauth_app, client_name: "", redirect_uris: "", client_id: "boop"))
38
39 assert %Ecto.ConstraintError{} = error
40 assert error.constraint == "apps_client_id_index"
41 assert error.type == :unique
42 end
43 end
44 end