Diff

spec/util_datamapper_spec.lua @ 11457:6a51749af7f4

util.datamapper: Add initial support for parsing arrays
author Kim Alvefur <zash@zash.se>
date Thu, 18 Mar 2021 12:57:25 +0100 (2021-03-18)
parent 11453:f0037234b2e9
child 11458:0e00fa518688
line wrap: on
line diff
--- a/spec/util_datamapper_spec.lua	Sun Mar 14 16:50:49 2021 +0100
+++ b/spec/util_datamapper_spec.lua	Thu Mar 18 12:57:25 2021 +0100
@@ -46,6 +46,11 @@
 					type = "string";
 					xml = {name = "origin-id"; namespace = "urn:xmpp:sid:0"; x_single_attribute = "id"};
 				};
+				reactions = {
+					type = "array";
+					xml = {namespace = "urn:xmpp:reactions:0"; wrapped = true};
+					items = {type = "string"; xml = {name = "reaction"}};
+				};
 			};
 		};
 
@@ -57,6 +62,10 @@
 				<active xmlns='http://jabber.org/protocol/chatstates'/>
 				<fallback xmlns='urn:xmpp:fallback:0'/>
 				<origin-id xmlns='urn:xmpp:sid:0' id='qgkmMdPB'/>
+				<reactions id='744f6e18-a57a-11e9-a656-4889e7820c76' xmlns='urn:xmpp:reactions:0'>
+					<reaction>👋</reaction>
+					<reaction>🐢</reaction>
+				</reactions>
 				</message>
 				]];
 
@@ -71,6 +80,10 @@
 			state = "active";
 			fallback = true;
 			origin_id = "qgkmMdPB";
+			reactions = {
+				"👋",
+				"🐢",
+			};
 		};
 	end);
 
@@ -85,11 +98,21 @@
 			local u = map.unparse(s, d);
 			assert.equal("message", u.name);
 			assert.same(x.attr, u.attr);
-			assert.equal(#x.tags-1, #u.tags)
 			assert.equal(x:get_child_text("body"), u:get_child_text("body"));
 			assert.equal(x:get_child_text("delay", "urn:xmpp:delay"), u:get_child_text("delay", "urn:xmpp:delay"));
 			assert.same(x:get_child("delay", "urn:xmpp:delay").attr, u:get_child("delay", "urn:xmpp:delay").attr);
 			assert.same(x:get_child("origin-id", "urn:xmpp:sid:0").attr, u:get_child("origin-id", "urn:xmpp:sid:0").attr);
+			for _, tag in ipairs(x.tags) do
+				if tag.name ~= "UNRELATED" and tag.name ~= "reactions" then
+					assert.truthy(u:get_child(tag.name, tag.attr.xmlns) or u:get_child(tag.name), tag:top_tag())
+				end
+			end
+			assert.equal(#x.tags-2, #u.tags)
+
+			pending("arrays", function ()
+				assert.truthy(u:get_child("reactions", "urn:xmpp:reactions:0"))
+			end);
+
 		end);
 	end);
 end)