switest 0.2.0 → 0.4.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 +15 -5
- data/lib/switest/esl/client.rb +15 -7
- data/lib/switest/esl/connection.rb +5 -2
- data/lib/switest/scenario.rb +14 -3
- 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: 056e2a1dd0271f490fdfb77978cdb272b8ac79f592aa18818642956d12f7c1a8
|
|
4
|
+
data.tar.gz: 28ec935b623017b29b5bd2f6899d82b85a84b6ac7a452977f4f9cb25f6445b9d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7dcffb0b3476237f826d7480251f00e70046197737d9886ea48a16dc886b463d1dfc83223858008fce51d14ab791e7d374252c43adf931a06ee95d114300d204
|
|
7
|
+
data.tar.gz: bded19bd55e5f76a7e2b93fa67f757e924f5f1bfe3b4089ab7c0c31ee8f74a4c97db7f9ce8437f2f6daf6da7790440ca941529a548f6e9905fc9699c668c3da4
|
data/README.md
CHANGED
|
@@ -168,14 +168,24 @@ 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 (see note below)
|
|
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
|
|
176
178
|
assert_dtmf(agent, "123") { other.send_dtmf("123") } # With block: flushes stale DTMF first
|
|
177
179
|
```
|
|
178
180
|
|
|
181
|
+
**Note on `assert_bridged`:** This assertion only works when a CHANNEL_BRIDGE
|
|
182
|
+
event fires on a channel Switest tracks. It works when the FreeSWITCH dialplan
|
|
183
|
+
runs the `bridge` application on an inbound channel picked up via
|
|
184
|
+
`listen_for_call`. It does **not** work for agent-to-agent calls routed through
|
|
185
|
+
SIP gateways — the bridge happens on internal gateway legs whose UUIDs Switest
|
|
186
|
+
doesn't track. For gateway scenarios, use `assert_answered` on both agents
|
|
187
|
+
instead to confirm the call is connected.
|
|
188
|
+
|
|
179
189
|
The `hangup_all` helper ends all active calls (useful before CDR assertions):
|
|
180
190
|
|
|
181
191
|
```ruby
|
data/lib/switest/esl/client.rb
CHANGED
|
@@ -39,16 +39,24 @@ module Switest
|
|
|
39
39
|
|
|
40
40
|
# Hangup all active calls individually and wait for them to end.
|
|
41
41
|
# This ensures proper hangup_cause is set for each call (important for CDRs).
|
|
42
|
+
# Sends all hangups first, then waits with a shared deadline to avoid
|
|
43
|
+
# O(n * timeout) delays with many calls.
|
|
42
44
|
def hangup_all(cause: "NORMAL_CLEARING", timeout: 5)
|
|
43
45
|
return unless @connection&.connected?
|
|
44
46
|
|
|
45
|
-
@calls.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
rescue
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
active = @calls.values.reject(&:ended?)
|
|
48
|
+
|
|
49
|
+
# Send all hangups without waiting
|
|
50
|
+
active.each do |call|
|
|
51
|
+
call.hangup(cause, wait: false) rescue nil
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Wait for all to end with a single shared deadline
|
|
55
|
+
deadline = Time.now + timeout
|
|
56
|
+
active.each do |call|
|
|
57
|
+
remaining = deadline - Time.now
|
|
58
|
+
break if remaining <= 0
|
|
59
|
+
call.wait_for_end(timeout: remaining) unless call.ended?
|
|
52
60
|
end
|
|
53
61
|
end
|
|
54
62
|
|
|
@@ -110,8 +110,11 @@ module Switest
|
|
|
110
110
|
|
|
111
111
|
def subscribe_events
|
|
112
112
|
events = %w[
|
|
113
|
-
CHANNEL_CREATE
|
|
114
|
-
|
|
113
|
+
CHANNEL_CREATE # Detect new inbound calls
|
|
114
|
+
CHANNEL_ANSWER # Track when calls are answered
|
|
115
|
+
CHANNEL_BRIDGE # Track when calls are bridged
|
|
116
|
+
CHANNEL_HANGUP_COMPLETE # Track call end with final headers
|
|
117
|
+
DTMF # Receive DTMF digits per call
|
|
115
118
|
].join(" ")
|
|
116
119
|
|
|
117
120
|
@socket.write("event plain #{events}\n\n")
|
data/lib/switest/scenario.rb
CHANGED
|
@@ -49,6 +49,18 @@ module Switest
|
|
|
49
49
|
refute agent.call?, "Expected agent to not have received a call"
|
|
50
50
|
end
|
|
51
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
|
+
|
|
52
64
|
def assert_hungup(agent, timeout: 5)
|
|
53
65
|
assert agent.call?, "Agent has no call"
|
|
54
66
|
success = agent.wait_for_end(timeout: timeout)
|
|
@@ -66,9 +78,8 @@ module Switest
|
|
|
66
78
|
|
|
67
79
|
if block
|
|
68
80
|
agent.flush_dtmf
|
|
69
|
-
|
|
70
|
-
received = agent.receive_dtmf(count: expected_dtmf.length, timeout: timeout)
|
|
71
|
-
task.wait
|
|
81
|
+
Concurrent::ScheduledTask.execute(after) { block.call }
|
|
82
|
+
received = agent.receive_dtmf(count: expected_dtmf.length, timeout: timeout + after)
|
|
72
83
|
else
|
|
73
84
|
received = agent.receive_dtmf(count: expected_dtmf.length, timeout: timeout)
|
|
74
85
|
end
|
data/lib/switest/version.rb
CHANGED