1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.OAuth.AppTest do
8 alias Pleroma.Web.OAuth.App
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
20 attrs = %{client_name: "Mastodon-Local", redirect_uris: "."}
21 {:ok, %App{} = app} = App.get_or_make(attrs, ["write"])
22 assert app.scopes == ["write"]
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"]