Skip to content

Commit

Permalink
Create and Delete CF resource on the fly (#1060)
Browse files Browse the repository at this point in the history
* Create and Delete resource on the fly

* function to create swml application resource

* relay app create and delete on the fly

* integrate API in video room test

* cleanup e2e-realtime utilities

* create and delete swml resource
  • Loading branch information
iAmmar7 authored Jun 5, 2024
1 parent 3ef51dc commit fcd913c
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 187 deletions.
62 changes: 57 additions & 5 deletions internal/e2e-js/fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
import type { Video } from '@signalwire/js'
import { PageWithWsInspector, intercepWsTraffic, } from 'playwrigth-ws-inspector'
import { PageWithWsInspector, intercepWsTraffic } from 'playwrigth-ws-inspector'
import { test as baseTest, expect, type Page } from '@playwright/test'
import { enablePageLogs } from './utils'
import {
CreateRelayAppResourceParams,
CreateSWMLAppResourceParams,
Resource,
createRelayAppResource,
createSWMLAppResource,
createVideoRoomResource,
deleteResource,
enablePageLogs,
} from './utils'

type CustomPage = Page & {
swNetworkDown: () => Promise<void>
swNetworkUp: () => Promise<void>
}
type CustomFixture = {
createCustomPage(options: { name: string }): Promise<PageWithWsInspector<CustomPage>>
createCustomPage(options: {
name: string
}): Promise<PageWithWsInspector<CustomPage>>
createCustomVanillaPage(options: { name: string }): Promise<Page>
resource: {
createVideoRoomResource: typeof createVideoRoomResource
createSWMLAppResource: typeof createSWMLAppResource
createRelayAppResource: typeof createRelayAppResource
resources: Resource[]
}
}

const test = baseTest.extend<CustomFixture>({
createCustomPage: async ({ context }, use) => {
const maker = async (options: { name: string }): Promise<PageWithWsInspector<CustomPage>> => {
const maker = async (options: {
name: string
}): Promise<PageWithWsInspector<CustomPage>> => {
let page = await context.newPage()
enablePageLogs(page, options.name)
//@ts-ignore
Expand Down Expand Up @@ -68,7 +87,6 @@ const test = baseTest.extend<CustomFixture>({
expect(row.rootEl).toBe(0)
})
},

createCustomVanillaPage: async ({ context }, use) => {
const maker = async (options: { name: string }): Promise<Page> => {
const page = await context.newPage()
Expand All @@ -79,6 +97,40 @@ const test = baseTest.extend<CustomFixture>({

console.log('Cleaning up pages..')
},
resource: async ({}, use) => {
const resources: Resource[] = []

const resource = {
createVideoRoomResource: async (params?: string) => {
const data = await createVideoRoomResource(params)
resources.push(data)
return data
},
createSWMLAppResource: async (params: CreateSWMLAppResourceParams) => {
const data = await createSWMLAppResource(params)
resources.push(data)
return data
},
createRelayAppResource: async (params: CreateRelayAppResourceParams) => {
const data = await createRelayAppResource(params)
resources.push(data)
return data
},
resources,
}
await use(resource)

// Clean up resources after use
const deleteResources = resources.map(async (resource) => {
try {
await deleteResource(resource.id)
console.log('>> Resource deleted successfully:', resource.id)
} catch (error) {
console.error('>> Failed to delete resource:', resource.id, error)
}
})
await Promise.allSettled(deleteResources)
},
})

export { test, expect, Page }
11 changes: 7 additions & 4 deletions internal/e2e-js/tests/callfabric/conversation.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { uuid } from '@signalwire/core'
import { SignalWireContract } from '@signalwire/js'
import { test, expect } from '../../fixtures'
import { SERVER_URL, createVideoRoom, createCFClient } from '../../utils'
import { uuid } from '@signalwire/core'
import { SERVER_URL, createCFClient } from '../../utils'

test.describe('Conversation Room', () => {
test('send message in a room conversation', async ({ createCustomPage }) => {
test('send message in a room conversation', async ({
createCustomPage,
resource,
}) => {
const page = await createCustomPage({ name: '[page]' })
const page2 = await createCustomPage({
name: '[page2]',
Expand All @@ -16,7 +19,7 @@ test.describe('Conversation Room', () => {
await createCFClient(page2)

const roomName = `e2e-js-convo-room_${uuid()}`
await createVideoRoom(roomName)
await resource.createVideoRoomResource(roomName)

const firstMsgEvent = await page.evaluate(
({ roomName }) => {
Expand Down
46 changes: 31 additions & 15 deletions internal/e2e-js/tests/callfabric/relayApp.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { uuid } from '@signalwire/core'

Check failure on line 1 in internal/e2e-js/tests/callfabric/relayApp.spec.ts

View workflow job for this annotation

GitHub Actions / Run E2E tests (18.x, callfabric)

[callfabric] › callfabric/relayApp.spec.ts:14:7 › CallFabric Relay Application › should connect to the relay app and expect an audio playback

1) [callfabric] › callfabric/relayApp.spec.ts:14:7 › CallFabric Relay Application › should connect to the relay app and expect an audio playback Test timeout of 120000ms exceeded.

Check failure on line 1 in internal/e2e-js/tests/callfabric/relayApp.spec.ts

View workflow job for this annotation

GitHub Actions / Run E2E tests (18.x, callfabric)

[callfabric] › callfabric/relayApp.spec.ts:14:7 › CallFabric Relay Application › should connect to the relay app and expect an audio playback

1) [callfabric] › callfabric/relayApp.spec.ts:14:7 › CallFabric Relay Application › should connect to the relay app and expect an audio playback Pending operations: - page.evaluate at tests/callfabric/relayApp.spec.ts:81:34 - page.evaluate at utils.ts:1025:30 - page.evaluate at tests/callfabric/relayApp.spec.ts:93:16
import { SignalWire } from '@signalwire/realtime-api'
import {
createCFClient,
Expand All @@ -12,6 +13,7 @@ import { test, expect } from '../../fixtures'
test.describe('CallFabric Relay Application', () => {
test('should connect to the relay app and expect an audio playback', async ({
createCustomPage,
resource,
}) => {
const client = await SignalWire({
host: process.env.RELAY_HOST,
Expand All @@ -22,8 +24,14 @@ test.describe('CallFabric Relay Application', () => {
},
})

const reference = `e2e-relay-app_${uuid()}`
await resource.createRelayAppResource({
name: reference,
reference,
})

await client.voice.listen({
topics: ['cf-e2e-test-relay'],
topics: [reference],
onCallReceived: async (call) => {
try {
console.log('Call received', call.id)
Expand All @@ -50,16 +58,14 @@ test.describe('CallFabric Relay Application', () => {

await createCFClient(page)

const resourceName = 'cf-e2e-test-relay'

await page.evaluate(
async (options) => {
return new Promise<any>(async (resolve, _reject) => {
// @ts-expect-error
const client = window._client

const call = await client.dial({
to: `/public/${options.resourceName}`,
to: `/private/${options.reference}`,
rootElement: document.getElementById('rootElement'),
})

Expand All @@ -69,7 +75,7 @@ test.describe('CallFabric Relay Application', () => {
resolve(call)
})
},
{ resourceName }
{ reference }
)

const callPlayStarted = page.evaluate(async () => {

Check failure on line 81 in internal/e2e-js/tests/callfabric/relayApp.spec.ts

View workflow job for this annotation

GitHub Actions / Run E2E tests (18.x, callfabric)

[callfabric] › callfabric/relayApp.spec.ts:14:7 › CallFabric Relay Application › should connect to the relay app and expect an audio playback

1) [callfabric] › callfabric/relayApp.spec.ts:14:7 › CallFabric Relay Application › should connect to the relay app and expect an audio playback Error: page.evaluate: Target closed 79 | ) 80 | > 81 | const callPlayStarted = page.evaluate(async () => *** | ^ 82 | // @ts-expect-error 83 | const roomObj: Video.RoomSession = window._roomObj 84 | return new Promise<boolean>((resolve) => *** at /home/runner/work/signalwire-js/signalwire-js/internal/e2e-js/tests/callfabric/relayApp.spec.ts:81:34
Expand Down Expand Up @@ -126,6 +132,7 @@ test.describe('CallFabric Relay Application', () => {

test('should connect to the relay app and expect a silence', async ({
createCustomPage,
resource,
}) => {
const client = await SignalWire({
host: process.env.RELAY_HOST,
Expand All @@ -136,8 +143,14 @@ test.describe('CallFabric Relay Application', () => {
},
})

const reference = `e2e-relay-app_${uuid()}`
await resource.createRelayAppResource({
name: reference,
reference,
})

await client.voice.listen({
topics: ['cf-e2e-test-relay'],
topics: [reference],
onCallReceived: async (call) => {
try {
console.log('Call received', call.id)
Expand All @@ -160,16 +173,14 @@ test.describe('CallFabric Relay Application', () => {

await createCFClient(page)

const resourceName = 'cf-e2e-test-relay'

await page.evaluate(
async (options) => {
return new Promise<any>(async (resolve, _reject) => {
// @ts-expect-error
const client = window._client

const call = await client.dial({
to: `/public/${options.resourceName}`,
to: `/private/${options.reference}`,
rootElement: document.getElementById('rootElement'),
})

Expand All @@ -179,7 +190,7 @@ test.describe('CallFabric Relay Application', () => {
resolve(call)
})
},
{ resourceName }
{ reference }
)

const callPlayStarted = page.evaluate(async () => {
Expand Down Expand Up @@ -249,6 +260,7 @@ test.describe('CallFabric Relay Application', () => {

test('should connect to the relay app and expect a hangup', async ({
createCustomPage,
resource,
}) => {
const client = await SignalWire({
host: process.env.RELAY_HOST,
Expand All @@ -259,8 +271,14 @@ test.describe('CallFabric Relay Application', () => {
},
})

const reference = `e2e-relay-app_${uuid()}`
await resource.createRelayAppResource({
name: reference,
reference,
})

await client.voice.listen({
topics: ['cf-e2e-test-relay'],
topics: [reference],
onCallReceived: async (call) => {
try {
console.log('Call received', call.id)
Expand All @@ -279,8 +297,6 @@ test.describe('CallFabric Relay Application', () => {
const page = await createCustomPage({ name: '[page]' })
await page.goto(SERVER_URL)

const resourceName = 'cf-e2e-test-relay'

await createCFClient(page)

await page.evaluate(
Expand All @@ -290,7 +306,7 @@ test.describe('CallFabric Relay Application', () => {
const client = window._client

const call = await client.dial({
to: `/public/${options.resourceName}`,
to: `/private/${options.reference}`,
rootElement: document.getElementById('rootElement'),
})

Expand All @@ -300,7 +316,7 @@ test.describe('CallFabric Relay Application', () => {
resolve(call)
})
},
{ resourceName }
{ reference }
)

const expectInitialEvents = expectCFInitialEvents(page)
Expand Down
64 changes: 46 additions & 18 deletions internal/e2e-js/tests/callfabric/swml.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { uuid } from '@signalwire/core'

Check failure on line 1 in internal/e2e-js/tests/callfabric/swml.spec.ts

View workflow job for this annotation

GitHub Actions / Run E2E tests (18.x, callfabric)

[callfabric] › callfabric/swml.spec.ts:43:7 › CallFabric SWML › should dial an address and expect a TTS audio

2) [callfabric] › callfabric/swml.spec.ts:43:7 › CallFabric SWML › should dial an address and expect a TTS audio Test timeout of 120000ms exceeded.

Check failure on line 1 in internal/e2e-js/tests/callfabric/swml.spec.ts

View workflow job for this annotation

GitHub Actions / Run E2E tests (18.x, callfabric)

[callfabric] › callfabric/swml.spec.ts:43:7 › CallFabric SWML › should dial an address and expect a TTS audio

2) [callfabric] › callfabric/swml.spec.ts:43:7 › CallFabric SWML › should dial an address and expect a TTS audio Pending operations: - page.evaluate at tests/callfabric/swml.spec.ts:80:34 - page.evaluate at utils.ts:1025:30 - page.evaluate at tests/callfabric/swml.spec.ts:92:16
import { test } from '../../fixtures'
import {
SERVER_URL,
Expand All @@ -8,14 +9,49 @@ import {
} from '../../utils'

test.describe('CallFabric SWML', () => {
const swmlTTS = {
sections: {
main: [
'answer',
{
play: {
volume: 10,
urls: [
'say:Hi',
'say:Welcome to SignalWire',
"say:Thank you for calling us. All our lines are currently busy, but your call is important to us. Please hang up, and we'll return your call as soon as our representative is available.",
],
},
},
],
},
}
const swmlHangup = {
version: '1.0.0',
sections: {
main: [
'answer',
{
hangup: {
reason: 'busy',
},
},
],
},
}

test('should dial an address and expect a TTS audio', async ({
createCustomPage,
resource,
}) => {
const page = await createCustomPage({ name: '[page]' })
await page.goto(SERVER_URL)

const resourceName = process.env.RESOURCE_NAME ?? '/public/cf-e2e-test-tts'
console.log(`#### Dialing ${resourceName}`)
const resourceName = `e2e-swml-app_${uuid()}`
await resource.createSWMLAppResource({
name: resourceName,
contents: swmlTTS,
})

await createCFClient(page)

Expand All @@ -28,7 +64,7 @@ test.describe('CallFabric SWML', () => {
const client = window._client

const call = await client.dial({
to: resourceName,
to: `/private/${resourceName}`,
rootElement: document.getElementById('rootElement'),
})

Expand All @@ -40,18 +76,6 @@ test.describe('CallFabric SWML', () => {
},
{ resourceName }
)
page.expectWsTraffic({
assertations: [
{
type: "send",
name: "connect",
expect: {
method: "signalwire.connect",
"params.version.major": 4,
},
}
]
})

const callPlayStarted = page.evaluate(async () => {

Check failure on line 80 in internal/e2e-js/tests/callfabric/swml.spec.ts

View workflow job for this annotation

GitHub Actions / Run E2E tests (18.x, callfabric)

[callfabric] › callfabric/swml.spec.ts:43:7 › CallFabric SWML › should dial an address and expect a TTS audio

2) [callfabric] › callfabric/swml.spec.ts:43:7 › CallFabric SWML › should dial an address and expect a TTS audio Error: page.evaluate: Target closed 78 | ) 79 | > 80 | const callPlayStarted = page.evaluate(async () => *** | ^ 81 | // @ts-expect-error 82 | const roomObj: Video.RoomSession = window._roomObj 83 | return new Promise<boolean>((resolve) => *** at /home/runner/work/signalwire-js/signalwire-js/internal/e2e-js/tests/callfabric/swml.spec.ts:80:34
// @ts-expect-error
Expand Down Expand Up @@ -101,12 +125,16 @@ test.describe('CallFabric SWML', () => {

test('should dial an address and expect a hangup', async ({
createCustomPage,
resource,
}) => {
const page = await createCustomPage({ name: '[page]' })
await page.goto(SERVER_URL)

const resourceName =
process.env.RESOURCE_NAME ?? '/public/cf-e2e-test-hangup'
const resourceName = `e2e-swml-app_${uuid()}`
await resource.createSWMLAppResource({
name: resourceName,
contents: swmlHangup,
})

await createCFClient(page)

Expand All @@ -118,7 +146,7 @@ test.describe('CallFabric SWML', () => {
const client = window._client

const call = await client.dial({
to: resourceName,
to: `/private/${resourceName}`,
rootElement: document.getElementById('rootElement'),
})

Expand Down
Loading

0 comments on commit fcd913c

Please sign in to comment.