1 defmodule Pleroma.Docs.GeneratorTest do
2 use ExUnit.Case, async: true
3 alias Pleroma.Docs.Generator
16 suggestions: {:list_behaviour_implementations, Pleroma.Upload.Filter}
20 type: {:list, :module},
22 suggestions: {:list_behaviour_implementations, Pleroma.Web.ActivityPub.MRF}
43 key: :another_key_with_label,
44 label: "Another label",
58 {:tuple, "string", 8080},
59 [:atom, Pleroma.Upload, {:atom, Pleroma.Upload}]
64 label: "Special Label",
70 group: {:subgroup, Swoosh.Adapters.SMTP},
73 description: "`Swoosh.Adapters.SMTP` adapter specific setting",
74 suggestions: [:always, :never, :if_available]
77 key: "application/xml",
78 type: {:list, :string},
84 description: "List of TLS version to use",
85 suggestions: [:tlsv1, ":tlsv1.1", ":tlsv1.2"]
98 children: [%{key: :key1, type: :string, suggestions: [""]}]
100 %{group: "Some string group", key: "Some string key", type: :group}
103 describe "convert_to_strings/1" do
104 test "group, key, label" do
105 [desc1, desc2 | _] = Generator.convert_to_strings(@descriptions)
107 assert desc1[:group] == ":pleroma"
108 assert desc1[:key] == "Pleroma.Upload"
109 assert desc1[:label] == "Pleroma.Upload"
111 assert desc2[:group] == ":tesla"
112 assert desc2[:key] == ":adapter"
113 assert desc2[:label] == "Adapter"
116 test "group without key" do
117 descriptions = Generator.convert_to_strings(@descriptions)
118 desc = Enum.at(descriptions, 2)
120 assert desc[:group] == ":cors_plug"
122 assert desc[:label] == "Cors plug"
125 test "children key, label, type" do
126 [%{children: [child1, child2, child3, child4 | _]} | _] =
127 Generator.convert_to_strings(@descriptions)
129 assert child1[:key] == ":uploader"
130 assert child1[:label] == "Uploader"
131 assert child1[:type] == :module
133 assert child2[:key] == ":filters"
134 assert child2[:label] == "Filters"
135 assert child2[:type] == {:list, :module}
137 assert child3[:key] == "Pleroma.Upload"
138 assert child3[:label] == "Pleroma.Upload"
139 assert child3[:type] == :string
141 assert child4[:key] == ":some_key"
142 assert child4[:label] == "Some key"
143 assert child4[:type] == :keyword
146 test "child with predefined label" do
147 [%{children: children} | _] = Generator.convert_to_strings(@descriptions)
148 child = Enum.at(children, 5)
149 assert child[:key] == "Pleroma.Upload"
150 assert child[:label] == "Special Label"
154 [%{children: children} | _] = Generator.convert_to_strings(@descriptions)
155 child = Enum.at(children, 3)
156 %{children: [subchild | _]} = child
158 assert subchild[:key] == ":another_key"
159 assert subchild[:label] == "Another key"
160 assert subchild[:type] == :integer
163 test "subchild with predefined label" do
164 [%{children: children} | _] = Generator.convert_to_strings(@descriptions)
165 child = Enum.at(children, 3)
166 %{children: subchildren} = child
167 subchild = Enum.at(subchildren, 1)
169 assert subchild[:key] == ":another_key_with_label"
170 assert subchild[:label] == "Another label"
173 test "module suggestions" do
174 [%{children: [%{suggestions: suggestions} | _]} | _] =
175 Generator.convert_to_strings(@descriptions)
177 Enum.each(suggestions, fn suggestion ->
178 assert String.starts_with?(suggestion, "Pleroma.")
182 test "atoms in suggestions with leading `:`" do
183 [%{children: children} | _] = Generator.convert_to_strings(@descriptions)
184 %{suggestions: suggestions} = Enum.at(children, 4)
185 assert Enum.at(suggestions, 0) == ":atom"
186 assert Enum.at(suggestions, 1) == "Pleroma.Upload"
187 assert Enum.at(suggestions, 2) == {":tuple", "string", 8080}
188 assert Enum.at(suggestions, 3) == [":atom", "Pleroma.Upload", {":atom", "Pleroma.Upload"}]
190 %{suggestions: suggestions} = Enum.at(children, 6)
191 assert Enum.at(suggestions, 0) == ":always"
192 assert Enum.at(suggestions, 1) == ":never"
193 assert Enum.at(suggestions, 2) == ":if_available"
196 test "group, key as string in main desc" do
197 descriptions = Generator.convert_to_strings(@descriptions)
198 desc = Enum.at(descriptions, 3)
199 assert desc[:group] == "Some string group"
200 assert desc[:key] == "Some string key"
203 test "key as string subchild" do
204 [%{children: children} | _] = Generator.convert_to_strings(@descriptions)
205 child = Enum.at(children, 7)
206 assert child[:key] == "application/xml"
209 test "suggestion for tls versions" do
210 [%{children: children} | _] = Generator.convert_to_strings(@descriptions)
211 child = Enum.at(children, 8)
212 assert child[:suggestions] == [":tlsv1", ":tlsv1.1", ":tlsv1.2"]
215 test "subgroup with module name" do
216 [%{children: children} | _] = Generator.convert_to_strings(@descriptions)
218 %{group: subgroup} = Enum.at(children, 6)
219 assert subgroup == {":subgroup", "Swoosh.Adapters.SMTP"}