Comparison

spec/util_stanza_spec.lua @ 11087:cdd4684992f1

spec.stanza spec: Split up util.error related tests
author Kim Alvefur <zash@zash.se>
date Sat, 26 Sep 2020 19:00:17 +0200
parent 11086:2846b6226a8e
child 11088:1f84d0e4d0c4
comparison
equal deleted inserted replaced
11086:2846b6226a8e 11087:cdd4684992f1
230 assert.has.error_match(function () 230 assert.has.error_match(function ()
231 st.error_reply(st.error_reply(st.message({type="chat"}), "modify", "forbidden"), "cancel", "service-unavailable"); 231 st.error_reply(st.error_reply(st.message({type="chat"}), "modify", "forbidden"), "cancel", "service-unavailable");
232 end, "got stanza of type error"); 232 end, "got stanza of type error");
233 end); 233 end);
234 234
235 describe("util.error integration", function ()
235 it("should accept util.error objects", function () 236 it("should accept util.error objects", function ()
236 local s = st.message({ to = "touser", from = "fromuser", id = "123", type = "chat" }, "Hello"); 237 local s = st.message({ to = "touser", from = "fromuser", id = "123", type = "chat" }, "Hello");
237 local e = errors.new({ type = "modify", condition = "not-acceptable", text = "Bork bork bork" }, { by = "this.test" }); 238 local e = errors.new({ type = "modify", condition = "not-acceptable", text = "Bork bork bork" }, { by = "this.test" });
238 local r = st.error_reply(s, e); 239 local r = st.error_reply(s, e);
239 240
245 assert.are.equal(r.tags[1].name, "error"); 246 assert.are.equal(r.tags[1].name, "error");
246 assert.are.equal(r.tags[1].attr.type, e.type); 247 assert.are.equal(r.tags[1].attr.type, e.type);
247 assert.are.equal(r.tags[1].tags[1].name, e.condition); 248 assert.are.equal(r.tags[1].tags[1].name, e.condition);
248 assert.are.equal(r.tags[1].tags[2]:get_text(), e.text); 249 assert.are.equal(r.tags[1].tags[2]:get_text(), e.text);
249 assert.are.equal("this.test", r.tags[1].attr.by); 250 assert.are.equal("this.test", r.tags[1].attr.by);
250 251 end);
252
253 it("should accept util.error objects with an URI", function ()
254 local s = st.message({ to = "touser", from = "fromuser", id = "123", type = "chat" }, "Hello");
251 local gone = errors.new({ condition = "gone", extra = { uri = "file:///dev/null" } }) 255 local gone = errors.new({ condition = "gone", extra = { uri = "file:///dev/null" } })
252 local gonner = st.error_reply(s, gone); 256 local gonner = st.error_reply(s, gone);
253 assert.are.equal("gone", gonner.tags[1].tags[1].name); 257 assert.are.equal("gone", gonner.tags[1].tags[1].name);
254 assert.are.equal("file:///dev/null", gonner.tags[1].tags[1][1]); 258 assert.are.equal("file:///dev/null", gonner.tags[1].tags[1][1]);
255 259 end);
260
261 it("should accept util.error objects with application specific error", function ()
262 local s = st.message({ to = "touser", from = "fromuser", id = "123", type = "chat" }, "Hello");
256 local e = errors.new({ condition = "internal-server-error", text = "Namespaced thing happened", 263 local e = errors.new({ condition = "internal-server-error", text = "Namespaced thing happened",
257 extra = {namespace="xmpp:example.test", condition="this-happened"} }) 264 extra = {namespace="xmpp:example.test", condition="this-happened"} })
258 local r = st.error_reply(s, e); 265 local r = st.error_reply(s, e);
259 assert.are.equal("xmpp:example.test", r.tags[1].tags[3].attr.xmlns); 266 assert.are.equal("xmpp:example.test", r.tags[1].tags[3].attr.xmlns);
260 assert.are.equal("this-happened", r.tags[1].tags[3].name); 267 assert.are.equal("this-happened", r.tags[1].tags[3].name);
263 extra = {tag=st.stanza("that-happened", { xmlns = "xmpp:example.test", ["another-attribute"] = "here" })} }) 270 extra = {tag=st.stanza("that-happened", { xmlns = "xmpp:example.test", ["another-attribute"] = "here" })} })
264 local r2 = st.error_reply(s, e2); 271 local r2 = st.error_reply(s, e2);
265 assert.are.equal("xmpp:example.test", r2.tags[1].tags[3].attr.xmlns); 272 assert.are.equal("xmpp:example.test", r2.tags[1].tags[3].attr.xmlns);
266 assert.are.equal("that-happened", r2.tags[1].tags[3].name); 273 assert.are.equal("that-happened", r2.tags[1].tags[3].name);
267 assert.are.equal("here", r2.tags[1].tags[3].attr["another-attribute"]); 274 assert.are.equal("here", r2.tags[1].tags[3].attr["another-attribute"]);
275 end);
268 end); 276 end);
269 end); 277 end);
270 278
271 describe("should reject #invalid", function () 279 describe("should reject #invalid", function ()
272 local invalid_names = { 280 local invalid_names = {