| 1 | -- One-shot test client: sends "-ping" to the bot and expects a reply |
| 2 | local verse = require "verse"; |
| 3 | require "verse.client"; |
| 4 | |
| 5 | verse.set_log_handler(print, { "warn", "error" }); |
| 6 | |
| 7 | local c = verse.new(); |
| 8 | c.connect_host = "prosody"; |
| 9 | |
| 10 | local timeout = 30; |
| 11 | verse.add_task(timeout, function () |
| 12 | print("TEST FAIL: no reply after "..timeout.."s"); |
| 13 | os.exit(1); |
| 14 | end); |
| 15 | |
| 16 | c:hook("ready", function () |
| 17 | c:send(verse.presence()); |
| 18 | c:send(verse.message({ to = "riddim@prosody", type = "chat" }) |
| 19 | :tag("body"):text("-ping")); |
| 20 | end); |
| 21 | |
| 22 | c:hook("stanza", function (stanza) |
| 23 | if stanza.name == "message" then |
| 24 | local body = stanza:get_child_text("body"); |
| 25 | if body then |
| 26 | print("Reply from bot: "..body); |
| 27 | if body:lower():match("pong") then |
| 28 | print("TEST PASS"); |
| 29 | os.exit(0); |
| 30 | else |
| 31 | print("TEST FAIL: unexpected reply"); |
| 32 | os.exit(2); |
| 33 | end |
| 34 | end |
| 35 | end |
| 36 | end); |
| 37 | |
| 38 | c:hook("disconnected", function () |
| 39 | print("TEST FAIL: disconnected"); |
| 40 | os.exit(1); |
| 41 | end); |
| 42 | |
| 43 | c:connect_client("tester@prosody", "testerpass"); |
| 44 | |
| 45 | verse.loop(); |