1# frozen_string_literal: true
2
3require "test_helper"
4require "command"
5
6Command::COMMAND_MANAGER = Minitest::Mock.new
7
8class CommandTest < Minitest::Test
9 def test_cancel_finishes
10 blather = Minitest::Mock.new
11 iq1 = Blather::Stanza::Iq::Command.new
12 iq1.from = "test@example.com"
13 iq1.id = "test-id"
14 iq1.sessionid = "session-id"
15
16 # The library digests the sessionID I give it...
17 session = iq1.sessionid
18
19 iq2 = Blather::Stanza::Iq::Command.new
20 iq2.from = "test@example.com"
21 iq2.id = "cancel-id"
22 iq2.sessionid = "session-id"
23 iq2.action = :cancel
24
25 Command::COMMAND_MANAGER.expect(
26 :write,
27 EMPromise.reject(iq2),
28 [Matching.new do |iq|
29 assert_equal "test-id", iq.id
30 assert_equal session, iq.sessionid
31 end]
32 )
33
34 blather.expect(
35 :<<,
36 nil,
37 [Matching.new do |iq|
38 assert "canceled", iq.status
39 assert_equal "cancel-id", iq.id
40 assert_equal session, iq.sessionid
41 end]
42 )
43
44 execute_command(iq1, blather: blather) { |cmd|
45 cmd.reply.then do
46 raise "Should have cancelled"
47 end
48 }.then do
49 assert_mock blather
50 assert_mock Command::COMMAND_MANAGER
51 end
52 end
53 em :test_cancel_finishes
54end