Skip to content

Commit 2df64af

Browse files
committed
Revert "remove duplicate tests"
This reverts commit 94eaa7c9aec0f5b3bd167821e9bcab3335900d59.
1 parent 1f3c05f commit 2df64af

23 files changed

+3266
-2
lines changed
Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
import tap from 'tap'
2+
import { SignalWire } from '@signalwire/realtime-api'
3+
import {
4+
createTestRunner,
5+
CALL_COLLECT_PROPS,
6+
CALL_PROPS,
7+
TestHandler,
8+
makeSipDomainAppAddress,
9+
} from './utils'
10+
11+
const handler: TestHandler = ({ domainApp }) => {
12+
if (!domainApp) {
13+
throw new Error('Missing domainApp')
14+
}
15+
16+
return new Promise<number>(async (resolve, reject) => {
17+
try {
18+
const client = await SignalWire({
19+
host: process.env.RELAY_HOST || 'relay.swire.io',
20+
project: process.env.RELAY_PROJECT as string,
21+
token: process.env.RELAY_TOKEN as string,
22+
debug: {
23+
logWsTraffic: true,
24+
},
25+
})
26+
27+
let waitForCollectStartResolve: () => void
28+
const waitForCollectStart = new Promise<void>((resolve) => {
29+
waitForCollectStartResolve = resolve
30+
})
31+
let waitForCollectEndResolve: () => void
32+
const waitForCollectEnd = new Promise<void>((resolve) => {
33+
waitForCollectEndResolve = resolve
34+
})
35+
36+
const unsubVoice = await client.voice.listen({
37+
topics: [domainApp.call_relay_context, 'home'],
38+
onCallReceived: async (call) => {
39+
try {
40+
const resultAnswer = await call.answer()
41+
tap.hasProps(call, CALL_PROPS, 'Inbound - Call answered')
42+
tap.equal(
43+
call.id,
44+
resultAnswer.id,
45+
'Inbound - Call answered gets the same instance'
46+
)
47+
48+
// Wait until the caller starts the collect
49+
await waitForCollectStart
50+
51+
// Send wrong digits 123 to the caller (callee expects 1234)
52+
const sendDigits = await call.sendDigits('1w2w3w4w#')
53+
tap.equal(
54+
call.id,
55+
sendDigits.id,
56+
'Inbound - sendDigit returns the same instance'
57+
)
58+
59+
// Wait until the caller ends the collect
60+
await waitForCollectEnd
61+
62+
await call.hangup()
63+
} catch (error) {
64+
console.error('Error answering inbound call', error)
65+
}
66+
},
67+
})
68+
69+
const call = await client.voice.dialSip({
70+
to: makeSipDomainAppAddress({
71+
name: 'to',
72+
domain: domainApp.domain,
73+
}),
74+
from: makeSipDomainAppAddress({
75+
name: 'from',
76+
domain: domainApp.domain,
77+
}),
78+
timeout: 30,
79+
listen: {
80+
onCollectInputStarted(collect) {
81+
tap.hasProps(
82+
collect,
83+
CALL_COLLECT_PROPS,
84+
'voice.dialSip: Collect input started'
85+
)
86+
},
87+
},
88+
})
89+
tap.ok(call.id, 'Outbound - Call resolved')
90+
91+
const unsubCall = await call.listen({
92+
onCollectStarted(collect) {
93+
tap.hasProps(
94+
collect,
95+
CALL_COLLECT_PROPS,
96+
'call.listen: Collect started'
97+
)
98+
},
99+
onCollectEnded(collect) {
100+
// NotOk since we unsubscribe this listener before the collect ends
101+
tap.notOk(collect, 'call.listen: Collect ended')
102+
},
103+
})
104+
105+
// Caller starts a collect
106+
const collect = await call
107+
.collect({
108+
initialTimeout: 4.0,
109+
digits: {
110+
max: 4,
111+
digitTimeout: 10,
112+
terminators: '#',
113+
},
114+
partialResults: true,
115+
continuous: false,
116+
sendStartOfInput: true,
117+
startInputTimers: false,
118+
listen: {
119+
// onUpdated runs three times since callee sends 4 digits (1234)
120+
// 4th (final) digit emits onEnded
121+
onUpdated: (collect) => {
122+
tap.hasProps(
123+
collect,
124+
CALL_COLLECT_PROPS,
125+
'call.collect: Collect updated'
126+
)
127+
},
128+
onFailed: (collect) => {
129+
tap.notOk(collect.id, 'call.collect: Collect failed')
130+
},
131+
},
132+
})
133+
.onStarted()
134+
tap.equal(
135+
call.id,
136+
collect.callId,
137+
'Outbound - Collect returns the same call instance'
138+
)
139+
140+
// Resolve the collect start promise
141+
waitForCollectStartResolve!()
142+
143+
const unsubCollect = await collect.listen({
144+
onEnded: (_collect) => {
145+
tap.hasProps(
146+
_collect,
147+
CALL_COLLECT_PROPS,
148+
'collect.listen: Collect ended'
149+
)
150+
tap.equal(
151+
_collect.id,
152+
collect.id,
153+
'collect.listen: Collect correct id'
154+
)
155+
},
156+
})
157+
158+
await unsubCall()
159+
160+
console.log('Waiting for the digits from the inbound call')
161+
162+
// Compare what caller has received
163+
const recDigits = await collect.ended()
164+
tap.equal(recDigits.digits, '1234', 'Outbound - Received the same digit')
165+
166+
// Resolve the collect end promise
167+
waitForCollectEndResolve!()
168+
169+
// Resolve if the call has ended or ending
170+
const waitForParams = ['ended', 'ending', ['ending', 'ended']] as const
171+
const results = await Promise.all(
172+
waitForParams.map((params) => call.waitFor(params as any))
173+
)
174+
waitForParams.forEach((value, i) => {
175+
if (typeof value === 'string') {
176+
tap.ok(results[i], `"${value}": completed successfully.`)
177+
} else {
178+
tap.ok(
179+
results[i],
180+
`${JSON.stringify(value)}: completed successfully.`
181+
)
182+
}
183+
})
184+
185+
await unsubVoice()
186+
187+
await unsubCollect()
188+
189+
await client.disconnect()
190+
191+
resolve(0)
192+
} catch (error) {
193+
console.error('VoiceCollectAllListeners error', error)
194+
reject(4)
195+
}
196+
})
197+
}
198+
199+
async function main() {
200+
const runner = createTestRunner({
201+
name: 'Voice Collect with all Listeners E2E',
202+
testHandler: handler,
203+
executionTime: 60_000,
204+
useDomainApp: true,
205+
})
206+
207+
await runner.run()
208+
}
209+
210+
main()
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
import tap from 'tap'
2+
import { SignalWire } from '@signalwire/realtime-api'
3+
import {
4+
createTestRunner,
5+
CALL_COLLECT_PROPS,
6+
CALL_PROPS,
7+
TestHandler,
8+
makeSipDomainAppAddress,
9+
} from './utils'
10+
11+
const handler: TestHandler = ({ domainApp }) => {
12+
if (!domainApp) {
13+
throw new Error('Missing domainApp')
14+
}
15+
16+
return new Promise<number>(async (resolve, reject) => {
17+
try {
18+
const client = await SignalWire({
19+
host: process.env.RELAY_HOST || 'relay.swire.io',
20+
project: process.env.RELAY_PROJECT as string,
21+
token: process.env.RELAY_TOKEN as string,
22+
debug: {
23+
logWsTraffic: true,
24+
},
25+
})
26+
27+
let waitForCollectStartResolve: () => void
28+
const waitForCollectStart = new Promise<void>((resolve) => {
29+
waitForCollectStartResolve = resolve
30+
})
31+
let waitForCollectEndResolve: () => void
32+
const waitForCollectEnd = new Promise<void>((resolve) => {
33+
waitForCollectEndResolve = resolve
34+
})
35+
36+
const unsubVoice = await client.voice.listen({
37+
topics: [domainApp.call_relay_context, 'home'],
38+
onCallReceived: async (call) => {
39+
try {
40+
const resultAnswer = await call.answer()
41+
tap.hasProps(call, CALL_PROPS, 'Inbound - Call answered')
42+
tap.equal(
43+
call.id,
44+
resultAnswer.id,
45+
'Inbound - Call answered gets the same instance'
46+
)
47+
48+
// Wait until the caller starts the collect
49+
await waitForCollectStart
50+
51+
// Send wrong digits 123 to the caller (callee expects 1234)
52+
const sendDigits = await call.sendDigits('1w2w3#')
53+
tap.equal(
54+
call.id,
55+
sendDigits.id,
56+
'Inbound - sendDigit returns the same instance'
57+
)
58+
59+
// Wait until the caller ends the collect
60+
await waitForCollectEnd
61+
62+
await call.hangup()
63+
} catch (error) {
64+
console.error('Error answering inbound call', error)
65+
}
66+
},
67+
})
68+
69+
const call = await client.voice.dialSip({
70+
to: makeSipDomainAppAddress({
71+
name: 'to',
72+
domain: domainApp.domain,
73+
}),
74+
from: makeSipDomainAppAddress({
75+
name: 'from',
76+
domain: domainApp.domain,
77+
}),
78+
timeout: 30,
79+
})
80+
tap.ok(call.id, 'Outbound - Call resolved')
81+
82+
const unsubCall = await call.listen({
83+
onCollectStarted: (collect) => {
84+
tap.hasProps(collect, CALL_COLLECT_PROPS, 'Collect started')
85+
tap.equal(collect.callId, call.id, 'Collect correct call id')
86+
},
87+
onCollectInputStarted: (collect) => {
88+
tap.hasProps(collect, CALL_COLLECT_PROPS, 'Collect input started')
89+
},
90+
// onCollectUpdated runs three times since callee sends 4 digits (1234)
91+
// 4th (final) digit emits onCollectEnded
92+
onCollectUpdated: (collect) => {
93+
tap.hasProps(collect, CALL_COLLECT_PROPS, 'Collect updated')
94+
},
95+
onCollectFailed: (collect) => {
96+
tap.notOk(collect.id, 'Collect failed')
97+
},
98+
onCollectEnded: (collect) => {
99+
tap.hasProps(collect, CALL_COLLECT_PROPS, 'Collect ended')
100+
},
101+
})
102+
103+
// Caller starts a collect
104+
const collect = await call
105+
.collect({
106+
initialTimeout: 4.0,
107+
digits: {
108+
max: 4,
109+
digitTimeout: 10,
110+
terminators: '#',
111+
},
112+
partialResults: true,
113+
continuous: false,
114+
sendStartOfInput: true,
115+
startInputTimers: false,
116+
})
117+
.onStarted()
118+
tap.equal(
119+
call.id,
120+
collect.callId,
121+
'Outbound - Collect returns the same call instance'
122+
)
123+
124+
// Resolve the collect start promise
125+
waitForCollectStartResolve!()
126+
127+
console.log('Waiting for the digits from the inbound call')
128+
129+
// Compare what caller has received
130+
const recDigits = await collect.ended()
131+
tap.not(recDigits.digits, '1234', 'Outbound - Received the same digit')
132+
133+
// Resolve the collect end promise
134+
waitForCollectEndResolve!()
135+
136+
// Resolve if the call has ended or ending
137+
const waitForParams = ['ended', 'ending', ['ending', 'ended']] as const
138+
const results = await Promise.all(
139+
waitForParams.map((params) => call.waitFor(params as any))
140+
)
141+
waitForParams.forEach((value, i) => {
142+
if (typeof value === 'string') {
143+
tap.ok(results[i], `"${value}": completed successfully.`)
144+
} else {
145+
tap.ok(
146+
results[i],
147+
`${JSON.stringify(value)}: completed successfully.`
148+
)
149+
}
150+
})
151+
152+
await unsubVoice()
153+
154+
await unsubCall()
155+
156+
await client.disconnect()
157+
158+
resolve(0)
159+
} catch (error) {
160+
console.error('VoiceCollectCallListeners error', error)
161+
reject(4)
162+
}
163+
})
164+
}
165+
166+
async function main() {
167+
const runner = createTestRunner({
168+
name: 'Voice Collect with Call Listeners E2E',
169+
testHandler: handler,
170+
executionTime: 60_000,
171+
useDomainApp: true,
172+
})
173+
174+
await runner.run()
175+
}
176+
177+
main()

0 commit comments

Comments
 (0)