Resolve follow activity from accept/reject without ID (#328)
[akkoma] / test / pleroma / xml_builder_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.XmlBuilderTest do
6 use Pleroma.DataCase, async: true
7 alias Pleroma.XmlBuilder
8
9 test "Build a basic xml string from a tuple" do
10 data = {:feed, %{xmlns: "http://www.w3.org/2005/Atom"}, "Some content"}
11
12 expected_xml = "<feed xmlns=\"http://www.w3.org/2005/Atom\">Some content</feed>"
13
14 assert XmlBuilder.to_xml(data) == expected_xml
15 end
16
17 test "returns a complete document" do
18 data = {:feed, %{xmlns: "http://www.w3.org/2005/Atom"}, "Some content"}
19
20 expected_xml =
21 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><feed xmlns=\"http://www.w3.org/2005/Atom\">Some content</feed>"
22
23 assert XmlBuilder.to_doc(data) == expected_xml
24 end
25
26 test "Works without attributes" do
27 data = {
28 :feed,
29 "Some content"
30 }
31
32 expected_xml = "<feed>Some content</feed>"
33
34 assert XmlBuilder.to_xml(data) == expected_xml
35 end
36
37 test "It works with nested tuples" do
38 data = {
39 :feed,
40 [
41 {:guy, "brush"},
42 {:lament, %{configuration: "puzzle"}, "pinhead"}
43 ]
44 }
45
46 expected_xml =
47 ~s[<feed><guy>brush</guy><lament configuration="puzzle">pinhead</lament></feed>]
48
49 assert XmlBuilder.to_xml(data) == expected_xml
50 end
51
52 test "Represents NaiveDateTime as iso8601" do
53 assert XmlBuilder.to_xml(~N[2000-01-01 13:13:33]) == "2000-01-01T13:13:33"
54 end
55
56 test "Uses self-closing tags when no content is giving" do
57 data = {
58 :link,
59 %{rel: "self"}
60 }
61
62 expected_xml = ~s[<link rel="self" />]
63 assert XmlBuilder.to_xml(data) == expected_xml
64 end
65 end