Skip to content

Commit fcd913c

Browse files
authored
Create and Delete CF resource on the fly (#1060)
* 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
1 parent 3ef51dc commit fcd913c

File tree

8 files changed

+248
-187
lines changed

8 files changed

+248
-187
lines changed

internal/e2e-js/fixtures.ts

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,39 @@
11
import type { Video } from '@signalwire/js'
2-
import { PageWithWsInspector, intercepWsTraffic, } from 'playwrigth-ws-inspector'
2+
import { PageWithWsInspector, intercepWsTraffic } from 'playwrigth-ws-inspector'
33
import { test as baseTest, expect, type Page } from '@playwright/test'
4-
import { enablePageLogs } from './utils'
4+
import {
5+
CreateRelayAppResourceParams,
6+
CreateSWMLAppResourceParams,
7+
Resource,
8+
createRelayAppResource,
9+
createSWMLAppResource,
10+
createVideoRoomResource,
11+
deleteResource,
12+
enablePageLogs,
13+
} from './utils'
514

615
type CustomPage = Page & {
716
swNetworkDown: () => Promise<void>
817
swNetworkUp: () => Promise<void>
918
}
1019
type CustomFixture = {
11-
createCustomPage(options: { name: string }): Promise<PageWithWsInspector<CustomPage>>
20+
createCustomPage(options: {
21+
name: string
22+
}): Promise<PageWithWsInspector<CustomPage>>
1223
createCustomVanillaPage(options: { name: string }): Promise<Page>
24+
resource: {
25+
createVideoRoomResource: typeof createVideoRoomResource
26+
createSWMLAppResource: typeof createSWMLAppResource
27+
createRelayAppResource: typeof createRelayAppResource
28+
resources: Resource[]
29+
}
1330
}
1431

1532
const test = baseTest.extend<CustomFixture>({
1633
createCustomPage: async ({ context }, use) => {
17-
const maker = async (options: { name: string }): Promise<PageWithWsInspector<CustomPage>> => {
34+
const maker = async (options: {
35+
name: string
36+
}): Promise<PageWithWsInspector<CustomPage>> => {
1837
let page = await context.newPage()
1938
enablePageLogs(page, options.name)
2039
//@ts-ignore
@@ -68,7 +87,6 @@ const test = baseTest.extend<CustomFixture>({
6887
expect(row.rootEl).toBe(0)
6988
})
7089
},
71-
7290
createCustomVanillaPage: async ({ context }, use) => {
7391
const maker = async (options: { name: string }): Promise<Page> => {
7492
const page = await context.newPage()
@@ -79,6 +97,40 @@ const test = baseTest.extend<CustomFixture>({
7997

8098
console.log('Cleaning up pages..')
8199
},
100+
resource: async ({}, use) => {
101+
const resources: Resource[] = []
102+
103+
const resource = {
104+
createVideoRoomResource: async (params?: string) => {
105+
const data = await createVideoRoomResource(params)
106+
resources.push(data)
107+
return data
108+
},
109+
createSWMLAppResource: async (params: CreateSWMLAppResourceParams) => {
110+
const data = await createSWMLAppResource(params)
111+
resources.push(data)
112+
return data
113+
},
114+
createRelayAppResource: async (params: CreateRelayAppResourceParams) => {
115+
const data = await createRelayAppResource(params)
116+
resources.push(data)
117+
return data
118+
},
119+
resources,
120+
}
121+
await use(resource)
122+
123+
// Clean up resources after use
124+
const deleteResources = resources.map(async (resource) => {
125+
try {
126+
await deleteResource(resource.id)
127+
console.log('>> Resource deleted successfully:', resource.id)
128+
} catch (error) {
129+
console.error('>> Failed to delete resource:', resource.id, error)
130+
}
131+
})
132+
await Promise.allSettled(deleteResources)
133+
},
82134
})
83135

84136
export { test, expect, Page }

internal/e2e-js/tests/callfabric/conversation.spec.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
import { uuid } from '@signalwire/core'
12
import { SignalWireContract } from '@signalwire/js'
23
import { test, expect } from '../../fixtures'
3-
import { SERVER_URL, createVideoRoom, createCFClient } from '../../utils'
4-
import { uuid } from '@signalwire/core'
4+
import { SERVER_URL, createCFClient } from '../../utils'
55

66
test.describe('Conversation Room', () => {
7-
test('send message in a room conversation', async ({ createCustomPage }) => {
7+
test('send message in a room conversation', async ({
8+
createCustomPage,
9+
resource,
10+
}) => {
811
const page = await createCustomPage({ name: '[page]' })
912
const page2 = await createCustomPage({
1013
name: '[page2]',
@@ -16,7 +19,7 @@ test.describe('Conversation Room', () => {
1619
await createCFClient(page2)
1720

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

2124
const firstMsgEvent = await page.evaluate(
2225
({ roomName }) => {

internal/e2e-js/tests/callfabric/relayApp.spec.ts

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { uuid } from '@signalwire/core'
12
import { SignalWire } from '@signalwire/realtime-api'
23
import {
34
createCFClient,
@@ -12,6 +13,7 @@ import { test, expect } from '../../fixtures'
1213
test.describe('CallFabric Relay Application', () => {
1314
test('should connect to the relay app and expect an audio playback', async ({
1415
createCustomPage,
16+
resource,
1517
}) => {
1618
const client = await SignalWire({
1719
host: process.env.RELAY_HOST,
@@ -22,8 +24,14 @@ test.describe('CallFabric Relay Application', () => {
2224
},
2325
})
2426

27+
const reference = `e2e-relay-app_${uuid()}`
28+
await resource.createRelayAppResource({
29+
name: reference,
30+
reference,
31+
})
32+
2533
await client.voice.listen({
26-
topics: ['cf-e2e-test-relay'],
34+
topics: [reference],
2735
onCallReceived: async (call) => {
2836
try {
2937
console.log('Call received', call.id)
@@ -50,16 +58,14 @@ test.describe('CallFabric Relay Application', () => {
5058

5159
await createCFClient(page)
5260

53-
const resourceName = 'cf-e2e-test-relay'
54-
5561
await page.evaluate(
5662
async (options) => {
5763
return new Promise<any>(async (resolve, _reject) => {
5864
// @ts-expect-error
5965
const client = window._client
6066

6167
const call = await client.dial({
62-
to: `/public/${options.resourceName}`,
68+
to: `/private/${options.reference}`,
6369
rootElement: document.getElementById('rootElement'),
6470
})
6571

@@ -69,7 +75,7 @@ test.describe('CallFabric Relay Application', () => {
6975
resolve(call)
7076
})
7177
},
72-
{ resourceName }
78+
{ reference }
7379
)
7480

7581
const callPlayStarted = page.evaluate(async () => {
@@ -126,6 +132,7 @@ test.describe('CallFabric Relay Application', () => {
126132

127133
test('should connect to the relay app and expect a silence', async ({
128134
createCustomPage,
135+
resource,
129136
}) => {
130137
const client = await SignalWire({
131138
host: process.env.RELAY_HOST,
@@ -136,8 +143,14 @@ test.describe('CallFabric Relay Application', () => {
136143
},
137144
})
138145

146+
const reference = `e2e-relay-app_${uuid()}`
147+
await resource.createRelayAppResource({
148+
name: reference,
149+
reference,
150+
})
151+
139152
await client.voice.listen({
140-
topics: ['cf-e2e-test-relay'],
153+
topics: [reference],
141154
onCallReceived: async (call) => {
142155
try {
143156
console.log('Call received', call.id)
@@ -160,16 +173,14 @@ test.describe('CallFabric Relay Application', () => {
160173

161174
await createCFClient(page)
162175

163-
const resourceName = 'cf-e2e-test-relay'
164-
165176
await page.evaluate(
166177
async (options) => {
167178
return new Promise<any>(async (resolve, _reject) => {
168179
// @ts-expect-error
169180
const client = window._client
170181

171182
const call = await client.dial({
172-
to: `/public/${options.resourceName}`,
183+
to: `/private/${options.reference}`,
173184
rootElement: document.getElementById('rootElement'),
174185
})
175186

@@ -179,7 +190,7 @@ test.describe('CallFabric Relay Application', () => {
179190
resolve(call)
180191
})
181192
},
182-
{ resourceName }
193+
{ reference }
183194
)
184195

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

250261
test('should connect to the relay app and expect a hangup', async ({
251262
createCustomPage,
263+
resource,
252264
}) => {
253265
const client = await SignalWire({
254266
host: process.env.RELAY_HOST,
@@ -259,8 +271,14 @@ test.describe('CallFabric Relay Application', () => {
259271
},
260272
})
261273

274+
const reference = `e2e-relay-app_${uuid()}`
275+
await resource.createRelayAppResource({
276+
name: reference,
277+
reference,
278+
})
279+
262280
await client.voice.listen({
263-
topics: ['cf-e2e-test-relay'],
281+
topics: [reference],
264282
onCallReceived: async (call) => {
265283
try {
266284
console.log('Call received', call.id)
@@ -279,8 +297,6 @@ test.describe('CallFabric Relay Application', () => {
279297
const page = await createCustomPage({ name: '[page]' })
280298
await page.goto(SERVER_URL)
281299

282-
const resourceName = 'cf-e2e-test-relay'
283-
284300
await createCFClient(page)
285301

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

292308
const call = await client.dial({
293-
to: `/public/${options.resourceName}`,
309+
to: `/private/${options.reference}`,
294310
rootElement: document.getElementById('rootElement'),
295311
})
296312

@@ -300,7 +316,7 @@ test.describe('CallFabric Relay Application', () => {
300316
resolve(call)
301317
})
302318
},
303-
{ resourceName }
319+
{ reference }
304320
)
305321

306322
const expectInitialEvents = expectCFInitialEvents(page)

internal/e2e-js/tests/callfabric/swml.spec.ts

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { uuid } from '@signalwire/core'
12
import { test } from '../../fixtures'
23
import {
34
SERVER_URL,
@@ -8,14 +9,49 @@ import {
89
} from '../../utils'
910

1011
test.describe('CallFabric SWML', () => {
12+
const swmlTTS = {
13+
sections: {
14+
main: [
15+
'answer',
16+
{
17+
play: {
18+
volume: 10,
19+
urls: [
20+
'say:Hi',
21+
'say:Welcome to SignalWire',
22+
"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.",
23+
],
24+
},
25+
},
26+
],
27+
},
28+
}
29+
const swmlHangup = {
30+
version: '1.0.0',
31+
sections: {
32+
main: [
33+
'answer',
34+
{
35+
hangup: {
36+
reason: 'busy',
37+
},
38+
},
39+
],
40+
},
41+
}
42+
1143
test('should dial an address and expect a TTS audio', async ({
1244
createCustomPage,
45+
resource,
1346
}) => {
1447
const page = await createCustomPage({ name: '[page]' })
1548
await page.goto(SERVER_URL)
1649

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

2056
await createCFClient(page)
2157

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

3066
const call = await client.dial({
31-
to: resourceName,
67+
to: `/private/${resourceName}`,
3268
rootElement: document.getElementById('rootElement'),
3369
})
3470

@@ -40,18 +76,6 @@ test.describe('CallFabric SWML', () => {
4076
},
4177
{ resourceName }
4278
)
43-
page.expectWsTraffic({
44-
assertations: [
45-
{
46-
type: "send",
47-
name: "connect",
48-
expect: {
49-
method: "signalwire.connect",
50-
"params.version.major": 4,
51-
},
52-
}
53-
]
54-
})
5579

5680
const callPlayStarted = page.evaluate(async () => {
5781
// @ts-expect-error
@@ -101,12 +125,16 @@ test.describe('CallFabric SWML', () => {
101125

102126
test('should dial an address and expect a hangup', async ({
103127
createCustomPage,
128+
resource,
104129
}) => {
105130
const page = await createCustomPage({ name: '[page]' })
106131
await page.goto(SERVER_URL)
107132

108-
const resourceName =
109-
process.env.RESOURCE_NAME ?? '/public/cf-e2e-test-hangup'
133+
const resourceName = `e2e-swml-app_${uuid()}`
134+
await resource.createSWMLAppResource({
135+
name: resourceName,
136+
contents: swmlHangup,
137+
})
110138

111139
await createCFClient(page)
112140

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

120148
const call = await client.dial({
121-
to: resourceName,
149+
to: `/private/${resourceName}`,
122150
rootElement: document.getElementById('rootElement'),
123151
})
124152

0 commit comments

Comments
 (0)