switest 0.1.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +24 -6
- data/lib/switest/agent.rb +5 -0
- data/lib/switest/esl/call.rb +4 -0
- data/lib/switest/scenario.rb +24 -2
- data/lib/switest/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3c144f6162bbe043cadc3c2743542ff52b0b9c2ef7d9ac2b694fe88cd1db1ebb
|
|
4
|
+
data.tar.gz: f99e71cbfd40ae2baf0ad5eab7b8864a66f01c611e612d843a7482fa642c3d6d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4185e0b448059955f50cd699d095c12666197daf13efa83a203aebfd2d0a3515e287bc7d0334c651f4a967f89181ae0252030f00a07d2f0e354ac3989a6e13ef
|
|
7
|
+
data.tar.gz: 661109e09e38b8fbed7eeb32ceb7c664046d1fda387d77b85f832d2fe172d8cc0dc47882d3df00bb76351082e32490a66e781ace96d8f50e471048e32463988d
|
data/README.md
CHANGED
|
@@ -168,11 +168,14 @@ agent.end_reason # e.g. "NORMAL_CLEARING"
|
|
|
168
168
|
`Switest::Scenario` provides these assertions:
|
|
169
169
|
|
|
170
170
|
```ruby
|
|
171
|
-
assert_call(agent, timeout: 5)
|
|
172
|
-
assert_no_call(agent, timeout: 2)
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
171
|
+
assert_call(agent, timeout: 5) # Agent receives a call
|
|
172
|
+
assert_no_call(agent, timeout: 2) # Agent does NOT receive a call
|
|
173
|
+
assert_answered(agent, timeout: 5) # Call has been answered
|
|
174
|
+
assert_bridged(agent, timeout: 5) # Call has been bridged
|
|
175
|
+
assert_hungup(agent, timeout: 5) # Call has ended
|
|
176
|
+
assert_not_hungup(agent, timeout: 2) # Call is still active
|
|
177
|
+
assert_dtmf(agent, "123", timeout: 5) # Agent receives expected DTMF digits
|
|
178
|
+
assert_dtmf(agent, "123") { other.send_dtmf("123") } # With block: flushes stale DTMF first
|
|
176
179
|
```
|
|
177
180
|
|
|
178
181
|
The `hangup_all` helper ends all active calls (useful before CDR assertions):
|
|
@@ -228,7 +231,22 @@ digits = alice.receive_dtmf(count: 4, timeout: 5)
|
|
|
228
231
|
assert_equal "1234", digits
|
|
229
232
|
```
|
|
230
233
|
|
|
231
|
-
Or use the assertion helper
|
|
234
|
+
Or use the assertion helper with a block to avoid stale DTMF issues.
|
|
235
|
+
The block is executed after a configurable delay (`after:`, default 1s)
|
|
236
|
+
while the assertion is already listening:
|
|
237
|
+
|
|
238
|
+
```ruby
|
|
239
|
+
assert_dtmf(bob, "1234") do
|
|
240
|
+
alice.send_dtmf("1234")
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
# With custom delay and timeout:
|
|
244
|
+
assert_dtmf(bob, "1234", timeout: 10, after: 0.5) do
|
|
245
|
+
alice.send_dtmf("1234")
|
|
246
|
+
end
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
Without a block it works as a simple wait (backward compatible):
|
|
232
250
|
|
|
233
251
|
```ruby
|
|
234
252
|
assert_dtmf(alice, "1234", timeout: 5)
|
data/lib/switest/agent.rb
CHANGED
|
@@ -72,6 +72,11 @@ module Switest
|
|
|
72
72
|
@call.receive_dtmf(count: count, timeout: timeout)
|
|
73
73
|
end
|
|
74
74
|
|
|
75
|
+
def flush_dtmf
|
|
76
|
+
raise "No call for DTMF" unless @call
|
|
77
|
+
@call.flush_dtmf
|
|
78
|
+
end
|
|
79
|
+
|
|
75
80
|
def wait_for_call(timeout: 5)
|
|
76
81
|
deadline = Time.now + timeout
|
|
77
82
|
while Time.now < deadline
|
data/lib/switest/esl/call.rb
CHANGED
data/lib/switest/scenario.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "minitest/test"
|
|
4
|
+
require "concurrent"
|
|
4
5
|
|
|
5
6
|
module Switest
|
|
6
7
|
class Scenario < Minitest::Test
|
|
@@ -48,6 +49,18 @@ module Switest
|
|
|
48
49
|
refute agent.call?, "Expected agent to not have received a call"
|
|
49
50
|
end
|
|
50
51
|
|
|
52
|
+
def assert_answered(agent, timeout: 5)
|
|
53
|
+
assert agent.call?, "Agent has no call"
|
|
54
|
+
success = agent.wait_for_answer(timeout: timeout)
|
|
55
|
+
assert success, "Expected call to be answered within #{timeout} seconds"
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def assert_bridged(agent, timeout: 5)
|
|
59
|
+
assert agent.call?, "Agent has no call"
|
|
60
|
+
success = agent.wait_for_bridge(timeout: timeout)
|
|
61
|
+
assert success, "Expected call to be bridged within #{timeout} seconds"
|
|
62
|
+
end
|
|
63
|
+
|
|
51
64
|
def assert_hungup(agent, timeout: 5)
|
|
52
65
|
assert agent.call?, "Agent has no call"
|
|
53
66
|
success = agent.wait_for_end(timeout: timeout)
|
|
@@ -60,9 +73,18 @@ module Switest
|
|
|
60
73
|
refute agent.ended?, "Expected call to still be active"
|
|
61
74
|
end
|
|
62
75
|
|
|
63
|
-
def assert_dtmf(agent, expected_dtmf, timeout: 5)
|
|
76
|
+
def assert_dtmf(agent, expected_dtmf, timeout: 5, after: 1, &block)
|
|
64
77
|
assert agent.call?, "Agent has no call"
|
|
65
|
-
|
|
78
|
+
|
|
79
|
+
if block
|
|
80
|
+
agent.flush_dtmf
|
|
81
|
+
task = Concurrent::ScheduledTask.execute(after) { block.call }
|
|
82
|
+
received = agent.receive_dtmf(count: expected_dtmf.length, timeout: timeout)
|
|
83
|
+
task.wait
|
|
84
|
+
else
|
|
85
|
+
received = agent.receive_dtmf(count: expected_dtmf.length, timeout: timeout)
|
|
86
|
+
end
|
|
87
|
+
|
|
66
88
|
assert_equal expected_dtmf, received, "Expected DTMF '#{expected_dtmf}' but received '#{received}'"
|
|
67
89
|
end
|
|
68
90
|
end
|
data/lib/switest/version.rb
CHANGED