1 defmodule Pleroma.Akkoma.FrontendSettingsProfileTest do
2 use Pleroma.DataCase, async: true
3 use Oban.Testing, repo: Pleroma.Repo
4 alias Pleroma.Akkoma.FrontendSettingsProfile
8 describe "changeset/2" do
11 frontend_name = "test"
13 settings = %{"test" => "test"}
14 struct = %FrontendSettingsProfile{}
18 frontend_name: frontend_name,
19 profile_name: profile_name,
24 assert %{valid?: true} = FrontendSettingsProfile.changeset(struct, attrs)
27 test "when settings is too long" do
28 clear_config([:instance, :max_frontend_settings_json_chars], 10)
30 frontend_name = "test"
32 settings = %{"verylong" => "verylongoops"}
33 struct = %FrontendSettingsProfile{}
37 frontend_name: frontend_name,
38 profile_name: profile_name,
43 assert %{valid?: false, errors: [settings: {"is too long", _}]} =
44 FrontendSettingsProfile.changeset(struct, attrs)
47 test "when frontend name is too short" do
51 settings = %{"test" => "test"}
52 struct = %FrontendSettingsProfile{}
56 frontend_name: frontend_name,
57 profile_name: profile_name,
62 assert %{valid?: false, errors: [frontend_name: {"can't be blank", _}]} =
63 FrontendSettingsProfile.changeset(struct, attrs)
66 test "when profile name is too short" do
68 frontend_name = "test"
70 settings = %{"test" => "test"}
71 struct = %FrontendSettingsProfile{}
75 frontend_name: frontend_name,
76 profile_name: profile_name,
81 assert %{valid?: false, errors: [profile_name: {"can't be blank", _}]} =
82 FrontendSettingsProfile.changeset(struct, attrs)
85 test "when version is negative" do
87 frontend_name = "test"
89 settings = %{"test" => "test"}
90 struct = %FrontendSettingsProfile{}
94 frontend_name: frontend_name,
95 profile_name: profile_name,
100 assert %{valid?: false, errors: [version: {"must be greater than %{number}", _}]} =
101 FrontendSettingsProfile.changeset(struct, attrs)
105 describe "create_or_update/2" do
106 test "it should create a new record" do
108 frontend_name = "test"
109 profile_name = "test"
110 settings = %{"test" => "test"}
112 assert {:ok, %FrontendSettingsProfile{}} =
113 FrontendSettingsProfile.create_or_update(
122 test "it should update a record" do
124 frontend_name = "test"
125 profile_name = "test"
127 insert(:frontend_setting_profile,
129 frontend_name: frontend_name,
130 profile_name: profile_name,
131 settings: %{"test" => "test"},
135 settings = %{"test" => "test2"}
137 assert {:ok, %FrontendSettingsProfile{settings: ^settings}} =
138 FrontendSettingsProfile.create_or_update(
148 describe "get_all_by_user_and_frontend_name/2" do
149 test "it should return all records" do
151 frontend_name = "test"
153 insert(:frontend_setting_profile,
155 frontend_name: frontend_name,
156 profile_name: "profileA",
157 settings: %{"test" => "test"},
161 insert(:frontend_setting_profile,
163 frontend_name: frontend_name,
164 profile_name: "profileB",
165 settings: %{"test" => "test"},
169 assert [%FrontendSettingsProfile{profile_name: "profileA"}, %{profile_name: "profileB"}] =
170 FrontendSettingsProfile.get_all_by_user_and_frontend_name(user, frontend_name)
174 describe "get_by_user_and_frontend_name_and_profile_name/3" do
175 test "it should return a record" do
177 frontend_name = "test"
178 profile_name = "profileA"
180 insert(:frontend_setting_profile,
182 frontend_name: frontend_name,
183 profile_name: profile_name,
184 settings: %{"test" => "test"},
188 assert %FrontendSettingsProfile{profile_name: "profileA"} =
189 FrontendSettingsProfile.get_by_user_and_frontend_name_and_profile_name(