Software / code / prosody
Comparison
spec/util_stanza_spec.lua @ 10503:e25a1a9a6e7e
util.stanza: Accept util.error object to error_reply
If we're moving towards util.error as the standard error container then
this makes sense.
This may allow for future extensibility without needing a lot of
optional arguments.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 14 Dec 2019 22:47:41 +0100 |
| parent | 10446:5c2d1b13537c |
| child | 10717:05e4645fc9b3 |
comparison
equal
deleted
inserted
replaced
| 10502:f1c0aa521dd5 | 10503:e25a1a9a6e7e |
|---|---|
| 1 | 1 |
| 2 local st = require "util.stanza"; | 2 local st = require "util.stanza"; |
| 3 local errors = require "util.error"; | |
| 3 | 4 |
| 4 describe("util.stanza", function() | 5 describe("util.stanza", function() |
| 5 describe("#preserialize()", function() | 6 describe("#preserialize()", function() |
| 6 it("should work", function() | 7 it("should work", function() |
| 7 local stanza = st.stanza("message", { type = "chat" }):text_tag("body", "Hello"); | 8 local stanza = st.stanza("message", { type = "chat" }):text_tag("body", "Hello"); |
| 229 assert.has.error_match(function () | 230 assert.has.error_match(function () |
| 230 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"); |
| 231 end, "got stanza of type error"); | 232 end, "got stanza of type error"); |
| 232 end); | 233 end); |
| 233 | 234 |
| 235 it("should accept util.error objects", function () | |
| 236 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" }); | |
| 238 local r = st.error_reply(s, e); | |
| 239 | |
| 240 assert.are.equal(r.name, s.name); | |
| 241 assert.are.equal(r.id, s.id); | |
| 242 assert.are.equal(r.attr.to, s.attr.from); | |
| 243 assert.are.equal(r.attr.from, s.attr.to); | |
| 244 assert.are.equal(r.attr.type, "error"); | |
| 245 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].tags[1].name, e.condition); | |
| 248 assert.are.equal(r.tags[1].tags[2]:get_text(), e.text); | |
| 249 end); | |
| 250 | |
| 234 end); | 251 end); |
| 235 | 252 |
| 236 describe("should reject #invalid", function () | 253 describe("should reject #invalid", function () |
| 237 local invalid_names = { | 254 local invalid_names = { |
| 238 ["empty string"] = "", ["characters"] = "<>"; | 255 ["empty string"] = "", ["characters"] = "<>"; |