Software / code / prosody
Comparison
spec/util_datamapper_spec.lua @ 11462:d1982b7eb00d
util.datamapper: Fix arrays nesting one level too deep
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 19 Mar 2021 01:17:59 +0100 |
| parent | 11458:0e00fa518688 |
| child | 11466:c098d07e6717 |
comparison
equal
deleted
inserted
replaced
| 11461:766b0eddd12c | 11462:d1982b7eb00d |
|---|---|
| 44 }; | 44 }; |
| 45 origin_id = { | 45 origin_id = { |
| 46 type = "string"; | 46 type = "string"; |
| 47 xml = {name = "origin-id"; namespace = "urn:xmpp:sid:0"; x_single_attribute = "id"}; | 47 xml = {name = "origin-id"; namespace = "urn:xmpp:sid:0"; x_single_attribute = "id"}; |
| 48 }; | 48 }; |
| 49 reactions = { | 49 react = { |
| 50 type = "array"; | 50 type = "object"; |
| 51 xml = {namespace = "urn:xmpp:reactions:0"; wrapped = true}; | 51 xml = {namespace = "urn:xmpp:reactions:0"; name = "reactions"}; |
| 52 items = {type = "string"; xml = {name = "reaction"}}; | 52 properties = { |
| 53 to = {type = "string"; xml = {attribute = true; name = "id"}}; | |
| 54 reactions = {type = "array"; items = {type = "string"; xml = {name = "reaction"}}}; | |
| 55 }; | |
| 53 }; | 56 }; |
| 54 }; | 57 }; |
| 55 }; | 58 }; |
| 56 | 59 |
| 57 x = xml.parse [[ | 60 x = xml.parse [[ |
| 78 body = "Hello"; | 81 body = "Hello"; |
| 79 delay = {from = "test"; stamp = "2021-03-07T15:59:08+00:00"; reason = "Becasue"}; | 82 delay = {from = "test"; stamp = "2021-03-07T15:59:08+00:00"; reason = "Becasue"}; |
| 80 state = "active"; | 83 state = "active"; |
| 81 fallback = true; | 84 fallback = true; |
| 82 origin_id = "qgkmMdPB"; | 85 origin_id = "qgkmMdPB"; |
| 83 reactions = { | 86 react = { |
| 84 "👋", | 87 to = "744f6e18-a57a-11e9-a656-4889e7820c76"; |
| 85 "🐢", | 88 reactions = { |
| 89 "👋", | |
| 90 "🐢", | |
| 91 }; | |
| 86 }; | 92 }; |
| 87 }; | 93 }; |
| 88 end); | 94 end); |
| 89 | 95 |
| 90 describe("parse", function() | 96 describe("parse", function() |
| 100 assert.same(x.attr, u.attr); | 106 assert.same(x.attr, u.attr); |
| 101 assert.equal(x:get_child_text("body"), u:get_child_text("body")); | 107 assert.equal(x:get_child_text("body"), u:get_child_text("body")); |
| 102 assert.equal(x:get_child_text("delay", "urn:xmpp:delay"), u:get_child_text("delay", "urn:xmpp:delay")); | 108 assert.equal(x:get_child_text("delay", "urn:xmpp:delay"), u:get_child_text("delay", "urn:xmpp:delay")); |
| 103 assert.same(x:get_child("delay", "urn:xmpp:delay").attr, u:get_child("delay", "urn:xmpp:delay").attr); | 109 assert.same(x:get_child("delay", "urn:xmpp:delay").attr, u:get_child("delay", "urn:xmpp:delay").attr); |
| 104 assert.same(x:get_child("origin-id", "urn:xmpp:sid:0").attr, u:get_child("origin-id", "urn:xmpp:sid:0").attr); | 110 assert.same(x:get_child("origin-id", "urn:xmpp:sid:0").attr, u:get_child("origin-id", "urn:xmpp:sid:0").attr); |
| 111 assert.same(x:get_child("reactions", "urn:xmpp:reactions:0").attr, u:get_child("reactions", "urn:xmpp:reactions:0").attr); | |
| 112 assert.same(2, #u:get_child("reactions", "urn:xmpp:reactions:0").tags); | |
| 105 for _, tag in ipairs(x.tags) do | 113 for _, tag in ipairs(x.tags) do |
| 106 if tag.name ~= "UNRELATED" then | 114 if tag.name ~= "UNRELATED" then |
| 107 assert.truthy(u:get_child(tag.name, tag.attr.xmlns) or u:get_child(tag.name), tag:top_tag()) | 115 assert.truthy(u:get_child(tag.name, tag.attr.xmlns) or u:get_child(tag.name), tag:top_tag()) |
| 108 end | 116 end |
| 109 end | 117 end |