diff options
author | Kim Alvefur <zash@zash.se> | 2021-03-07 00:57:36 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2021-03-07 00:57:36 +0100 |
commit | 081eb23c54b685c01e531468e6ba59740d779878 (patch) | |
tree | da41100aef148a93053fd4d07677ec7661172a45 /spec/util_datamapper_spec.lua | |
parent | 02da1378f86be8afd5f0fda367f1466072898786 (diff) | |
download | prosody-081eb23c54b685c01e531468e6ba59740d779878.tar.gz prosody-081eb23c54b685c01e531468e6ba59740d779878.zip |
util.datamapper: Library for extracting data from stanzas
Based on the XML support in the OpenAPI specification.
Diffstat (limited to 'spec/util_datamapper_spec.lua')
-rw-r--r-- | spec/util_datamapper_spec.lua | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/spec/util_datamapper_spec.lua b/spec/util_datamapper_spec.lua new file mode 100644 index 00000000..0e1dfdab --- /dev/null +++ b/spec/util_datamapper_spec.lua @@ -0,0 +1,56 @@ +local xml +local map + +setup(function() + xml = require "util.xml"; + map = require "util.datamapper"; +end); + +describe("util.datampper", function() + + local s, x, d + setup(function() + + local function attr() return {type = "string"; xml = {attribute = true}} end + s = { + type = "object"; + xml = {name = "message"; namespace = "jabber:client"}; + properties = { + to = attr(); + from = attr(); + type = attr(); + id = attr(); + body = "string"; + lang = {type = "string"; xml = {attribute = true; prefix = "xml"}}; + delay = { + type = "object"; + xml = {namespace = "urn:xmpp:delay"; name = "delay"}; + properties = {stamp = attr(); from = attr(); reason = {type = "string"; xml = {text = true}}}; + }; + }; + }; + + x = xml.parse [[ + <message xmlns="jabber:client" xml:lang="en" to="a@test" from="b@test" type="chat" id="1"> + <body>Hello</body> + <delay xmlns='urn:xmpp:delay' from='test' stamp='2021-03-07T15:59:08+00:00'>Becasue</delay> + </message> + ]]; + + d = { + to = "a@test"; + from = "b@test"; + type = "chat"; + id = "1"; + lang = "en"; + body = "Hello"; + delay = {from = "test"; stamp = "2021-03-07T15:59:08+00:00"; reason = "Becasue"}; + }; + end); + + describe("parse", function() + it("works", function() + assert.same(d, map.parse(s, x)); + end); + end); +end) |