Skip to content

Commit

Permalink
Refactor realtime-api e2e tests (#1051)
Browse files Browse the repository at this point in the history
* Refactor delete domain app

* remove log

* enable websocket logs
  • Loading branch information
iAmmar7 authored May 15, 2024
1 parent b811a98 commit dce2a6e
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 64 deletions.
105 changes: 49 additions & 56 deletions internal/e2e-realtime-api/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,30 +77,32 @@ export const createTestRunner = ({
run: async () => {
start()

let exitCode = 0
const id = uuid
const domainAppName = `d-app-${id}`
const params: TestHandlerParams = {}

try {
if (useDomainApp) {
params.domainApp = await createDomainApp({
name: `d-app-${uuid}`,
identifier: uuid,
name: domainAppName,
identifier: id,
call_handler: 'relay_context',
call_relay_context: `d-app-ctx-${uuid}`,
call_relay_context: `d-app-ctx-${id}`,
})
}
const exitCode = await testHandler(params)
if (params.domainApp) {
console.log('Delete domain app..')
await deleteDomainApp({ id: params.domainApp.id })
}
done(exitCode)
console.log('Created domain app:', domainAppName)
exitCode = await testHandler(params)
} catch (error) {
clearTimeout(timer)
console.error(`Test Runner ${name} Failed!`, error)
exitCode = 1
} finally {
if (params.domainApp) {
console.log('Delete domain app..')
await deleteDomainApp({ id: params.domainApp.id })
console.log('Deleted domain app:', domainAppName)
}
done(1)
done(exitCode)
}
},
}
Expand Down Expand Up @@ -195,66 +197,57 @@ type CreateDomainAppParams = {
call_handler: 'relay_context'
call_relay_context: string
}
const createDomainApp = (params: CreateDomainAppParams): Promise<DomainApp> => {
return new Promise((resolve, reject) => {
const data = JSON.stringify(params)
const options = {
host: process.env.API_HOST,
port: 443,
const createDomainApp = async (
params: CreateDomainAppParams
): Promise<DomainApp> => {
const response = await fetch(
`https://${process.env.API_HOST}/api/relay/rest/domain_applications`,
{
method: 'POST',
path: '/api/relay/rest/domain_applications',
headers: {
Authorization: getAuthorization(),
'Content-Type': 'application/json',
'Content-Length': data.length,
Authorization: getAuthorization(),
},
body: JSON.stringify(params),
}
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()
})
)
if (!response.ok) {
const errorData = await response.json()
throw new Error(
`Failed to create domain app: ${
errorData.message || JSON.stringify(errorData)
}`
)
}
const data = await response.json()
return data
}

type DeleteDomainAppParams = {
id: string
}
const deleteDomainApp = ({ id }: DeleteDomainAppParams): Promise<void> => {
return new Promise<void>((resolve, reject) => {
const options = {
host: process.env.API_HOST,
port: 443,
const deleteDomainApp = async ({
id,
}: DeleteDomainAppParams): Promise<Response> => {
const response = await fetch(
`https://${process.env.API_HOST}/api/relay/rest/domain_applications/${id}`,
{
method: 'DELETE',
path: `/api/relay/rest/domain_applications/${id}`,
headers: {
Authorization: getAuthorization(),
'Content-Type': 'application/json',
Authorization: getAuthorization(),
},
}
const req = request(options, (response) => {
let body = ''
response.on('data', (chunk) => {
body += chunk
})

response.on('end', () => {
resolve()
})
})
req.on('error', reject)
req.end()
})
)
if (!response.ok) {
const errorData = await response.json()
throw new Error(
`Failed to delete domain app: ${
errorData.message || JSON.stringify(errorData)
}`
)
}
return response
}

export const CALL_PROPS = [
Expand Down
2 changes: 1 addition & 1 deletion internal/e2e-realtime-api/src/voicePass.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const handler: TestHandler = ({ domainApp }) => {
project: process.env.RELAY_PROJECT as string,
token: process.env.RELAY_TOKEN as string,
debug: {
// logWsTraffic: true,
logWsTraffic: true,
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const handler: TestHandler = ({ domainApp }) => {
project: process.env.RELAY_PROJECT as string,
token: process.env.RELAY_TOKEN as string,
debug: {
// logWsTraffic: true,
logWsTraffic: true,
},
})

Expand Down Expand Up @@ -131,7 +131,6 @@ const handler: TestHandler = ({ domainApp }) => {
},
})


const unsubPlay = await play.listen({
onStarted: (playback) => {
// NotOk since the listener is attached after the call.play has resolved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const handler: TestHandler = ({ domainApp }) => {
project: process.env.RELAY_PROJECT as string,
token: process.env.RELAY_TOKEN as string,
debug: {
// logWsTraffic: true,
logWsTraffic: true,
},
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const handler: TestHandler = ({ domainApp }) => {
project: process.env.RELAY_PROJECT as string,
token: process.env.RELAY_TOKEN as string,
debug: {
// logWsTraffic: true,
logWsTraffic: true,
},
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const handler: TestHandler = ({ domainApp }) => {
project: process.env.RELAY_PROJECT as string,
token: process.env.RELAY_TOKEN as string,
debug: {
// logWsTraffic: true,
logWsTraffic: true,
},
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const handler: TestHandler = ({ domainApp }) => {
project: process.env.RELAY_PROJECT as string,
token: process.env.RELAY_TOKEN as string,
debug: {
// logWsTraffic: true,
logWsTraffic: true,
},
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const handler: TestHandler = ({ domainApp }) => {
project: process.env.RELAY_PROJECT as string,
token: process.env.RELAY_TOKEN as string,
debug: {
// logWsTraffic: true,
logWsTraffic: true,
},
})

Expand Down

0 comments on commit dce2a6e

Please sign in to comment.