Comparison

spec/util_datamapper_spec.lua @ 11435:a1fa6202fa13

util.datamapper: Library for extracting data from stanzas Based on the XML support in the OpenAPI specification.
author Kim Alvefur <zash@zash.se>
date Sun, 07 Mar 2021 00:57:36 +0100
child 11436:5df9ffc25bb4
comparison
equal deleted inserted replaced
11434:66d4067bdfb2 11435:a1fa6202fa13
1 local xml
2 local map
3
4 setup(function()
5 xml = require "util.xml";
6 map = require "util.datamapper";
7 end);
8
9 describe("util.datampper", function()
10
11 local s, x, d
12 setup(function()
13
14 local function attr() return {type = "string"; xml = {attribute = true}} end
15 s = {
16 type = "object";
17 xml = {name = "message"; namespace = "jabber:client"};
18 properties = {
19 to = attr();
20 from = attr();
21 type = attr();
22 id = attr();
23 body = "string";
24 lang = {type = "string"; xml = {attribute = true; prefix = "xml"}};
25 delay = {
26 type = "object";
27 xml = {namespace = "urn:xmpp:delay"; name = "delay"};
28 properties = {stamp = attr(); from = attr(); reason = {type = "string"; xml = {text = true}}};
29 };
30 };
31 };
32
33 x = xml.parse [[
34 <message xmlns="jabber:client" xml:lang="en" to="a@test" from="b@test" type="chat" id="1">
35 <body>Hello</body>
36 <delay xmlns='urn:xmpp:delay' from='test' stamp='2021-03-07T15:59:08+00:00'>Becasue</delay>
37 </message>
38 ]];
39
40 d = {
41 to = "a@test";
42 from = "b@test";
43 type = "chat";
44 id = "1";
45 lang = "en";
46 body = "Hello";
47 delay = {from = "test"; stamp = "2021-03-07T15:59:08+00:00"; reason = "Becasue"};
48 };
49 end);
50
51 describe("parse", function()
52 it("works", function()
53 assert.same(d, map.parse(s, x));
54 end);
55 end);
56 end)