diff --git a/.changeset/eight-vans-unite.md b/.changeset/eight-vans-unite.md new file mode 100644 index 000000000..382b8fd93 --- /dev/null +++ b/.changeset/eight-vans-unite.md @@ -0,0 +1,5 @@ +--- +'@sw-internal/e2e-realtime-api': patch +--- + +Review realtime-api tests using domain apps diff --git a/internal/e2e-realtime-api/src/chat.test.ts b/internal/e2e-realtime-api/src/chat.test.ts index 1df51e005..9a592b194 100644 --- a/internal/e2e-realtime-api/src/chat.test.ts +++ b/internal/e2e-realtime-api/src/chat.test.ts @@ -8,6 +8,7 @@ import { timeoutPromise, SWCloseEvent } from '@signalwire/core' import { Chat as RealtimeAPIChat } from '@signalwire/realtime-api' import { Chat as JSChat } from '@signalwire/js' import { WebSocket } from 'ws' +import { randomUUID } from 'node:crypto' import { createTestRunner, createCRT, sessionStorageMock } from './utils' // @ts-ignore @@ -20,12 +21,12 @@ global.window = { sessionStorage: sessionStorageMock() } const promiseTimeout = 4_000 const promiseException = 4 // error code to identify the Promise timeout // TODO: pass as argument -const channel = 'rw' +const channel = randomUUID() const params = { memberId: 'e2e-uuid-here', channels: { - rw: { + [channel]: { read: true, write: true, }, @@ -57,13 +58,13 @@ const testChatClientSubscribe = ( firstClient.on('member.joined', (member) => { // TODO: Check the member payload - console.log('jsChat member.joined', member) + console.log('jsChat member.joined') events += 1 resolveIfDone() }) secondClient.on('member.joined', (member) => { // TODO: Check the member payload - console.log('rtChat member.joined', member) + console.log('rtChat member.joined') events += 1 resolveIfDone() }) @@ -92,14 +93,14 @@ const testChatClientPublish = ( const now = Date.now() firstClient.once('message', (message) => { - console.log('jsChat message', message) + console.log('jsChat message') if (message.meta.now === now) { events += 1 resolveIfDone() } }) secondClient.once('message', (message) => { - console.log('rtChat message', message) + console.log('rtChat message') if (message.meta.now === now) { events += 1 resolveIfDone() @@ -146,13 +147,13 @@ const testChatClientUnsubscribe = ( firstClient.on('member.left', (member) => { // TODO: Check the member payload - console.log('jsChat member.left', member) + console.log('jsChat member.left') events += 1 resolveIfDone() }) secondClient.on('member.left', (member) => { // TODO: Check the member payload - console.log('rtChat member.left', member) + console.log('rtChat member.left') events += 1 resolveIfDone() }) @@ -198,14 +199,14 @@ const testChatClientSetAndGetMemberState = ( firstClient.once('member.updated', (member) => { // TODO: Check the member payload - console.log('jsChat member.updated', member) + console.log('jsChat member.updated') if (member.state.email === 'e2e@example.com') { events += 1 resolveIfDone() } }) secondClient.once('member.updated', (member) => { - console.log('rtChat member.updated', member) + console.log('rtChat member.updated') if (member.state.email === 'e2e@example.com') { events += 1 resolveIfDone() @@ -218,7 +219,7 @@ const testChatClientSetAndGetMemberState = ( memberId: params.memberId, }) // TODO: Better compare getStateResult - if (!getStateResult.channels.rw.state) { + if (!getStateResult.channels[channel].state) { console.error('Invalid state', JSON.stringify(getStateResult)) reject(4) } @@ -314,6 +315,7 @@ async function main() { const runner = createTestRunner({ name: 'Chat E2E', testHandler: handler, + executionTime: 15_000, }) await runner.run() diff --git a/internal/e2e-realtime-api/src/pubSub.test.ts b/internal/e2e-realtime-api/src/pubSub.test.ts index 37422427f..7da663124 100644 --- a/internal/e2e-realtime-api/src/pubSub.test.ts +++ b/internal/e2e-realtime-api/src/pubSub.test.ts @@ -10,6 +10,7 @@ import { timeoutPromise, SWCloseEvent } from '@signalwire/core' import { PubSub as RealtimeAPIPubSub } from '@signalwire/realtime-api' import { PubSub as JSPubSub } from '@signalwire/js' import { WebSocket } from 'ws' +import { randomUUID } from 'node:crypto' import { createTestRunner, createCRT, sessionStorageMock } from './utils' // @ts-ignore @@ -22,12 +23,12 @@ global.window = { sessionStorage: sessionStorageMock() } const promiseTimeout = 4_000 const promiseException = 4 // error code to identify the Promise timeout // TODO: pass as argument -const channel = 'rw' +const channel = randomUUID() const params = { memberId: 'e2e-uuid-here', channels: { - rw: { + [channel]: { read: true, write: true, }, @@ -79,14 +80,14 @@ const testPubSubClientPublish = ( const now = Date.now() firstClient.once('message', (message) => { - console.log('jsPubSub message', message) + console.log('jsPubSub message') if (message.meta.now === now) { events += 1 resolveIfDone() } }) secondClient.once('message', (message) => { - console.log('rtPubSub message', message) + console.log('rtPubSub message') if (message.meta.now === now) { events += 1 resolveIfDone() diff --git a/internal/e2e-realtime-api/src/success.test.ts b/internal/e2e-realtime-api/src/success.test.ts deleted file mode 100644 index 43fff9044..000000000 --- a/internal/e2e-realtime-api/src/success.test.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { createTestRunner } from './utils' - -const handler = () => { - return new Promise((resolve) => { - setTimeout(() => resolve(0), 2000) - }) -} - -async function main() { - const runner = createTestRunner({ - name: 'test-success', - testHandler: handler, - }) - - await runner.run() -} - -main() diff --git a/internal/e2e-realtime-api/src/task.test.ts b/internal/e2e-realtime-api/src/task.test.ts index d482960b9..f41e64d24 100644 --- a/internal/e2e-realtime-api/src/task.test.ts +++ b/internal/e2e-realtime-api/src/task.test.ts @@ -1,9 +1,10 @@ +import { randomUUID } from 'node:crypto' import { Task } from '@signalwire/realtime-api' import { createTestRunner } from './utils' const handler = () => { return new Promise(async (resolve, reject) => { - const context = 'task-e2e' + const context = randomUUID() const firstPayload = { id: Date.now(), item: 'first', diff --git a/internal/e2e-realtime-api/src/utils.ts b/internal/e2e-realtime-api/src/utils.ts index 0a6931826..da7ec4319 100644 --- a/internal/e2e-realtime-api/src/utils.ts +++ b/internal/e2e-realtime-api/src/utils.ts @@ -1,20 +1,56 @@ import { request } from 'node:https' +import { randomUUID, randomBytes } from 'node:crypto' /** * 10 seconds to execute the script by default */ const MAX_EXECUTION_TIME = 10_000 +interface DomainApp { + type: 'domain_application' + id: string + name: string + domain: string + identifier: string + ip_auth_enabled: boolean + ip_auth: string[] + call_handler: 'relay_context' + call_request_url: string | null + call_request_method: string + call_fallback_url: string | null + call_fallback_method: string + call_status_callback_url: string | null + call_status_callback_method: string + call_relay_context: string + call_laml_application_id: string | null + call_video_room_id: string | null + call_relay_script_url: string | null + encryption: 'optional' + codecs: ('PCMU' | 'PCMA')[] + ciphers: string[] +} +interface TestHandlerParams { + domainApp?: DomainApp +} + +export type TestHandler = + | (() => Promise) + | ((params: TestHandlerParams) => Promise) + interface CreateTestRunnerParams { + uuid?: string name: string - testHandler(): Promise + testHandler: TestHandler executionTime?: number + useDomainApp?: boolean } export const createTestRunner = ({ + uuid = randomUUID(), name, testHandler, executionTime = MAX_EXECUTION_TIME, + useDomainApp = false, }: CreateTestRunnerParams) => { let timer: ReturnType @@ -40,7 +76,16 @@ export const createTestRunner = ({ start() try { - const exitCode = await testHandler() + const params: TestHandlerParams = {} + if (useDomainApp) { + params.domainApp = await createDomainApp({ + name: `d-app-${uuid}`, + identifier: uuid, + call_handler: 'relay_context', + call_relay_context: `d-app-ctx-${uuid}`, + }) + } + const exitCode = await testHandler(params) done(exitCode) } catch (error) { clearTimeout(timer) @@ -127,3 +172,47 @@ export const sleep = (ms = 3000) => { setTimeout(r, ms) }) } + +export const makeSipDomainAppAddress = ({ name, domain }) => { + return `sip:${name}-${randomBytes(16).toString('hex')}@${domain}.${ + process.env.DAPP_DOMAIN + }` +} + +type CreateDomainAppParams = { + name: string + identifier: string + call_handler: 'relay_context' + call_relay_context: string +} +const createDomainApp = (params: CreateDomainAppParams): Promise => { + return new Promise((resolve, reject) => { + const data = JSON.stringify(params) + const options = { + host: process.env.API_HOST, + port: 443, + method: 'POST', + path: '/api/relay/rest/domain_applications', + headers: { + Authorization: getAuthorization(), + 'Content-Type': 'application/json', + 'Content-Length': data.length, + }, + } + const req = request(options, (response) => { + let body = '' + response.on('data', (chunk) => { + body += chunk + }) + + response.on('end', () => { + resolve(JSON.parse(body)) + }) + }) + + req.on('error', reject) + + req.write(data) + req.end() + }) +} diff --git a/internal/e2e-realtime-api/src/voice.test.ts b/internal/e2e-realtime-api/src/voice.test.ts index 9a4ffaf5e..43a471852 100644 --- a/internal/e2e-realtime-api/src/voice.test.ts +++ b/internal/e2e-realtime-api/src/voice.test.ts @@ -1,17 +1,24 @@ import tap from 'tap' import { Voice } from '@signalwire/realtime-api' -import { createTestRunner } from './utils' - -const handler = () => { +import { + type TestHandler, + createTestRunner, + makeSipDomainAppAddress, +} from './utils' + +const handler: TestHandler = ({ domainApp }) => { + if (!domainApp) { + throw new Error('Missing domainApp') + } return new Promise(async (resolve, reject) => { const client = new Voice.Client({ - host: process.env.RELAY_HOST || 'relay.swire.io', + host: process.env.RELAY_HOST, project: process.env.RELAY_PROJECT as string, token: process.env.RELAY_TOKEN as string, - topics: [process.env.VOICE_CONTEXT as string], + topics: [domainApp.call_relay_context], // logLevel: "trace", debug: { - logWsTraffic: true, + logWsTraffic: false, }, }) @@ -151,17 +158,21 @@ const handler = () => { 'Correct Digits were entered' ) - console.log( - `Connecting ${process.env.VOICE_DIAL_FROM_NUMBER} to ${process.env.VOICE_CONNECT_TO_NUMBER}` - ) + console.log(`Connecting to a peer..`) const ringback = new Voice.Playlist().add( Voice.Playlist.Ringtone({ name: 'it', }) ) - const peer = await call.connectPhone({ - from: process.env.VOICE_DIAL_FROM_NUMBER!, - to: process.env.VOICE_CONNECT_TO_NUMBER!, + const peer = await call.connectSip({ + from: makeSipDomainAppAddress({ + name: 'connect-from', + domain: domainApp.domain, + }), + to: makeSipDomainAppAddress({ + name: 'connect-to', + domain: domainApp.domain, + }), timeout: 30, ringback, // optional maxPricePerMinute: 10, @@ -212,9 +223,15 @@ const handler = () => { }) try { - const call = await client.dialPhone({ - to: process.env.VOICE_DIAL_TO_NUMBER as string, - from: process.env.VOICE_DIAL_FROM_NUMBER as string, + const call = await client.dialSip({ + to: makeSipDomainAppAddress({ + name: 'to', + domain: domainApp.domain, + }), + from: makeSipDomainAppAddress({ + name: 'from', + domain: domainApp.domain, + }), timeout: 30, maxPricePerMinute: 10, }) @@ -266,6 +283,7 @@ async function main() { name: 'Voice E2E', testHandler: handler, executionTime: 60_000, + useDomainApp: true, }) await runner.run() diff --git a/internal/e2e-realtime-api/src/voiceCollect.test.ts b/internal/e2e-realtime-api/src/voiceCollect.test.ts index 65eb9a1d8..c00af3de7 100644 --- a/internal/e2e-realtime-api/src/voiceCollect.test.ts +++ b/internal/e2e-realtime-api/src/voiceCollect.test.ts @@ -1,14 +1,21 @@ import tap from 'tap' import { Voice } from '@signalwire/realtime-api' -import { createTestRunner } from './utils' - -const handler = () => { +import { + type TestHandler, + createTestRunner, + makeSipDomainAppAddress, +} from './utils' + +const handler: TestHandler = ({ domainApp }) => { + if (!domainApp) { + throw new Error('Missing domainApp') + } return new Promise(async (resolve, reject) => { const client = new Voice.Client({ - host: process.env.RELAY_HOST || 'relay.swire.io', + host: process.env.RELAY_HOST, project: process.env.RELAY_PROJECT as string, token: process.env.RELAY_TOKEN as string, - contexts: [process.env.VOICE_CONTEXT as string], + contexts: [domainApp.call_relay_context], // logLevel: "trace", debug: { logWsTraffic: true, @@ -37,7 +44,7 @@ const handler = () => { ) call.on('collect.started', (collect) => { - console.log('>>> collect.started', collect) + console.log('>>> collect.started') }) call.on('collect.updated', (collect) => { console.log('>>> collect.updated', collect.digits) @@ -83,10 +90,15 @@ const handler = () => { }) try { - const call = await client.dialPhone({ - // make an outbound call to an `office` context to trigger the `call.received` event above - to: process.env.VOICE_DIAL_TO_NUMBER as string, - from: process.env.VOICE_DIAL_FROM_NUMBER as string, + const call = await client.dialSip({ + to: makeSipDomainAppAddress({ + name: 'to', + domain: domainApp.domain, + }), + from: makeSipDomainAppAddress({ + name: 'from', + domain: domainApp.domain, + }), timeout: 30, }) tap.ok(call.id, 'Call resolved') @@ -132,6 +144,7 @@ async function main() { name: 'Voice Collect E2E', testHandler: handler, executionTime: 60_000, + useDomainApp: true, }) await runner.run() diff --git a/internal/e2e-realtime-api/src/voiceDetect.test.ts b/internal/e2e-realtime-api/src/voiceDetect.test.ts index f2b74d8ba..5e268a3ec 100644 --- a/internal/e2e-realtime-api/src/voiceDetect.test.ts +++ b/internal/e2e-realtime-api/src/voiceDetect.test.ts @@ -1,14 +1,21 @@ import tap from 'tap' import { Voice } from '@signalwire/realtime-api' -import { createTestRunner } from './utils' +import { + type TestHandler, + createTestRunner, + makeSipDomainAppAddress, +} from './utils' -const handler = () => { +const handler: TestHandler = ({ domainApp }) => { + if (!domainApp) { + throw new Error('Missing domainApp') + } return new Promise(async (resolve, reject) => { const client = new Voice.Client({ host: process.env.RELAY_HOST, project: process.env.RELAY_PROJECT as string, token: process.env.RELAY_TOKEN as string, - contexts: [process.env.VOICE_CONTEXT as string], + contexts: [domainApp.call_relay_context], }) let waitForDetectStartResolve @@ -64,9 +71,15 @@ const handler = () => { }) try { - const call = await client.dialPhone({ - to: process.env.VOICE_DIAL_TO_NUMBER as string, - from: process.env.VOICE_DIAL_FROM_NUMBER as string, + const call = await client.dialSip({ + to: makeSipDomainAppAddress({ + name: 'to', + domain: domainApp.domain, + }), + from: makeSipDomainAppAddress({ + name: 'from', + domain: domainApp.domain, + }), timeout: 30, }) tap.ok(call.id, 'Outbound - Call resolved') @@ -103,6 +116,7 @@ async function main() { name: 'Voice Detect E2E', testHandler: handler, executionTime: 30_000, + useDomainApp: true, }) await runner.run() diff --git a/internal/e2e-realtime-api/src/voicePass.test.ts b/internal/e2e-realtime-api/src/voicePass.test.ts index 7292558d9..4265b3090 100644 --- a/internal/e2e-realtime-api/src/voicePass.test.ts +++ b/internal/e2e-realtime-api/src/voicePass.test.ts @@ -1,14 +1,21 @@ import tap from 'tap' import { Voice } from '@signalwire/realtime-api' -import { createTestRunner } from './utils' +import { + type TestHandler, + createTestRunner, + makeSipDomainAppAddress, +} from './utils' -const handler = () => { +const handler: TestHandler = ({ domainApp }) => { + if (!domainApp) { + throw new Error('Missing domainApp') + } return new Promise(async (resolve, reject) => { const options = { - host: process.env.RELAY_HOST || 'relay.swire.io', + host: process.env.RELAY_HOST, project: process.env.RELAY_PROJECT as string, token: process.env.RELAY_TOKEN as string, - contexts: [process.env.VOICE_CONTEXT as string], + contexts: [domainApp.call_relay_context], // logLevel: "trace", debug: { // logWsTraffic: true, @@ -72,12 +79,18 @@ const handler = () => { }) try { - const call = await client1.dialPhone({ - // make an outbound call to an `office` context to trigger the `call.received` event above - to: process.env.VOICE_DIAL_TO_NUMBER as string, - from: process.env.VOICE_DIAL_FROM_NUMBER as string, + const call = await client1.dialSip({ + to: makeSipDomainAppAddress({ + name: 'to', + domain: domainApp.domain, + }), + from: makeSipDomainAppAddress({ + name: 'from', + domain: domainApp.domain, + }), timeout: 30, }) + tap.ok(call.id, 'Call resolved') const waitForParams = ['ended', 'ending', ['ending', 'ended']] as const @@ -108,6 +121,7 @@ async function main() { name: 'Voice Pass E2E', testHandler: handler, executionTime: 60_000, + useDomainApp: true, }) await runner.run() diff --git a/internal/e2e-realtime-api/src/voicePlayback.test.ts b/internal/e2e-realtime-api/src/voicePlayback.test.ts index 17b5c244d..56d0fe863 100644 --- a/internal/e2e-realtime-api/src/voicePlayback.test.ts +++ b/internal/e2e-realtime-api/src/voicePlayback.test.ts @@ -1,14 +1,21 @@ import tap from 'tap' import { Voice } from '@signalwire/realtime-api' -import { createTestRunner } from './utils' - -const handler = () => { +import { + type TestHandler, + createTestRunner, + makeSipDomainAppAddress, +} from './utils' + +const handler: TestHandler = ({ domainApp }) => { + if (!domainApp) { + throw new Error('Missing domainApp') + } return new Promise(async (resolve, reject) => { const client = new Voice.Client({ - host: process.env.RELAY_HOST || 'relay.swire.io', + host: process.env.RELAY_HOST, project: process.env.RELAY_PROJECT as string, token: process.env.RELAY_TOKEN as string, - contexts: [process.env.VOICE_CONTEXT as string], + topics: [domainApp.call_relay_context], }) client.on('call.received', async (call) => { @@ -68,10 +75,17 @@ const handler = () => { }) try { - const call = await client.dialPhone({ - to: process.env.VOICE_DIAL_TO_NUMBER as string, - from: process.env.VOICE_DIAL_FROM_NUMBER as string, + const call = await client.dialSip({ + to: makeSipDomainAppAddress({ + name: 'to', + domain: domainApp.domain, + }), + from: makeSipDomainAppAddress({ + name: 'from', + domain: domainApp.domain, + }), timeout: 30, + maxPricePerMinute: 10, }) tap.ok(call.id, 'Outbound - Call resolved') @@ -143,6 +157,7 @@ async function main() { name: 'Voice Playback E2E', testHandler: handler, executionTime: 60_000, + useDomainApp: true, }) await runner.run() diff --git a/internal/e2e-realtime-api/src/voicePlaybackMultiple.test.ts b/internal/e2e-realtime-api/src/voicePlaybackMultiple.test.ts index 4b0b38145..5940c654b 100644 --- a/internal/e2e-realtime-api/src/voicePlaybackMultiple.test.ts +++ b/internal/e2e-realtime-api/src/voicePlaybackMultiple.test.ts @@ -1,14 +1,21 @@ import tap from 'tap' import { Voice } from '@signalwire/realtime-api' -import { createTestRunner } from './utils' - -const handler = () => { +import { + type TestHandler, + createTestRunner, + makeSipDomainAppAddress, +} from './utils' + +const handler: TestHandler = ({ domainApp }) => { + if (!domainApp) { + throw new Error('Missing domainApp') + } return new Promise(async (resolve, reject) => { const client = new Voice.Client({ - host: process.env.RELAY_HOST || 'relay.swire.io', + host: process.env.RELAY_HOST, project: process.env.RELAY_PROJECT as string, token: process.env.RELAY_TOKEN as string, - contexts: [process.env.VOICE_CONTEXT as string], + topics: [domainApp.call_relay_context], }) let waitForOutboundPlaybackStartResolve @@ -107,10 +114,17 @@ const handler = () => { }) try { - const call = await client.dialPhone({ - to: process.env.VOICE_DIAL_TO_NUMBER as string, - from: process.env.VOICE_DIAL_FROM_NUMBER as string, + const call = await client.dialSip({ + to: makeSipDomainAppAddress({ + name: 'to', + domain: domainApp.domain, + }), + from: makeSipDomainAppAddress({ + name: 'from', + domain: domainApp.domain, + }), timeout: 30, + maxPricePerMinute: 10, }) tap.ok(call.id, 'Outbound - Call resolved') @@ -172,6 +186,7 @@ async function main() { name: 'Voice Playback multiple E2E', testHandler: handler, executionTime: 60_000, + useDomainApp: true, }) await runner.run() diff --git a/internal/e2e-realtime-api/src/voicePrompt.test.ts b/internal/e2e-realtime-api/src/voicePrompt.test.ts index c87384781..2feedc612 100644 --- a/internal/e2e-realtime-api/src/voicePrompt.test.ts +++ b/internal/e2e-realtime-api/src/voicePrompt.test.ts @@ -1,16 +1,23 @@ import tap from 'tap' import { Voice } from '@signalwire/realtime-api' -import { createTestRunner } from './utils' - -const handler = () => { +import { + type TestHandler, + createTestRunner, + makeSipDomainAppAddress, +} from './utils' + +const handler: TestHandler = ({ domainApp }) => { + if (!domainApp) { + throw new Error('Missing domainApp') + } return new Promise(async (resolve, reject) => { const client = new Voice.Client({ - host: process.env.RELAY_HOST || 'relay.swire.io', + host: process.env.RELAY_HOST, project: process.env.RELAY_PROJECT as string, token: process.env.RELAY_TOKEN as string, - contexts: [process.env.VOICE_CONTEXT as string], + topics: [domainApp.call_relay_context], debug: { - logWsTraffic: true, + logWsTraffic: false, }, }) @@ -71,9 +78,15 @@ const handler = () => { }) try { - const call = await client.dialPhone({ - to: process.env.VOICE_DIAL_TO_NUMBER as string, - from: process.env.VOICE_DIAL_FROM_NUMBER as string, + const call = await client.dialSip({ + to: makeSipDomainAppAddress({ + name: 'to', + domain: domainApp.domain, + }), + from: makeSipDomainAppAddress({ + name: 'from', + domain: domainApp.domain, + }), timeout: 30, }) tap.ok(call.id, 'Outbound - Call resolved') @@ -139,6 +152,7 @@ async function main() { name: 'Voice Prompt E2E', testHandler: handler, executionTime: 60_000, + useDomainApp: true, }) await runner.run() diff --git a/internal/e2e-realtime-api/src/voiceRecordMultiple.test.ts b/internal/e2e-realtime-api/src/voiceRecordMultiple.test.ts index 74a78a221..8528638c5 100644 --- a/internal/e2e-realtime-api/src/voiceRecordMultiple.test.ts +++ b/internal/e2e-realtime-api/src/voiceRecordMultiple.test.ts @@ -1,16 +1,23 @@ import tap from 'tap' import { Voice } from '@signalwire/realtime-api' -import { createTestRunner } from './utils' - -const handler = () => { +import { + type TestHandler, + createTestRunner, + makeSipDomainAppAddress, +} from './utils' + +const handler: TestHandler = ({ domainApp }) => { + if (!domainApp) { + throw new Error('Missing domainApp') + } return new Promise(async (resolve, reject) => { const client = new Voice.Client({ - host: process.env.RELAY_HOST || 'relay.swire.io', + host: process.env.RELAY_HOST, project: process.env.RELAY_PROJECT as string, token: process.env.RELAY_TOKEN as string, - contexts: [process.env.VOICE_CONTEXT as string], + contexts: [domainApp.call_relay_context], debug: { - logWsTraffic: true, + logWsTraffic: false, }, }) @@ -76,9 +83,15 @@ const handler = () => { }) try { - const call = await client.dialPhone({ - to: process.env.VOICE_DIAL_TO_NUMBER as string, - from: process.env.VOICE_DIAL_FROM_NUMBER as string, + const call = await client.dialSip({ + to: makeSipDomainAppAddress({ + name: 'to', + domain: domainApp.domain, + }), + from: makeSipDomainAppAddress({ + name: 'from', + domain: domainApp.domain, + }), timeout: 30, }) tap.ok(call.id, 'Outbound - Call resolved') @@ -138,6 +151,7 @@ async function main() { name: 'Voice Recording multiple E2E', testHandler: handler, executionTime: 60_000, + useDomainApp: true, }) await runner.run() diff --git a/internal/e2e-realtime-api/src/voiceRecording.test.ts b/internal/e2e-realtime-api/src/voiceRecording.test.ts index 839067b66..81cf78555 100644 --- a/internal/e2e-realtime-api/src/voiceRecording.test.ts +++ b/internal/e2e-realtime-api/src/voiceRecording.test.ts @@ -1,6 +1,10 @@ import tap from 'tap' import { Voice } from '@signalwire/realtime-api' -import { createTestRunner } from './utils' +import { + type TestHandler, + createTestRunner, + makeSipDomainAppAddress, +} from './utils' const CALL_RECORDING_GETTERS = [ 'id', @@ -13,16 +17,20 @@ const CALL_RECORDING_GETTERS = [ 'duration', 'record', ] -const handler = () => { + +const handler: TestHandler = ({ domainApp }) => { + if (!domainApp) { + throw new Error('Missing domainApp') + } return new Promise(async (resolve, reject) => { // Expect exact 12 tests tap.plan(12) const client = new Voice.Client({ - host: process.env.RELAY_HOST || 'relay.swire.io', + host: process.env.RELAY_HOST, project: process.env.RELAY_PROJECT as string, token: process.env.RELAY_TOKEN as string, - contexts: [process.env.VOICE_CONTEXT as string], + contexts: [domainApp.call_relay_context], debug: { logWsTraffic: true, }, @@ -113,10 +121,15 @@ const handler = () => { }) try { - // Make an outbound call - const call = await client.dialPhone({ - to: process.env.VOICE_DIAL_TO_NUMBER as string, - from: process.env.VOICE_DIAL_FROM_NUMBER as string, + const call = await client.dialSip({ + to: makeSipDomainAppAddress({ + name: 'to', + domain: domainApp.domain, + }), + from: makeSipDomainAppAddress({ + name: 'from', + domain: domainApp.domain, + }), timeout: 30, }) tap.ok(call.id, 'Outbound - Call resolved') @@ -169,6 +182,7 @@ async function main() { name: 'Voice Recording E2E', testHandler: handler, executionTime: 30_000, + useDomainApp: true, }) await runner.run() diff --git a/internal/e2e-realtime-api/src/voiceTap.test.ts b/internal/e2e-realtime-api/src/voiceTap.test.ts index ae99ab7d5..8614f7da7 100644 --- a/internal/e2e-realtime-api/src/voiceTap.test.ts +++ b/internal/e2e-realtime-api/src/voiceTap.test.ts @@ -1,14 +1,21 @@ import tap from 'tap' import { Voice } from '@signalwire/realtime-api' -import { createTestRunner } from './utils' +import { + type TestHandler, + createTestRunner, + makeSipDomainAppAddress, +} from './utils' -const handler = () => { +const handler: TestHandler = ({ domainApp }) => { + if (!domainApp) { + throw new Error('Missing domainApp') + } return new Promise(async (resolve, reject) => { const client = new Voice.Client({ - host: process.env.RELAY_HOST || 'relay.swire.io', + host: process.env.RELAY_HOST, project: process.env.RELAY_PROJECT as string, token: process.env.RELAY_TOKEN as string, - contexts: [process.env.VOICE_CONTEXT as string], + contexts: [domainApp.call_relay_context], }) let waitForTheAnswerResolve: (value: void) => void @@ -46,9 +53,15 @@ const handler = () => { }) try { - const call = await client.dialPhone({ - to: process.env.VOICE_DIAL_TO_NUMBER as string, - from: process.env.VOICE_DIAL_FROM_NUMBER as string, + const call = await client.dialSip({ + to: makeSipDomainAppAddress({ + name: 'to', + domain: domainApp.domain, + }), + from: makeSipDomainAppAddress({ + name: 'from', + domain: domainApp.domain, + }), timeout: 30, }) tap.ok(call.id, 'Outbound - Call resolved') @@ -86,6 +99,7 @@ async function main() { name: 'Voice Tap E2E', testHandler: handler, executionTime: 60_000, + useDomainApp: true, }) await runner.run()