1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.PleromaAPI.SettingsControllerTest do
6 use Pleroma.Web.ConnCase
10 describe "GET /api/v1/pleroma/settings/:app" do
12 oauth_access(["read:accounts"])
15 test "it gets empty settings", %{conn: conn} do
18 |> get("/api/v1/pleroma/settings/pleroma-fe")
19 |> json_response_and_validate_schema(:ok)
21 assert response == %{}
24 test "it gets settings", %{conn: conn, user: user} do
30 pleroma_settings_store: %{
37 |> get("/api/v1/pleroma/settings/pleroma-fe")
38 |> json_response_and_validate_schema(:ok)
40 assert %{"foo" => "bar"} == response
44 describe "POST /api/v1/pleroma/settings/:app" do
57 pleroma_settings_store: %{
58 "pleroma-fe" => settings
63 %{conn: conn} = oauth_access(["write:accounts"], user: user)
65 %{conn: conn, user: user, settings: settings}
68 test "it adds keys", %{conn: conn} do
71 |> put_req_header("content-type", "application/json")
72 |> patch("/api/v1/pleroma/settings/pleroma-fe", %{
75 "nested" => %{"3" => "4"}
77 |> json_response_and_validate_schema(:ok)
89 test "it removes keys", %{conn: conn} do
92 |> put_req_header("content-type", "application/json")
93 |> patch("/api/v1/pleroma/settings/pleroma-fe", %{
101 |> json_response_and_validate_schema(:ok)
103 assert response == %{
108 test "it does not override settings for other apps", %{
114 |> put_req_header("content-type", "application/json")
115 |> patch("/api/v1/pleroma/settings/admin-fe", %{"foo" => "bar"})
116 |> json_response_and_validate_schema(:ok)
118 user = Pleroma.User.get_by_id(user.id)
120 assert user.pleroma_settings_store == %{
121 "pleroma-fe" => settings,
122 "admin-fe" => %{"foo" => "bar"}