From bb8a73d1390b4df966dc21f45d74686f145cc7a6 Mon Sep 17 00:00:00 2001 From: Giacomo Vacca Date: Thu, 13 Feb 2025 17:38:09 +0100 Subject: [PATCH 01/14] e2e tests, CF, agent and guest --- internal/e2e-js/fixtures.ts | 13 +- internal/e2e-js/playwright.config.ts | 2 +- .../tests/callfabric/agent_customer.spec.ts | 124 +++++++++++++++ internal/e2e-js/utils.ts | 141 ++++++++++++++++++ 4 files changed, 277 insertions(+), 3 deletions(-) create mode 100644 internal/e2e-js/tests/callfabric/agent_customer.spec.ts diff --git a/internal/e2e-js/fixtures.ts b/internal/e2e-js/fixtures.ts index 05d72a8e6..a08b8610d 100644 --- a/internal/e2e-js/fixtures.ts +++ b/internal/e2e-js/fixtures.ts @@ -1,9 +1,12 @@ import { PageWithWsInspector, intercepWsTraffic } from 'playwrigth-ws-inspector' import { test as baseTest, expect, type Page } from '@playwright/test' import { + CreatecXMLScriptParams, CreateRelayAppResourceParams, CreateSWMLAppResourceParams, + ApplicationResource, Resource, + createcXMLScriptResource, createRelayAppResource, createSWMLAppResource, createVideoRoomResource, @@ -23,10 +26,11 @@ type CustomFixture = { }): Promise> createCustomVanillaPage(options: { name: string }): Promise resource: { + createcXMLScriptResource: typeof createcXMLScriptResource createVideoRoomResource: typeof createVideoRoomResource createSWMLAppResource: typeof createSWMLAppResource createRelayAppResource: typeof createRelayAppResource - resources: Resource[] + resources: ApplicationResource[] } } @@ -88,7 +92,7 @@ const test = baseTest.extend({ console.log('Cleaning up pages..') }, resource: async ({}, use) => { - const resources: Resource[] = [] + const resources: ApplicationResource[] = [] const resource = { createVideoRoomResource: async (params?: string) => { @@ -96,6 +100,11 @@ const test = baseTest.extend({ resources.push(data) return data }, + createcXMLScriptResource: async (params: CreatecXMLScriptParams) => { + const data = await createcXMLScriptResource(params) + resources.push(data) + return data + }, createSWMLAppResource: async (params: CreateSWMLAppResourceParams) => { const data = await createSWMLAppResource(params) resources.push(data) diff --git a/internal/e2e-js/playwright.config.ts b/internal/e2e-js/playwright.config.ts index 4d0c377d5..78e785532 100644 --- a/internal/e2e-js/playwright.config.ts +++ b/internal/e2e-js/playwright.config.ts @@ -62,7 +62,7 @@ const useDesktopChrome = { ...devices['Desktop Chrome'], launchOptions: { // devtools: true, - // headless: false, + headless: false, args: [ '--use-fake-ui-for-media-stream', '--use-fake-device-for-media-stream', diff --git a/internal/e2e-js/tests/callfabric/agent_customer.spec.ts b/internal/e2e-js/tests/callfabric/agent_customer.spec.ts new file mode 100644 index 000000000..28516da16 --- /dev/null +++ b/internal/e2e-js/tests/callfabric/agent_customer.spec.ts @@ -0,0 +1,124 @@ +import { uuid } from '@signalwire/core' +import { test } from '../../fixtures' +import { expect } from '../../fixtures' +import { + SERVER_URL, + createCFClient, + createGuestCFClient, + dialAddress, + expectCFFinalEvents, + expectCFInitialEvents, + expectPageReceiveAudio, + getResourceAddresses, +} from '../../utils' + +test.describe('CallFabric Agent/Customer interaction, cXML scripts', () => { + + const cXMLScriptAgentContent = { + call_handler_script: '4567486' + } + const cXMLScriptCustomerContent = { + call_handler_script: '4567486' + } + + test('agent and customer should dial an address linked to a cXML script and expect to join a Conference', async ({ + createCustomPage, + resource, + }) => { + // Agent + const agent_page = await createCustomPage({ name: '[agent_page]' }) + await agent_page.goto(SERVER_URL) + + const agentResourceName = `e2e-cxml-script-agent_${uuid()}` + const agent_resource_data = await resource.createcXMLScriptResource({ + name: agentResourceName, + contents: cXMLScriptAgentContent, + }) + + expect(agent_resource_data.cxml_application?.id).toBeDefined() + + await createCFClient(agent_page) + + await dialAddress(agent_page, { + address: `/private/${agentResourceName}`, // or /public/? + shouldWaitForJoin: false, + shouldStartCall: false, + dialOptions: { logLevel: 'debug', debug: { logWsTraffic: true }} + }) + + await agent_page.evaluate(async () => { + // @ts-expect-error + const call = window._roomObj + +// await call.start() + call.start() + }) + + console.log("Address dialled by Agent...") + // const expectInitialEventsForAgent = expectCFInitialEvents(agent_page, []) + // console.log("After CF Initial events for agent...") + + + + console.log('--------- creating customer ------------------') + // Customer + const customer_page = await createCustomPage({ name: '[customer_page]' }) + await customer_page.goto(SERVER_URL) + + const customerResourceName = `e2e-cxml-script-customer_${uuid()}` + const customer_resource_data = await resource.createcXMLScriptResource({ + name: customerResourceName, + contents: cXMLScriptCustomerContent, + }) + + expect(customer_resource_data.id).toBeDefined() + + // Time to retrieve the cXML script address(es) + const resource_addresses = await getResourceAddresses(customer_resource_data.id) + const allowed_addresses: string[] = resource_addresses.data.map((address: { id: any }) => address.id ?? '') + + console.log("Allowed addresses: ", allowed_addresses, " <---------------") + + await createGuestCFClient(customer_page, { allowed_addresses: allowed_addresses}) + + // Dial the resource address + await dialAddress(customer_page, { + address: `/private/${customerResourceName}`, // or /public/? + shouldWaitForJoin: false, + shouldStartCall: false, + dialOptions: { logLevel: 'debug', debug: { logWsTraffic: true }} + }) + + await customer_page.evaluate(async () => { + // @ts-expect-error + const call = window._roomObj + + await call.start() + }) + + console.log("Address dialled by Customer...") + // const expectInitialEventsForCustomer = expectCFInitialEvents(customer_page, []) + // console.log("After CF Initial events for customer...") + + + + + // await expectInitialEventsForAgent +// await expectInitialEventsForCustomer + + + + + + console.log("Expect to receive audio...") + await expectPageReceiveAudio(agent_page) + await expectPageReceiveAudio(customer_page) + + console.log("Expect final events...") + await expectCFFinalEvents(agent_page) + await expectCFFinalEvents(customer_page) + + console.log("Should do something or hang up...") + // hangup??? + }) +}) diff --git a/internal/e2e-js/utils.ts b/internal/e2e-js/utils.ts index 229c480e3..501504d47 100644 --- a/internal/e2e-js/utils.ts +++ b/internal/e2e-js/utils.ts @@ -153,6 +153,43 @@ export const createTestSATToken = async () => { return data.token } +interface GuestSATTokenRequest { + allowed_addresses: string[]; +} +export const createGuestSATToken = async (bodyData: GuestSATTokenRequest) => { + const response = await fetch( + `https://${process.env.API_HOST}/api/fabric/guests/tokens`, + { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Authorization: `Basic ${BASIC_TOKEN}`, + }, + body: JSON.stringify(bodyData), + } + ) + const data = await response.json() + console.log("---- guest token, data: ", data, " <--------------------") + return data.token +} + +export const getResourceAddresses = async (resource_id: string) => { + const response = await fetch( + `https://${process.env.API_HOST}/api/fabric/resources/${resource_id}/addresses`, + { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + Authorization: `Basic ${BASIC_TOKEN}`, + }, + } + ) + const data = await response.json() + console.log("---- get resource addresses for resource ID [", resource_id, "], response: ", data, " <--------------------") + return data +} + + interface CreateTestCRTOptions { ttl: number member_id: string @@ -528,6 +565,71 @@ export const createCFClient = async ( return swClient } +export const createGuestCFClient = async ( + page: Page, + bodyData: GuestSATTokenRequest, + params?: CreateCFClientParams, +) => { + const sat = await createGuestSATToken(bodyData) + if (!sat) { + console.error('Invalid Guest SAT. Exiting...') + process.exit(4) + } + + const { attachSagaMonitor = false } = params || {} + + const swClient = await page.evaluate( + async (options) => { + const _runningWorkers: any[] = [] + // @ts-expect-error + window._runningWorkers = _runningWorkers + const addTask = (task: any) => { + if (!_runningWorkers.includes(task)) { + _runningWorkers.push(task) + } + } + const removeTask = (task: any) => { + const index = _runningWorkers.indexOf(task) + if (index > -1) { + _runningWorkers.splice(index, 1) + } + } + + const sagaMonitor = { + effectResolved: (_effectId: number, result: any) => { + if (result?.toPromise) { + addTask(result) + // Remove the task when it completes or is cancelled + result.toPromise().finally(() => { + removeTask(result) + }) + } + }, + } + + // @ts-expect-error + const SignalWire = window._SWJS.SignalWire + const client: SignalWireContract = await SignalWire({ + host: options.RELAY_HOST, + token: options.API_TOKEN, + debug: { logWsTraffic: true }, + ...(options.attachSagaMonitor && { sagaMonitor }), + }) + + // @ts-expect-error + window._client = client + return client + }, + { + RELAY_HOST: process.env.RELAY_HOST, + API_TOKEN: sat, + attachSagaMonitor, + } + ) + + return swClient +} + interface DialAddressParams { address: string dialOptions?: Record @@ -1336,6 +1438,15 @@ export interface Resource { created_at: string } +export interface CXMLApplication { + id: string + // and other things +} + +export interface ApplicationResource extends Resource { + cxml_application?: CXMLApplication +} + export const createVideoRoomResource = async (name?: string) => { const response = await fetch( `https://${process.env.API_HOST}/api/fabric/resources/conference_rooms`, @@ -1383,6 +1494,36 @@ export const createSWMLAppResource = async ({ return data } +export interface CreatecXMLScriptParams { + name?: string + contents: Record +} +export const createcXMLScriptResource = async ({ + name, + contents, +}: CreatecXMLScriptParams) => { + const response = await fetch( +// `https://${process.env.API_HOST}/api/fabric/resources/cxml_scripts`, + `https://${process.env.API_HOST}/api/fabric/resources/cxml_applications`, + { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Authorization: `Basic ${BASIC_TOKEN}`, + }, + body: JSON.stringify({ + name: name ?? `e2e-cxml-script_${uuid()}`, + handle_calls_using: 'script', + call_handler_script: contents.call_handler_script, + }), + } + ) + const data = (await response.json()) as ApplicationResource + console.log('----> data:', data) + console.log('>> Resource cXML Script created:', data.id) + return data +} + export interface CreateRelayAppResourceParams { name?: string topic: string From fb3c5b42a01437f8407ef645c9980dff33453a58 Mon Sep 17 00:00:00 2001 From: Giacomo Vacca Date: Mon, 17 Feb 2025 11:20:09 +0100 Subject: [PATCH 02/14] e2e tests, CF, agent and guest --- .../tests/callfabric/agent_customer.spec.ts | 72 +++++++++++-------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/internal/e2e-js/tests/callfabric/agent_customer.spec.ts b/internal/e2e-js/tests/callfabric/agent_customer.spec.ts index 28516da16..0ae1d8e24 100644 --- a/internal/e2e-js/tests/callfabric/agent_customer.spec.ts +++ b/internal/e2e-js/tests/callfabric/agent_customer.spec.ts @@ -8,20 +8,27 @@ import { dialAddress, expectCFFinalEvents, expectCFInitialEvents, - expectPageReceiveAudio, + expectTotalAudioEnergyToBeGreaterThan, getResourceAddresses, } from '../../utils' -test.describe('CallFabric Agent/Customer interaction, cXML scripts', () => { + // TODO: external URL approach + + +test.describe('CallFabric Agent/Customer interaction, static cXML scripts', () => { + + const conference_name = `e2e-cxml-script-conference_${uuid()}` + + // TODO: Dedicated callbacks const cXMLScriptAgentContent = { - call_handler_script: '4567486' + call_handler_script: `${conference_name}` } const cXMLScriptCustomerContent = { - call_handler_script: '4567486' + call_handler_script: `${conference_name}` } - test('agent and customer should dial an address linked to a cXML script and expect to join a Conference', async ({ + test('agent and customer should dial an address linked to a static cXML script and expect to join a Conference', async ({ createCustomPage, resource, }) => { @@ -46,19 +53,17 @@ test.describe('CallFabric Agent/Customer interaction, cXML scripts', () => { dialOptions: { logLevel: 'debug', debug: { logWsTraffic: true }} }) + const expectInitialEventsForAgent = expectCFInitialEvents(agent_page, []) await agent_page.evaluate(async () => { // @ts-expect-error const call = window._roomObj -// await call.start() - call.start() + await call.start() }) console.log("Address dialled by Agent...") - // const expectInitialEventsForAgent = expectCFInitialEvents(agent_page, []) - // console.log("After CF Initial events for agent...") - - + expectInitialEventsForAgent + console.log("After CF Initial events for agent...") console.log('--------- creating customer ------------------') // Customer @@ -72,8 +77,6 @@ test.describe('CallFabric Agent/Customer interaction, cXML scripts', () => { }) expect(customer_resource_data.id).toBeDefined() - - // Time to retrieve the cXML script address(es) const resource_addresses = await getResourceAddresses(customer_resource_data.id) const allowed_addresses: string[] = resource_addresses.data.map((address: { id: any }) => address.id ?? '') @@ -81,7 +84,6 @@ test.describe('CallFabric Agent/Customer interaction, cXML scripts', () => { await createGuestCFClient(customer_page, { allowed_addresses: allowed_addresses}) - // Dial the resource address await dialAddress(customer_page, { address: `/private/${customerResourceName}`, // or /public/? shouldWaitForJoin: false, @@ -89,36 +91,48 @@ test.describe('CallFabric Agent/Customer interaction, cXML scripts', () => { dialOptions: { logLevel: 'debug', debug: { logWsTraffic: true }} }) + // Let the Agent wait a little before the Customer joins + await new Promise((r) => setTimeout(r, 2000)) + + const expectInitialEventsForCustomer = expectCFInitialEvents(customer_page, []) await customer_page.evaluate(async () => { // @ts-expect-error const call = window._roomObj await call.start() }) + await expectInitialEventsForCustomer - console.log("Address dialled by Customer...") - // const expectInitialEventsForCustomer = expectCFInitialEvents(customer_page, []) - // console.log("After CF Initial events for customer...") - + console.log("________ CALL IS IN PROGRESS ________________") + // 5 seconds' call + await new Promise((r) => setTimeout(r, 5000)) + console.log("Expect to have received audio...") + await expectTotalAudioEnergyToBeGreaterThan(agent_page, 0.15) + await expectTotalAudioEnergyToBeGreaterThan(customer_page, 0.15) - // await expectInitialEventsForAgent -// await expectInitialEventsForCustomer - + console.log("Test done - hanging up customer") + await customer_page.evaluate(async () => { + // @ts-expect-error + const call = window._roomObj + await call.hangup() + }) + console.log("Test done - hanging up agent") - console.log("Expect to receive audio...") - await expectPageReceiveAudio(agent_page) - await expectPageReceiveAudio(customer_page) + await agent_page.evaluate(async () => { + // @ts-expect-error + const call = window._roomObj - console.log("Expect final events...") - await expectCFFinalEvents(agent_page) - await expectCFFinalEvents(customer_page) + await call.hangup() + }) - console.log("Should do something or hang up...") - // hangup??? + // console.log("Expect final events for customer...") + // await expectCFFinalEvents(customer_page) + // console.log("Expect final events for agent...") + // await expectCFFinalEvents(agent_page) }) }) From 47b304b8f9ec48068cca7602ebd36502286ee177 Mon Sep 17 00:00:00 2001 From: Giacomo Vacca Date: Mon, 17 Feb 2025 12:10:16 +0100 Subject: [PATCH 03/14] e2e tests, CF, agent and guest --- .../e2e-js/tests/callfabric/agent_customer.spec.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/internal/e2e-js/tests/callfabric/agent_customer.spec.ts b/internal/e2e-js/tests/callfabric/agent_customer.spec.ts index 0ae1d8e24..42fe62e70 100644 --- a/internal/e2e-js/tests/callfabric/agent_customer.spec.ts +++ b/internal/e2e-js/tests/callfabric/agent_customer.spec.ts @@ -112,6 +112,10 @@ test.describe('CallFabric Agent/Customer interaction, static cXML scripts', () = await expectTotalAudioEnergyToBeGreaterThan(agent_page, 0.15) await expectTotalAudioEnergyToBeGreaterThan(customer_page, 0.15) + // Attach final listeners + const customerFinalEvents = expectCFFinalEvents(customer_page) + const agentFinalEvents = expectCFFinalEvents(customer_page) + console.log("Test done - hanging up customer") await customer_page.evaluate(async () => { @@ -130,9 +134,7 @@ test.describe('CallFabric Agent/Customer interaction, static cXML scripts', () = await call.hangup() }) - // console.log("Expect final events for customer...") - // await expectCFFinalEvents(customer_page) - // console.log("Expect final events for agent...") - // await expectCFFinalEvents(agent_page) + await customerFinalEvents + await agentFinalEvents }) }) From 43297c8a41ae4952720cff5722fc5854fa3c1c1f Mon Sep 17 00:00:00 2001 From: Giacomo Vacca Date: Tue, 18 Feb 2025 10:56:13 +0100 Subject: [PATCH 04/14] e2e tests, CF, agent and guest, external URL for cXML --- internal/e2e-js/fixtures.ts | 9 +- .../tests/callfabric/agent_customer.spec.ts | 131 +++++++++++++++++- internal/e2e-js/utils.ts | 32 +++++ 3 files changed, 165 insertions(+), 7 deletions(-) diff --git a/internal/e2e-js/fixtures.ts b/internal/e2e-js/fixtures.ts index a08b8610d..ca375dd49 100644 --- a/internal/e2e-js/fixtures.ts +++ b/internal/e2e-js/fixtures.ts @@ -5,7 +5,7 @@ import { CreateRelayAppResourceParams, CreateSWMLAppResourceParams, ApplicationResource, - Resource, + createcXMLExternalURLResource, createcXMLScriptResource, createRelayAppResource, createSWMLAppResource, @@ -14,6 +14,7 @@ import { disconnectClient, enablePageLogs, leaveRoom, + CreatecXMLExternalURLParams, } from './utils' type CustomPage = Page & { @@ -26,6 +27,7 @@ type CustomFixture = { }): Promise> createCustomVanillaPage(options: { name: string }): Promise resource: { + createcXMLExternalURLResource: typeof createcXMLExternalURLResource createcXMLScriptResource: typeof createcXMLScriptResource createVideoRoomResource: typeof createVideoRoomResource createSWMLAppResource: typeof createSWMLAppResource @@ -100,6 +102,11 @@ const test = baseTest.extend({ resources.push(data) return data }, + createcXMLExternalURLResource: async (params: CreatecXMLExternalURLParams) => { + const data = await createcXMLExternalURLResource(params) + resources.push(data) + return data + }, createcXMLScriptResource: async (params: CreatecXMLScriptParams) => { const data = await createcXMLScriptResource(params) resources.push(data) diff --git a/internal/e2e-js/tests/callfabric/agent_customer.spec.ts b/internal/e2e-js/tests/callfabric/agent_customer.spec.ts index 42fe62e70..ef3d59459 100644 --- a/internal/e2e-js/tests/callfabric/agent_customer.spec.ts +++ b/internal/e2e-js/tests/callfabric/agent_customer.spec.ts @@ -12,15 +12,11 @@ import { getResourceAddresses, } from '../../utils' - - // TODO: external URL approach - - -test.describe('CallFabric Agent/Customer interaction, static cXML scripts', () => { +const agent_customer_static_scripts_desc = 'CallFabric Agent/Customer interaction, static cXML scripts' +test.describe(agent_customer_static_scripts_desc, () => { const conference_name = `e2e-cxml-script-conference_${uuid()}` - // TODO: Dedicated callbacks const cXMLScriptAgentContent = { call_handler_script: `${conference_name}` } @@ -136,5 +132,128 @@ test.describe('CallFabric Agent/Customer interaction, static cXML scripts', () = await customerFinalEvents await agentFinalEvents + console.log("Test done -", agent_customer_static_scripts_desc) + }) +}) + +const agent_customer_external_url_desc = 'CallFabric Agent/Customer interaction, cXML with external URL' +test.describe(agent_customer_external_url_desc, () => { + // TODO: point to server that generates the response on the fly + const cXMLExternalURLAgent = { + call_handler_url: "https://dev.swire.io/laml-bins/07be593f-8e98-49e5-abce-075ad795f302" + } + const cXMLExternalURLCustomer = { + call_handler_url: "https://dev.swire.io/laml-bins/07be593f-8e98-49e5-abce-075ad795f302" + } + + test('agent and customer should dial an address linked to a cXML script with external URL and expect to join a Conference', async ({ + createCustomPage, + resource, + }) => { + // Agent + const agent_page = await createCustomPage({ name: '[agent_page]' }) + await agent_page.goto(SERVER_URL) + + const agentResourceName = `e2e-cxml-external-url-agent_${uuid()}` + const agent_resource_data = await resource.createcXMLExternalURLResource({ + name: agentResourceName, + contents: cXMLExternalURLAgent, + }) + + expect(agent_resource_data.cxml_application?.id).toBeDefined() + + await createCFClient(agent_page) + + await dialAddress(agent_page, { + address: `/private/${agentResourceName}`, // or /public/? + shouldWaitForJoin: false, + shouldStartCall: false, + dialOptions: { logLevel: 'debug', debug: { logWsTraffic: true }} + }) + + const expectInitialEventsForAgent = expectCFInitialEvents(agent_page, []) + await agent_page.evaluate(async () => { + // @ts-expect-error + const call = window._roomObj + + await call.start() + }) + + console.log("Address dialled by Agent...") + expectInitialEventsForAgent + console.log("After CF Initial events for agent...") + + console.log('--------- creating customer ------------------') + // Customer + const customer_page = await createCustomPage({ name: '[customer_page]' }) + await customer_page.goto(SERVER_URL) + + const customerResourceName = `e2e-cxml-external-url-customer_${uuid()}` + const customer_resource_data = await resource.createcXMLExternalURLResource({ + name: customerResourceName, + contents: cXMLExternalURLCustomer, + }) + + expect(customer_resource_data.id).toBeDefined() + const resource_addresses = await getResourceAddresses(customer_resource_data.id) + const allowed_addresses: string[] = resource_addresses.data.map((address: { id: any }) => address.id ?? '') + + console.log("Allowed addresses: ", allowed_addresses, " <---------------") + + await createGuestCFClient(customer_page, { allowed_addresses: allowed_addresses}) + + await dialAddress(customer_page, { + address: `/private/${customerResourceName}`, // or /public/? + shouldWaitForJoin: false, + shouldStartCall: false, + dialOptions: { logLevel: 'debug', debug: { logWsTraffic: true }} + }) + + // Let the Agent wait a little before the Customer joins + await new Promise((r) => setTimeout(r, 2000)) + + const expectInitialEventsForCustomer = expectCFInitialEvents(customer_page, []) + await customer_page.evaluate(async () => { + // @ts-expect-error + const call = window._roomObj + + await call.start() + }) + await expectInitialEventsForCustomer + + console.log("________ CALL IS IN PROGRESS ________________") + + // 5 seconds' call + await new Promise((r) => setTimeout(r, 5000)) + + console.log("Expect to have received audio...") + await expectTotalAudioEnergyToBeGreaterThan(agent_page, 0.15) + await expectTotalAudioEnergyToBeGreaterThan(customer_page, 0.15) + + // Attach final listeners + const customerFinalEvents = expectCFFinalEvents(customer_page) + const agentFinalEvents = expectCFFinalEvents(customer_page) + + console.log("Test done - hanging up customer") + + await customer_page.evaluate(async () => { + // @ts-expect-error + const call = window._roomObj + + await call.hangup() + }) + + console.log("Test done - hanging up agent") + + await agent_page.evaluate(async () => { + // @ts-expect-error + const call = window._roomObj + + await call.hangup() + }) + + await customerFinalEvents + await agentFinalEvents + console.log("Test done -", agent_customer_external_url_desc) }) }) diff --git a/internal/e2e-js/utils.ts b/internal/e2e-js/utils.ts index 501504d47..4332a4ca8 100644 --- a/internal/e2e-js/utils.ts +++ b/internal/e2e-js/utils.ts @@ -1524,6 +1524,38 @@ export const createcXMLScriptResource = async ({ return data } +export interface CreatecXMLExternalURLParams { + name?: string + contents: Record +} +export const createcXMLExternalURLResource = async ({ + name, + contents, +}: CreatecXMLExternalURLParams) => { + const response = await fetch( +// `https://${process.env.API_HOST}/api/fabric/resources/cxml_scripts`, + `https://${process.env.API_HOST}/api/fabric/resources/cxml_applications`, + { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Authorization: `Basic ${BASIC_TOKEN}`, + }, + body: JSON.stringify({ + name: name ?? `e2e-cxml-external-url_${uuid()}`, + handle_calls_using: 'external_url', + call_handler_url: contents.call_handler_url, + }), + } + ) + const data = (await response.json()) as ApplicationResource + console.log('----> data:', data) + console.log('>> Resource cXML External URL created:', data.id) + return data +} + + + export interface CreateRelayAppResourceParams { name?: string topic: string From 47652d7502f29f5f428336e4428e7a5bfb5e4ca7 Mon Sep 17 00:00:00 2001 From: Giacomo Vacca Date: Tue, 18 Feb 2025 11:16:50 +0100 Subject: [PATCH 05/14] e2e tests, CF, agent and guest, external URL for cXML --- internal/e2e-js/tests/callfabric/agent_customer.spec.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/internal/e2e-js/tests/callfabric/agent_customer.spec.ts b/internal/e2e-js/tests/callfabric/agent_customer.spec.ts index ef3d59459..bd674e477 100644 --- a/internal/e2e-js/tests/callfabric/agent_customer.spec.ts +++ b/internal/e2e-js/tests/callfabric/agent_customer.spec.ts @@ -138,12 +138,11 @@ test.describe(agent_customer_static_scripts_desc, () => { const agent_customer_external_url_desc = 'CallFabric Agent/Customer interaction, cXML with external URL' test.describe(agent_customer_external_url_desc, () => { - // TODO: point to server that generates the response on the fly const cXMLExternalURLAgent = { - call_handler_url: "https://dev.swire.io/laml-bins/07be593f-8e98-49e5-abce-075ad795f302" + call_handler_url: `${process.env.EXTERNAL_URL_FOR_CXML}` } const cXMLExternalURLCustomer = { - call_handler_url: "https://dev.swire.io/laml-bins/07be593f-8e98-49e5-abce-075ad795f302" + call_handler_url: `${process.env.EXTERNAL_URL_FOR_CXML}` } test('agent and customer should dial an address linked to a cXML script with external URL and expect to join a Conference', async ({ From e4f9e506e7e0f56a343df30369eace144139eb85 Mon Sep 17 00:00:00 2001 From: Giacomo Vacca Date: Tue, 18 Feb 2025 12:29:07 +0100 Subject: [PATCH 06/14] e2e tests, CF, guest in conference with stream --- .../tests/callfabric/agent_customer.spec.ts | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/internal/e2e-js/tests/callfabric/agent_customer.spec.ts b/internal/e2e-js/tests/callfabric/agent_customer.spec.ts index bd674e477..d1c9cead0 100644 --- a/internal/e2e-js/tests/callfabric/agent_customer.spec.ts +++ b/internal/e2e-js/tests/callfabric/agent_customer.spec.ts @@ -256,3 +256,77 @@ test.describe(agent_customer_external_url_desc, () => { console.log("Test done -", agent_customer_external_url_desc) }) }) + +const customer_stream_desc = 'CallFabric Customer connecting to stream' +test.describe(customer_stream_desc, () => { + test('customer should dial an address linked to a cXML script connecting to a conference with stream', async ({ + createCustomPage, + resource, + }) => { + + const conference_name = `e2e-cxml-customer-stream_${uuid()}` + const stream_url = `${process.env.CXML_STREAM_URL}` + + const cXMLScriptCustomerContent = { + call_handler_script: `${conference_name}` + } + + console.log('--------- creating customer ------------------') + // Customer + const customer_page = await createCustomPage({ name: '[customer_page]' }) + await customer_page.goto(SERVER_URL) + + const customerResourceName = `e2e-cxml-customer-stream_${uuid()}` + const customer_resource_data = await resource.createcXMLScriptResource({ + name: customerResourceName, + contents: cXMLScriptCustomerContent, + }) + + expect(customer_resource_data.id).toBeDefined() + const resource_addresses = await getResourceAddresses(customer_resource_data.id) + const allowed_addresses: string[] = resource_addresses.data.map((address: { id: any }) => address.id ?? '') + + console.log("Allowed addresses: ", allowed_addresses, " <---------------") + + await createGuestCFClient(customer_page, { allowed_addresses: allowed_addresses}) + + await dialAddress(customer_page, { + address: `/private/${customerResourceName}`, // or /public/? + shouldWaitForJoin: false, + shouldStartCall: false, + dialOptions: { logLevel: 'debug', debug: { logWsTraffic: true }} + }) + + const expectInitialEventsForCustomer = expectCFInitialEvents(customer_page, []) + await customer_page.evaluate(async () => { + // @ts-expect-error + const call = window._roomObj + + await call.start() + }) + await expectInitialEventsForCustomer + + console.log("________ CALL IS IN PROGRESS ________________") + + // 10 seconds' call + await new Promise((r) => setTimeout(r, 10000)) + + console.log("Expect to have received some audio...") + await expectTotalAudioEnergyToBeGreaterThan(customer_page, 0.01) + + // Attach final listeners + const customerFinalEvents = expectCFFinalEvents(customer_page) + + console.log("Test done - hanging up customer") + + await customer_page.evaluate(async () => { + // @ts-expect-error + const call = window._roomObj + + await call.hangup() + }) + + await customerFinalEvents + console.log("Test done -", customer_stream_desc) + }) +}) From 3e4f5062d18e6a9302a562738583258c52bc010f Mon Sep 17 00:00:00 2001 From: Giacomo Vacca Date: Tue, 18 Feb 2025 12:29:30 +0100 Subject: [PATCH 07/14] e2e tests, CF, guest in conference with stream --- internal/e2e-js/playwright.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/e2e-js/playwright.config.ts b/internal/e2e-js/playwright.config.ts index 78e785532..4d0c377d5 100644 --- a/internal/e2e-js/playwright.config.ts +++ b/internal/e2e-js/playwright.config.ts @@ -62,7 +62,7 @@ const useDesktopChrome = { ...devices['Desktop Chrome'], launchOptions: { // devtools: true, - headless: false, + // headless: false, args: [ '--use-fake-ui-for-media-stream', '--use-fake-device-for-media-stream', From eec47231a00b66d7eecde42d08f8160197716b48 Mon Sep 17 00:00:00 2001 From: Giacomo Vacca Date: Tue, 25 Feb 2025 10:14:01 +0100 Subject: [PATCH 08/14] Disable conference+stream test, review external URL --- .../tests/callfabric/agent_customer.spec.ts | 117 +++++++++--------- 1 file changed, 60 insertions(+), 57 deletions(-) diff --git a/internal/e2e-js/tests/callfabric/agent_customer.spec.ts b/internal/e2e-js/tests/callfabric/agent_customer.spec.ts index d1c9cead0..2b345ee5e 100644 --- a/internal/e2e-js/tests/callfabric/agent_customer.spec.ts +++ b/internal/e2e-js/tests/callfabric/agent_customer.spec.ts @@ -145,6 +145,8 @@ test.describe(agent_customer_external_url_desc, () => { call_handler_url: `${process.env.EXTERNAL_URL_FOR_CXML}` } + const test_uuid = `${uuid()}` + test('agent and customer should dial an address linked to a cXML script with external URL and expect to join a Conference', async ({ createCustomPage, resource, @@ -153,7 +155,7 @@ test.describe(agent_customer_external_url_desc, () => { const agent_page = await createCustomPage({ name: '[agent_page]' }) await agent_page.goto(SERVER_URL) - const agentResourceName = `e2e-cxml-external-url-agent_${uuid()}` + const agentResourceName = `${test_uuid}_e2e-cxml-external-url-agent_${uuid()}` const agent_resource_data = await resource.createcXMLExternalURLResource({ name: agentResourceName, contents: cXMLExternalURLAgent, @@ -187,7 +189,7 @@ test.describe(agent_customer_external_url_desc, () => { const customer_page = await createCustomPage({ name: '[customer_page]' }) await customer_page.goto(SERVER_URL) - const customerResourceName = `e2e-cxml-external-url-customer_${uuid()}` + const customerResourceName = `${test_uuid}_e2e-cxml-external-url-customer_${uuid()}` const customer_resource_data = await resource.createcXMLExternalURLResource({ name: customerResourceName, contents: cXMLExternalURLCustomer, @@ -257,76 +259,77 @@ test.describe(agent_customer_external_url_desc, () => { }) }) -const customer_stream_desc = 'CallFabric Customer connecting to stream' -test.describe(customer_stream_desc, () => { - test('customer should dial an address linked to a cXML script connecting to a conference with stream', async ({ - createCustomPage, - resource, - }) => { +// TODO: Enable when ready +// const customer_stream_desc = 'CallFabric Customer connecting to stream' +// test.describe(customer_stream_desc, () => { +// test('customer should dial an address linked to a cXML script connecting to a conference with stream', async ({ +// createCustomPage, +// resource, +// }) => { - const conference_name = `e2e-cxml-customer-stream_${uuid()}` - const stream_url = `${process.env.CXML_STREAM_URL}` +// const conference_name = `e2e-cxml-customer-stream_${uuid()}` +// const stream_url = `${process.env.CXML_STREAM_URL}` - const cXMLScriptCustomerContent = { - call_handler_script: `${conference_name}` - } +// const cXMLScriptCustomerContent = { +// call_handler_script: `${conference_name}` +// } - console.log('--------- creating customer ------------------') - // Customer - const customer_page = await createCustomPage({ name: '[customer_page]' }) - await customer_page.goto(SERVER_URL) +// console.log('--------- creating customer ------------------') +// // Customer +// const customer_page = await createCustomPage({ name: '[customer_page]' }) +// await customer_page.goto(SERVER_URL) - const customerResourceName = `e2e-cxml-customer-stream_${uuid()}` - const customer_resource_data = await resource.createcXMLScriptResource({ - name: customerResourceName, - contents: cXMLScriptCustomerContent, - }) +// const customerResourceName = `e2e-cxml-customer-stream_${uuid()}` +// const customer_resource_data = await resource.createcXMLScriptResource({ +// name: customerResourceName, +// contents: cXMLScriptCustomerContent, +// }) - expect(customer_resource_data.id).toBeDefined() - const resource_addresses = await getResourceAddresses(customer_resource_data.id) - const allowed_addresses: string[] = resource_addresses.data.map((address: { id: any }) => address.id ?? '') +// expect(customer_resource_data.id).toBeDefined() +// const resource_addresses = await getResourceAddresses(customer_resource_data.id) +// const allowed_addresses: string[] = resource_addresses.data.map((address: { id: any }) => address.id ?? '') - console.log("Allowed addresses: ", allowed_addresses, " <---------------") +// console.log("Allowed addresses: ", allowed_addresses, " <---------------") - await createGuestCFClient(customer_page, { allowed_addresses: allowed_addresses}) +// await createGuestCFClient(customer_page, { allowed_addresses: allowed_addresses}) - await dialAddress(customer_page, { - address: `/private/${customerResourceName}`, // or /public/? - shouldWaitForJoin: false, - shouldStartCall: false, - dialOptions: { logLevel: 'debug', debug: { logWsTraffic: true }} - }) +// await dialAddress(customer_page, { +// address: `/private/${customerResourceName}`, // or /public/? +// shouldWaitForJoin: false, +// shouldStartCall: false, +// dialOptions: { logLevel: 'debug', debug: { logWsTraffic: true }} +// }) - const expectInitialEventsForCustomer = expectCFInitialEvents(customer_page, []) - await customer_page.evaluate(async () => { - // @ts-expect-error - const call = window._roomObj +// const expectInitialEventsForCustomer = expectCFInitialEvents(customer_page, []) +// await customer_page.evaluate(async () => { +// // @ts-expect-error +// const call = window._roomObj - await call.start() - }) - await expectInitialEventsForCustomer +// await call.start() +// }) +// await expectInitialEventsForCustomer - console.log("________ CALL IS IN PROGRESS ________________") +// console.log("________ CALL IS IN PROGRESS ________________") - // 10 seconds' call - await new Promise((r) => setTimeout(r, 10000)) +// // 10 seconds' call +// await new Promise((r) => setTimeout(r, 10000)) - console.log("Expect to have received some audio...") - await expectTotalAudioEnergyToBeGreaterThan(customer_page, 0.01) +// console.log("Expect to have received some audio...") +// await expectTotalAudioEnergyToBeGreaterThan(customer_page, 0.01) - // Attach final listeners - const customerFinalEvents = expectCFFinalEvents(customer_page) +// // Attach final listeners +// const customerFinalEvents = expectCFFinalEvents(customer_page) - console.log("Test done - hanging up customer") +// console.log("Test done - hanging up customer") - await customer_page.evaluate(async () => { - // @ts-expect-error - const call = window._roomObj +// await customer_page.evaluate(async () => { +// // @ts-expect-error +// const call = window._roomObj - await call.hangup() - }) +// await call.hangup() +// }) - await customerFinalEvents - console.log("Test done -", customer_stream_desc) - }) -}) +// await customerFinalEvents +// console.log("Test done -", customer_stream_desc) +// }) +// }) From ae6c92e02194ebc696591c5c8e2f157ad72529f0 Mon Sep 17 00:00:00 2001 From: Giacomo Vacca Date: Wed, 26 Feb 2025 15:49:24 +0100 Subject: [PATCH 09/14] Address reviews --- internal/e2e-js/fixtures.ts | 6 +-- .../tests/callfabric/agent_customer.spec.ts | 40 +++++++------------ internal/e2e-js/utils.ts | 15 ++----- 3 files changed, 20 insertions(+), 41 deletions(-) diff --git a/internal/e2e-js/fixtures.ts b/internal/e2e-js/fixtures.ts index ca375dd49..a6e5a2d9d 100644 --- a/internal/e2e-js/fixtures.ts +++ b/internal/e2e-js/fixtures.ts @@ -4,7 +4,7 @@ import { CreatecXMLScriptParams, CreateRelayAppResourceParams, CreateSWMLAppResourceParams, - ApplicationResource, + Resource, createcXMLExternalURLResource, createcXMLScriptResource, createRelayAppResource, @@ -32,7 +32,7 @@ type CustomFixture = { createVideoRoomResource: typeof createVideoRoomResource createSWMLAppResource: typeof createSWMLAppResource createRelayAppResource: typeof createRelayAppResource - resources: ApplicationResource[] + resources: Resource[] } } @@ -94,7 +94,7 @@ const test = baseTest.extend({ console.log('Cleaning up pages..') }, resource: async ({}, use) => { - const resources: ApplicationResource[] = [] + const resources: Resource[] = [] const resource = { createVideoRoomResource: async (params?: string) => { diff --git a/internal/e2e-js/tests/callfabric/agent_customer.spec.ts b/internal/e2e-js/tests/callfabric/agent_customer.spec.ts index 2b345ee5e..cfb98b19a 100644 --- a/internal/e2e-js/tests/callfabric/agent_customer.spec.ts +++ b/internal/e2e-js/tests/callfabric/agent_customer.spec.ts @@ -45,8 +45,7 @@ test.describe(agent_customer_static_scripts_desc, () => { await dialAddress(agent_page, { address: `/private/${agentResourceName}`, // or /public/? shouldWaitForJoin: false, - shouldStartCall: false, - dialOptions: { logLevel: 'debug', debug: { logWsTraffic: true }} + shouldStartCall: false }) const expectInitialEventsForAgent = expectCFInitialEvents(agent_page, []) @@ -83,12 +82,11 @@ test.describe(agent_customer_static_scripts_desc, () => { await dialAddress(customer_page, { address: `/private/${customerResourceName}`, // or /public/? shouldWaitForJoin: false, - shouldStartCall: false, - dialOptions: { logLevel: 'debug', debug: { logWsTraffic: true }} + shouldStartCall: false }) // Let the Agent wait a little before the Customer joins - await new Promise((r) => setTimeout(r, 2000)) + await customer_page.waitForTimeout(2000) const expectInitialEventsForCustomer = expectCFInitialEvents(customer_page, []) await customer_page.evaluate(async () => { @@ -99,10 +97,8 @@ test.describe(agent_customer_static_scripts_desc, () => { }) await expectInitialEventsForCustomer - console.log("________ CALL IS IN PROGRESS ________________") - // 5 seconds' call - await new Promise((r) => setTimeout(r, 5000)) + await customer_page.waitForTimeout(5000) console.log("Expect to have received audio...") await expectTotalAudioEnergyToBeGreaterThan(agent_page, 0.15) @@ -110,7 +106,7 @@ test.describe(agent_customer_static_scripts_desc, () => { // Attach final listeners const customerFinalEvents = expectCFFinalEvents(customer_page) - const agentFinalEvents = expectCFFinalEvents(customer_page) + const agentFinalEvents = expectCFFinalEvents(agent_page) console.log("Test done - hanging up customer") @@ -130,8 +126,8 @@ test.describe(agent_customer_static_scripts_desc, () => { await call.hangup() }) - await customerFinalEvents - await agentFinalEvents + await Promise.all([customerFinalEvents, agentFinalEvents]) + console.log("Test done -", agent_customer_static_scripts_desc) }) }) @@ -168,8 +164,7 @@ test.describe(agent_customer_external_url_desc, () => { await dialAddress(agent_page, { address: `/private/${agentResourceName}`, // or /public/? shouldWaitForJoin: false, - shouldStartCall: false, - dialOptions: { logLevel: 'debug', debug: { logWsTraffic: true }} + shouldStartCall: false }) const expectInitialEventsForAgent = expectCFInitialEvents(agent_page, []) @@ -206,8 +201,7 @@ test.describe(agent_customer_external_url_desc, () => { await dialAddress(customer_page, { address: `/private/${customerResourceName}`, // or /public/? shouldWaitForJoin: false, - shouldStartCall: false, - dialOptions: { logLevel: 'debug', debug: { logWsTraffic: true }} + shouldStartCall: false }) // Let the Agent wait a little before the Customer joins @@ -222,10 +216,8 @@ test.describe(agent_customer_external_url_desc, () => { }) await expectInitialEventsForCustomer - console.log("________ CALL IS IN PROGRESS ________________") - // 5 seconds' call - await new Promise((r) => setTimeout(r, 5000)) + await customer_page.waitForTimeout(5000) console.log("Expect to have received audio...") await expectTotalAudioEnergyToBeGreaterThan(agent_page, 0.15) @@ -233,7 +225,7 @@ test.describe(agent_customer_external_url_desc, () => { // Attach final listeners const customerFinalEvents = expectCFFinalEvents(customer_page) - const agentFinalEvents = expectCFFinalEvents(customer_page) + const agentFinalEvents = expectCFFinalEvents(agent_page) console.log("Test done - hanging up customer") @@ -253,8 +245,7 @@ test.describe(agent_customer_external_url_desc, () => { await call.hangup() }) - await customerFinalEvents - await agentFinalEvents + await Promise.all([customerFinalEvents, agentFinalEvents]) console.log("Test done -", agent_customer_external_url_desc) }) }) @@ -296,8 +287,7 @@ test.describe(agent_customer_external_url_desc, () => { // await dialAddress(customer_page, { // address: `/private/${customerResourceName}`, // or /public/? // shouldWaitForJoin: false, -// shouldStartCall: false, -// dialOptions: { logLevel: 'debug', debug: { logWsTraffic: true }} +// shouldStartCall: false // }) // const expectInitialEventsForCustomer = expectCFInitialEvents(customer_page, []) @@ -309,10 +299,8 @@ test.describe(agent_customer_external_url_desc, () => { // }) // await expectInitialEventsForCustomer -// console.log("________ CALL IS IN PROGRESS ________________") - // // 10 seconds' call -// await new Promise((r) => setTimeout(r, 10000)) +// await customer_page.waitForTimeout(10000) // console.log("Expect to have received some audio...") // await expectTotalAudioEnergyToBeGreaterThan(customer_page, 0.01) diff --git a/internal/e2e-js/utils.ts b/internal/e2e-js/utils.ts index 4332a4ca8..8534cf14d 100644 --- a/internal/e2e-js/utils.ts +++ b/internal/e2e-js/utils.ts @@ -169,7 +169,6 @@ export const createGuestSATToken = async (bodyData: GuestSATTokenRequest) => { } ) const data = await response.json() - console.log("---- guest token, data: ", data, " <--------------------") return data.token } @@ -185,7 +184,6 @@ export const getResourceAddresses = async (resource_id: string) => { } ) const data = await response.json() - console.log("---- get resource addresses for resource ID [", resource_id, "], response: ", data, " <--------------------") return data } @@ -1436,6 +1434,7 @@ export interface Resource { type: string display_name: string created_at: string + cxml_application?: CXMLApplication } export interface CXMLApplication { @@ -1443,10 +1442,6 @@ export interface CXMLApplication { // and other things } -export interface ApplicationResource extends Resource { - cxml_application?: CXMLApplication -} - export const createVideoRoomResource = async (name?: string) => { const response = await fetch( `https://${process.env.API_HOST}/api/fabric/resources/conference_rooms`, @@ -1503,7 +1498,6 @@ export const createcXMLScriptResource = async ({ contents, }: CreatecXMLScriptParams) => { const response = await fetch( -// `https://${process.env.API_HOST}/api/fabric/resources/cxml_scripts`, `https://${process.env.API_HOST}/api/fabric/resources/cxml_applications`, { method: 'POST', @@ -1518,7 +1512,7 @@ export const createcXMLScriptResource = async ({ }), } ) - const data = (await response.json()) as ApplicationResource + const data = (await response.json()) as Resource console.log('----> data:', data) console.log('>> Resource cXML Script created:', data.id) return data @@ -1533,7 +1527,6 @@ export const createcXMLExternalURLResource = async ({ contents, }: CreatecXMLExternalURLParams) => { const response = await fetch( -// `https://${process.env.API_HOST}/api/fabric/resources/cxml_scripts`, `https://${process.env.API_HOST}/api/fabric/resources/cxml_applications`, { method: 'POST', @@ -1548,14 +1541,12 @@ export const createcXMLExternalURLResource = async ({ }), } ) - const data = (await response.json()) as ApplicationResource + const data = (await response.json()) as Resource console.log('----> data:', data) console.log('>> Resource cXML External URL created:', data.id) return data } - - export interface CreateRelayAppResourceParams { name?: string topic: string From 954037888c8f4872e7749ece614e8a65c4ba9e24 Mon Sep 17 00:00:00 2001 From: Giacomo Vacca Date: Wed, 26 Feb 2025 19:33:27 +0100 Subject: [PATCH 10/14] Address review, refactor --- internal/e2e-js/utils.ts | 72 ++++++++-------------------------------- 1 file changed, 13 insertions(+), 59 deletions(-) diff --git a/internal/e2e-js/utils.ts b/internal/e2e-js/utils.ts index 8534cf14d..168cca012 100644 --- a/internal/e2e-js/utils.ts +++ b/internal/e2e-js/utils.ts @@ -505,72 +505,26 @@ export const createCFClient = async ( page: Page, params?: CreateCFClientParams ) => { - const sat = await createTestSATToken() - if (!sat) { - console.error('Invalid SAT. Exiting..') - process.exit(4) - } - - const { attachSagaMonitor = false } = params || {} - - const swClient = await page.evaluate( - async (options) => { - const _runningWorkers: any[] = [] - // @ts-expect-error - window._runningWorkers = _runningWorkers - const addTask = (task: any) => { - if (!_runningWorkers.includes(task)) { - _runningWorkers.push(task) - } - } - const removeTask = (task: any) => { - const index = _runningWorkers.indexOf(task) - if (index > -1) { - _runningWorkers.splice(index, 1) - } - } - - const sagaMonitor = { - effectResolved: (_effectId: number, result: any) => { - if (result?.toPromise) { - addTask(result) - // Remove the task when it completes or is cancelled - result.toPromise().finally(() => { - removeTask(result) - }) - } - }, - } - - const SignalWire = window._SWJS.SignalWire - const client: SignalWireContract = await SignalWire({ - host: options.RELAY_HOST, - token: options.API_TOKEN, - debug: { logWsTraffic: true }, - ...(options.attachSagaMonitor && { sagaMonitor }), - }) - - window._client = client - return client - }, - { - RELAY_HOST: process.env.RELAY_HOST, - API_TOKEN: sat, - attachSagaMonitor, - } - ) - - return swClient + const sat = await createTestSATToken(); + return createCFClientWithToken(page, sat, params); } export const createGuestCFClient = async ( page: Page, bodyData: GuestSATTokenRequest, - params?: CreateCFClientParams, + params?: CreateCFClientParams +) => { + const sat = await createGuestSATToken(bodyData); + return createCFClientWithToken(page, sat, params); +} + +const createCFClientWithToken = async ( + page: Page, + sat: string | null, + params?: CreateCFClientParams ) => { - const sat = await createGuestSATToken(bodyData) if (!sat) { - console.error('Invalid Guest SAT. Exiting...') + console.error('Invalid SAT. Exiting..') process.exit(4) } From 5cfcbbfec5e4b7abcdea5c63d8af1a8e33838359 Mon Sep 17 00:00:00 2001 From: Giacomo Vacca Date: Wed, 26 Feb 2025 19:36:14 +0100 Subject: [PATCH 11/14] Add new CF test to its folder in playwright config --- internal/e2e-js/playwright.config.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/e2e-js/playwright.config.ts b/internal/e2e-js/playwright.config.ts index 4d0c377d5..cd9fc3bb5 100644 --- a/internal/e2e-js/playwright.config.ts +++ b/internal/e2e-js/playwright.config.ts @@ -36,6 +36,7 @@ const reattachTests = [ 'roomSessionReattachWrongProtocol.spec.ts', ] const callfabricTests = [ + 'agent_customer.spec.ts', 'address.spec.ts', 'cleanup.spec.ts', 'conversation.spec.ts', From 961cbad4f3254c558b049ea8659f376cdf8f74a8 Mon Sep 17 00:00:00 2001 From: Giacomo Vacca Date: Wed, 5 Mar 2025 18:26:21 +0100 Subject: [PATCH 12/14] Set default for EXTERNAL_URL_FOR_CXML --- internal/e2e-js/tests/callfabric/agent_customer.spec.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/e2e-js/tests/callfabric/agent_customer.spec.ts b/internal/e2e-js/tests/callfabric/agent_customer.spec.ts index cfb98b19a..ef6a6bb16 100644 --- a/internal/e2e-js/tests/callfabric/agent_customer.spec.ts +++ b/internal/e2e-js/tests/callfabric/agent_customer.spec.ts @@ -134,11 +134,13 @@ test.describe(agent_customer_static_scripts_desc, () => { const agent_customer_external_url_desc = 'CallFabric Agent/Customer interaction, cXML with external URL' test.describe(agent_customer_external_url_desc, () => { + const external_url_for_cxml = process.env.EXTERNAL_URL_FOR_CXML || 'https://us-central1-video-load-testing-with-gcf.cloudfunctions.net/gcf-external-url' + const cXMLExternalURLAgent = { - call_handler_url: `${process.env.EXTERNAL_URL_FOR_CXML}` + call_handler_url: external_url_for_cxml } const cXMLExternalURLCustomer = { - call_handler_url: `${process.env.EXTERNAL_URL_FOR_CXML}` + call_handler_url: external_url_for_cxml } const test_uuid = `${uuid()}` From 5ab47fe586bbad0cc5178fdad93929e91b6ea501 Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Thu, 6 Mar 2025 16:21:52 -0800 Subject: [PATCH 13/14] move to secret --- .github/workflows/browser-js-production.yml | 1 + .github/workflows/browser-js-staging.yml | 1 + internal/e2e-js/tests/callfabric/agent_customer.spec.ts | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/browser-js-production.yml b/.github/workflows/browser-js-production.yml index 08e52a9c3..20574763b 100644 --- a/.github/workflows/browser-js-production.yml +++ b/.github/workflows/browser-js-production.yml @@ -50,6 +50,7 @@ jobs: run: npm run -w=@sw-internal/e2e-js dev -- --project ${{ matrix.project }} env: SW_TEST_CONFIG: ${{ secrets.PRODUCTION_E2E_JS_SW_TEST_CONFIG }} + EXTERNAL_URL_FOR_CXML: ${{ secrets.EXTERNAL_URL_FOR_CXML }} report-result: needs: e2e-tests diff --git a/.github/workflows/browser-js-staging.yml b/.github/workflows/browser-js-staging.yml index 2db733302..68a264cce 100644 --- a/.github/workflows/browser-js-staging.yml +++ b/.github/workflows/browser-js-staging.yml @@ -49,6 +49,7 @@ jobs: run: npm run -w=@sw-internal/e2e-js dev -- --project ${{ matrix.project }} env: SW_TEST_CONFIG: ${{ secrets.STAGING_E2E_JS_SW_TEST_CONFIG }} + EXTERNAL_URL_FOR_CXML: ${{ secrets.EXTERNAL_URL_FOR_CXML }} report-result: needs: e2e-tests diff --git a/internal/e2e-js/tests/callfabric/agent_customer.spec.ts b/internal/e2e-js/tests/callfabric/agent_customer.spec.ts index ef6a6bb16..0605036a3 100644 --- a/internal/e2e-js/tests/callfabric/agent_customer.spec.ts +++ b/internal/e2e-js/tests/callfabric/agent_customer.spec.ts @@ -134,7 +134,7 @@ test.describe(agent_customer_static_scripts_desc, () => { const agent_customer_external_url_desc = 'CallFabric Agent/Customer interaction, cXML with external URL' test.describe(agent_customer_external_url_desc, () => { - const external_url_for_cxml = process.env.EXTERNAL_URL_FOR_CXML || 'https://us-central1-video-load-testing-with-gcf.cloudfunctions.net/gcf-external-url' + const external_url_for_cxml = process.env.EXTERNAL_URL_FOR_CXML const cXMLExternalURLAgent = { call_handler_url: external_url_for_cxml From d7a70c9f34fa222712ded8c41acee7f2b01303ed Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Fri, 7 Mar 2025 08:29:23 -0800 Subject: [PATCH 14/14] move to secret (#1188)