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.Docs.GeneratorTest do
6 use ExUnit.Case, async: true
7 alias Pleroma.Docs.Generator
20 suggestions: {:list_behaviour_implementations, Pleroma.Upload.Filter}
24 type: {:list, :module},
26 suggestions: {:list_behaviour_implementations, Pleroma.Web.ActivityPub.MRF.Policy}
47 key: :another_key_with_label,
48 label: "Another label",
62 {:tuple, "string", 8080},
63 [:atom, Pleroma.Upload, {:atom, Pleroma.Upload}]
68 label: "Special Label",
74 group: {:subgroup, Swoosh.Adapters.SMTP},
77 description: "`Swoosh.Adapters.SMTP` adapter specific setting",
78 suggestions: [:always, :never, :if_available]
81 key: "application/xml",
82 type: {:list, :string},
88 description: "List of TLS version to use",
89 suggestions: [:tlsv1, ":tlsv1.1", ":tlsv1.2", ":tlsv1.3"]
102 children: [%{key: :key1, type: :string, suggestions: [""]}]
104 %{group: "Some string group", key: "Some string key", type: :group}
107 describe "convert_to_strings/1" do
108 test "group, key, label" do
109 [desc1, desc2 | _] = Generator.convert_to_strings(@descriptions)
111 assert desc1[:group] == ":pleroma"
112 assert desc1[:key] == "Pleroma.Upload"
113 assert desc1[:label] == "Pleroma.Upload"
115 assert desc2[:group] == ":tesla"
116 assert desc2[:key] == ":adapter"
117 assert desc2[:label] == "Adapter"
120 test "group without key" do
121 descriptions = Generator.convert_to_strings(@descriptions)
122 desc = Enum.at(descriptions, 2)
124 assert desc[:group] == ":cors_plug"
126 assert desc[:label] == "Cors plug"
129 test "children key, label, type" do
130 [%{children: [child1, child2, child3, child4 | _]} | _] =
131 Generator.convert_to_strings(@descriptions)
133 assert child1[:key] == ":uploader"
134 assert child1[:label] == "Uploader"
135 assert child1[:type] == :module
137 assert child2[:key] == ":filters"
138 assert child2[:label] == "Filters"
139 assert child2[:type] == {:list, :module}
141 assert child3[:key] == "Pleroma.Upload"
142 assert child3[:label] == "Pleroma.Upload"
143 assert child3[:type] == :string
145 assert child4[:key] == ":some_key"
146 assert child4[:label] == "Some key"
147 assert child4[:type] == :keyword
150 test "child with predefined label" do
151 [%{children: children} | _] = Generator.convert_to_strings(@descriptions)
152 child = Enum.at(children, 5)
153 assert child[:key] == "Pleroma.Upload"
154 assert child[:label] == "Special Label"
158 [%{children: children} | _] = Generator.convert_to_strings(@descriptions)
159 child = Enum.at(children, 3)
160 %{children: [subchild | _]} = child
162 assert subchild[:key] == ":another_key"
163 assert subchild[:label] == "Another key"
164 assert subchild[:type] == :integer
167 test "subchild with predefined label" do
168 [%{children: children} | _] = Generator.convert_to_strings(@descriptions)
169 child = Enum.at(children, 3)
170 %{children: subchildren} = child
171 subchild = Enum.at(subchildren, 1)
173 assert subchild[:key] == ":another_key_with_label"
174 assert subchild[:label] == "Another label"
177 test "module suggestions" do
178 [%{children: [%{suggestions: suggestions} | _]} | _] =
179 Generator.convert_to_strings(@descriptions)
181 Enum.each(suggestions, fn suggestion ->
182 assert String.starts_with?(suggestion, "Pleroma.")
186 test "atoms in suggestions with leading `:`" do
187 [%{children: children} | _] = Generator.convert_to_strings(@descriptions)
188 %{suggestions: suggestions} = Enum.at(children, 4)
189 assert Enum.at(suggestions, 0) == ":atom"
190 assert Enum.at(suggestions, 1) == "Pleroma.Upload"
191 assert Enum.at(suggestions, 2) == {":tuple", "string", 8080}
192 assert Enum.at(suggestions, 3) == [":atom", "Pleroma.Upload", {":atom", "Pleroma.Upload"}]
194 %{suggestions: suggestions} = Enum.at(children, 6)
195 assert Enum.at(suggestions, 0) == ":always"
196 assert Enum.at(suggestions, 1) == ":never"
197 assert Enum.at(suggestions, 2) == ":if_available"
200 test "group, key as string in main desc" do
201 descriptions = Generator.convert_to_strings(@descriptions)
202 desc = Enum.at(descriptions, 3)
203 assert desc[:group] == "Some string group"
204 assert desc[:key] == "Some string key"
207 test "key as string subchild" do
208 [%{children: children} | _] = Generator.convert_to_strings(@descriptions)
209 child = Enum.at(children, 7)
210 assert child[:key] == "application/xml"
213 test "suggestion for tls versions" do
214 [%{children: children} | _] = Generator.convert_to_strings(@descriptions)
215 child = Enum.at(children, 8)
216 assert child[:suggestions] == [":tlsv1", ":tlsv1.1", ":tlsv1.2", ":tlsv1.3"]
219 test "subgroup with module name" do
220 [%{children: children} | _] = Generator.convert_to_strings(@descriptions)
222 %{group: subgroup} = Enum.at(children, 6)
223 assert subgroup == {":subgroup", "Swoosh.Adapters.SMTP"}