1 defmodule Pleroma.Docs.GeneratorTest do
2 use ExUnit.Case, async: true
3 alias Pleroma.Docs.Generator
17 Generator.list_modules_in_dir(
18 "lib/pleroma/upload/filter",
19 "Elixir.Pleroma.Upload.Filter."
24 type: {:list, :module},
27 Generator.list_modules_in_dir(
28 "lib/pleroma/web/activity_pub/mrf",
29 "Elixir.Pleroma.Web.ActivityPub.MRF."
51 key: :another_key_with_label,
52 label: "Another label",
66 {:tuple, "string", 8080},
67 [:atom, Pleroma.Upload, {:atom, Pleroma.Upload}]
72 label: "Special Label",
78 group: {:subgroup, Swoosh.Adapters.SMTP},
81 description: "`Swoosh.Adapters.SMTP` adapter specific setting",
82 suggestions: [:always, :never, :if_available]
85 key: "application/xml",
86 type: {:list, :string},
92 description: "List of TLS version to use",
93 suggestions: [:tlsv1, ":tlsv1.1", ":tlsv1.2"]
106 children: [%{key: :key1, type: :string, suggestions: [""]}]
108 %{group: "Some string group", key: "Some string key", type: :group}
111 describe "convert_to_strings/1" do
112 test "group, key, label" do
113 [desc1, desc2 | _] = Generator.convert_to_strings(@descriptions)
115 assert desc1[:group] == ":pleroma"
116 assert desc1[:key] == "Pleroma.Upload"
117 assert desc1[:label] == "Pleroma.Upload"
119 assert desc2[:group] == ":tesla"
120 assert desc2[:key] == ":adapter"
121 assert desc2[:label] == "Adapter"
124 test "group without key" do
125 descriptions = Generator.convert_to_strings(@descriptions)
126 desc = Enum.at(descriptions, 2)
128 assert desc[:group] == ":cors_plug"
130 assert desc[:label] == "Cors plug"
133 test "children key, label, type" do
134 [%{children: [child1, child2, child3, child4 | _]} | _] =
135 Generator.convert_to_strings(@descriptions)
137 assert child1[:key] == ":uploader"
138 assert child1[:label] == "Uploader"
139 assert child1[:type] == :module
141 assert child2[:key] == ":filters"
142 assert child2[:label] == "Filters"
143 assert child2[:type] == {:list, :module}
145 assert child3[:key] == "Pleroma.Upload"
146 assert child3[:label] == "Pleroma.Upload"
147 assert child3[:type] == :string
149 assert child4[:key] == ":some_key"
150 assert child4[:label] == "Some key"
151 assert child4[:type] == :keyword
154 test "child with predefined label" do
155 [%{children: children} | _] = Generator.convert_to_strings(@descriptions)
156 child = Enum.at(children, 5)
157 assert child[:key] == "Pleroma.Upload"
158 assert child[:label] == "Special Label"
162 [%{children: children} | _] = Generator.convert_to_strings(@descriptions)
163 child = Enum.at(children, 3)
164 %{children: [subchild | _]} = child
166 assert subchild[:key] == ":another_key"
167 assert subchild[:label] == "Another key"
168 assert subchild[:type] == :integer
171 test "subchild with predefined label" do
172 [%{children: children} | _] = Generator.convert_to_strings(@descriptions)
173 child = Enum.at(children, 3)
174 %{children: subchildren} = child
175 subchild = Enum.at(subchildren, 1)
177 assert subchild[:key] == ":another_key_with_label"
178 assert subchild[:label] == "Another label"
181 test "module suggestions" do
182 [%{children: [%{suggestions: suggestions} | _]} | _] =
183 Generator.convert_to_strings(@descriptions)
185 Enum.each(suggestions, fn suggestion ->
186 assert String.starts_with?(suggestion, "Pleroma.")
190 test "atoms in suggestions with leading `:`" do
191 [%{children: children} | _] = Generator.convert_to_strings(@descriptions)
192 %{suggestions: suggestions} = Enum.at(children, 4)
193 assert Enum.at(suggestions, 0) == ":atom"
194 assert Enum.at(suggestions, 1) == "Pleroma.Upload"
195 assert Enum.at(suggestions, 2) == {":tuple", "string", 8080}
196 assert Enum.at(suggestions, 3) == [":atom", "Pleroma.Upload", {":atom", "Pleroma.Upload"}]
198 %{suggestions: suggestions} = Enum.at(children, 6)
199 assert Enum.at(suggestions, 0) == ":always"
200 assert Enum.at(suggestions, 1) == ":never"
201 assert Enum.at(suggestions, 2) == ":if_available"
204 test "group, key as string in main desc" do
205 descriptions = Generator.convert_to_strings(@descriptions)
206 desc = Enum.at(descriptions, 3)
207 assert desc[:group] == "Some string group"
208 assert desc[:key] == "Some string key"
211 test "key as string subchild" do
212 [%{children: children} | _] = Generator.convert_to_strings(@descriptions)
213 child = Enum.at(children, 7)
214 assert child[:key] == "application/xml"
217 test "suggestion for tls versions" do
218 [%{children: children} | _] = Generator.convert_to_strings(@descriptions)
219 child = Enum.at(children, 8)
220 assert child[:suggestions] == [":tlsv1", ":tlsv1.1", ":tlsv1.2"]
223 test "subgroup with module name" do
224 [%{children: children} | _] = Generator.convert_to_strings(@descriptions)
226 %{group: subgroup} = Enum.at(children, 6)
227 assert subgroup == {":subgroup", "Swoosh.Adapters.SMTP"}